
    Αi,                        S SK Jr  S SKJr  S SKrS SKJr  S SKJr  \(       a  S SKJ	r	  S SK
Jr  S SKJr  S S	KJr  \R                  SS
4         SS jjrg)    )annotations)TYPE_CHECKINGN)stream)ReduceOp)Tensor)task)Group)	_ReduceOpTc                   U[         R                  :X  a  [        R                  R                  R                  5       S:  aq  Uc(  [        R                  R                  R                  5       OUnU R                  SUR                  -  5        [        R                  " U [         R                  UUSS9$ [        R                  " XX#SS9$ )a  

Reduce a tensor over all ranks so that all get the result.
As shown below, one process is started with a GPU and the data of this process is represented
by its group rank. The reduce operator is sum. Through all_reduce operator,
each GPU will have the sum of the data from all GPUs.

.. image:: https://githubraw.cdn.bcebos.com/PaddlePaddle/docs/develop/docs/api/paddle/distributed/img/allreduce.png
    :width: 800
    :alt: all_reduce
    :align: center

Args:
    tensor (Tensor): The input Tensor. It also works as the output Tensor. Its data type
        should be float16, float32, float64, int32, int64, int8, uint8 or bool.
    op (ReduceOp.SUM|ReduceOp.MAX|ReduceOp.MIN|ReduceOp.PROD|ReduceOp.AVG, optional): The operation used. Default value is ReduceOp.SUM.
    group (Group|None, optional): The group instance return by new_group or None for global default group.
    sync_op (bool, optional): Whether this op is a sync op. Default value is True.

Returns:
    Return a task object.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env: DISTRIBUTED)
        >>> import paddle
        >>> import paddle.distributed as dist

        >>> dist.init_parallel_env()
        >>> if dist.get_rank() == 0:
        ...     data = paddle.to_tensor([[4, 5, 6], [4, 5, 6]])
        >>> else:
        ...     data = paddle.to_tensor([[1, 2, 3], [1, 2, 3]])
        >>> dist.all_reduce(data)
        >>> print(data)
        >>> # [[5, 7, 9], [5, 7, 9]] (2 GPUs)
iR  g      ?F)opgroupsync_opuse_calc_stream)r   AVGpaddlebasecorenccl_versiondistributed
collective_get_global_groupscale_nranksr   
all_reduceSUM)tensorr   r   r   s       k/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/all_reduce.pyr   r      s    Z 
X\\fkk..;;=E } ));;= 	
 	cELL()  ||!
 	
 UU     )
r   r   r   r
   r   zGroup | Noner   boolreturnr   )
__future__r   typingr   r    paddle.distributed.communicationr   'paddle.distributed.communication.reducer   r   paddle.base.corer   &paddle.distributed.communication.groupr	   r
   r   r    r   r   <module>r(      sg    #    3 <%<A
 LL	>>> > 	>
 
>r   