Skip to content

Commit

Permalink
update doc for ReduceOp (PaddlePaddle#2791)
Browse files Browse the repository at this point in the history
* update doc for ReduceOp
  • Loading branch information
lilong12 authored Oct 19, 2020
1 parent cf14cd5 commit d91179d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci_scripts/api_white_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ paddle/fluid/layers/scatter_cn.rst
paddle/tensor/manipulation/scatter_cn.rst
paddle/distributed/init_parallel_env_cn.rst
paddle/distributed/spawn_cn.rst
paddle/distributed/ReduceOp_cn.rst
paddle/distributed/fleet/Fleet_cn.rst
paddle/distributed/fleet/utils/fs/ExecuteError_cn.rst
paddle/distributed/fleet/utils/fs/FSFileExistsError_cn.rst
Expand Down
1 change: 1 addition & 0 deletions doc/fluid/api_cn/distributed_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ paddle.distributed
distributed_cn/ParallelEnv_cn.rst
distributed_cn/prepare_context_cn.rst
distributed_cn/reduce_cn.rst
distributed_cn/ReduceOp_cn.rst
distributed_cn/scatter_cn.rst
distributed_cn/spawn_cn.rst
34 changes: 34 additions & 0 deletions doc/fluid/api_cn/distributed_cn/ReduceOp_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _cn_api_distributed_ReduceOp:

ReduceOp
-------------------------------

指定规约类操作的逐元素操作类型,需要是下述值之一:

ReduceOp.SUM

ReduceOp.MAX

ReduceOp.MIN

ReduceOp.PROD

代码示例
:::::::::
.. code-block:: python
import numpy as np
import paddle
from paddle.distributed import ReduceOp
from paddle.distributed import init_parallel_env
paddle.set_device('gpu:%d'%paddle.distributed.ParallelEnv().dev_id)
init_parallel_env()
if paddle.distributed.ParallelEnv().local_rank == 0:
np_data = np.array([[4, 5, 6], [4, 5, 6]])
else:
np_data = np.array([[1, 2, 3], [1, 2, 3]])
data = paddle.to_tensor(np_data)
paddle.distributed.all_reduce(data, op=ReduceOp.SUM)
out = data.numpy()
# [[5, 7, 9], [5, 7, 9]]
34 changes: 34 additions & 0 deletions doc/paddle/api/paddle/distributed/ReduceOp_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _cn_api_distributed_ReduceOp:

ReduceOp
-------------------------------

指定规约类操作的逐元素操作类型,需要是下述值之一:

ReduceOp.SUM

ReduceOp.MAX

ReduceOp.MIN

ReduceOp.PROD

代码示例
:::::::::
.. code-block:: python
import numpy as np
import paddle
from paddle.distributed import ReduceOp
from paddle.distributed import init_parallel_env
paddle.set_device('gpu:%d'%paddle.distributed.ParallelEnv().dev_id)
init_parallel_env()
if paddle.distributed.ParallelEnv().local_rank == 0:
np_data = np.array([[4, 5, 6], [4, 5, 6]])
else:
np_data = np.array([[1, 2, 3], [1, 2, 3]])
data = paddle.to_tensor(np_data)
paddle.distributed.all_reduce(data, op=ReduceOp.SUM)
out = data.numpy()
# [[5, 7, 9], [5, 7, 9]]
1 change: 1 addition & 0 deletions scripts/api_white_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ distributed_cn/all_reduce_cn.rst
distributed_cn/barrier_cn.rst
distributed_cn/broadcast_cn.rst
distributed_cn/reduce_cn.rst
distributed_cn/ReduceOp_cn.rst
distributed_cn/scatter_cn.rst
distributed_cn/init_parallel_env_cn.rst
distributed_cn/spawn_cn.rst

0 comments on commit d91179d

Please sign in to comment.