ReduceOp

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

ReduceOp.SUM

ReduceOp.MAX

ReduceOp.MIN

ReduceOp.PROD

代码示例

  1. import numpy as np
  2. import paddle
  3. from paddle.distributed import ReduceOp
  4. from paddle.distributed import init_parallel_env
  5. paddle.set_device('gpu:%d'%paddle.distributed.ParallelEnv().dev_id)
  6. init_parallel_env()
  7. if paddle.distributed.ParallelEnv().local_rank == 0:
  8. np_data = np.array([[4, 5, 6], [4, 5, 6]])
  9. else:
  10. np_data = np.array([[1, 2, 3], [1, 2, 3]])
  11. data = paddle.to_tensor(np_data)
  12. paddle.distributed.all_reduce(data, op=ReduceOp.SUM)
  13. out = data.numpy()
  14. # [[5, 7, 9], [5, 7, 9]]