From 99cd0a8c6bf5141f7ebf76e524fb74725400c7ea Mon Sep 17 00:00:00 2001 From: sandyhouse Date: Mon, 19 Oct 2020 10:25:03 +0800 Subject: [PATCH 1/4] add doc, test=document_fix --- python/paddle/distributed/collective.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/paddle/distributed/collective.py b/python/paddle/distributed/collective.py index 47db4d2e7a35d..4c3edbb3812b4 100644 --- a/python/paddle/distributed/collective.py +++ b/python/paddle/distributed/collective.py @@ -36,7 +36,15 @@ class ReduceOp: - """Reduce Operation""" + """ + Specify the type of operation used for element-wise reductions. + It should be one of the following values: + + ReduceOp.SUM: + ReduceOp.MAX: + ReduceOp.MIN: + ReduceOp.PROD: + """ SUM = 0 MAX = 1 MIN = 2 From 3a0358aad8769a137d65b5257ae7ee0ff15f343a Mon Sep 17 00:00:00 2001 From: sandyhouse Date: Mon, 19 Oct 2020 10:50:26 +0800 Subject: [PATCH 2/4] update, test=document_fix --- python/paddle/distributed/collective.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/paddle/distributed/collective.py b/python/paddle/distributed/collective.py index 4c3edbb3812b4..e07319dd6d5dd 100644 --- a/python/paddle/distributed/collective.py +++ b/python/paddle/distributed/collective.py @@ -41,8 +41,11 @@ class ReduceOp: It should be one of the following values: ReduceOp.SUM: + ReduceOp.MAX: + ReduceOp.MIN: + ReduceOp.PROD: """ SUM = 0 From 3520f0cd6df56c01409e6a51f3c86e4f94ce34be Mon Sep 17 00:00:00 2001 From: sandyhouse Date: Mon, 19 Oct 2020 11:51:23 +0800 Subject: [PATCH 3/4] update, test=document_fix --- python/paddle/distributed/collective.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/distributed/collective.py b/python/paddle/distributed/collective.py index e07319dd6d5dd..870a22b9ccb38 100644 --- a/python/paddle/distributed/collective.py +++ b/python/paddle/distributed/collective.py @@ -40,13 +40,13 @@ class ReduceOp: Specify the type of operation used for element-wise reductions. It should be one of the following values: - ReduceOp.SUM: + ReduceOp.SUM - ReduceOp.MAX: + ReduceOp.MAX - ReduceOp.MIN: + ReduceOp.MIN - ReduceOp.PROD: + ReduceOp.PROD """ SUM = 0 MAX = 1 From f2a6f86ecad9298feb554c10d9a00f6c15320756 Mon Sep 17 00:00:00 2001 From: sandyhouse Date: Mon, 19 Oct 2020 13:41:37 +0800 Subject: [PATCH 4/4] update, test=document_fix --- python/paddle/distributed/collective.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/python/paddle/distributed/collective.py b/python/paddle/distributed/collective.py index 870a22b9ccb38..b631f7bbe9d11 100644 --- a/python/paddle/distributed/collective.py +++ b/python/paddle/distributed/collective.py @@ -47,6 +47,25 @@ class ReduceOp: ReduceOp.MIN ReduceOp.PROD + + Examples: + .. 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]] """ SUM = 0 MAX = 1