
    Αi                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	J
r
Jr  S SKJrJr  \(       a  S SKJr  S SKJr  S S	KJr  S S
KJr  S rS rS \R,                  SSS4             SS jjrg)    )annotations)TYPE_CHECKING)	framework)data_feeder)_get_global_group_get_or_throw_group_rank_warn_cur_rank_not_in_group)ReduceOp_get_reduce_op)Tensor)task)Group)	_ReduceOpc                    [        U5      nU(       a  UR                  R                  XU5      $ UR                  R                  XXd5      nU(       a  UR                  " 5         U$ )N)r   process_groupreduce_on_calc_streamreducewait)tensordst_rank_in_groupopgroupsync_opuse_calc_streamop_typer   s           n/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/stream/reduce.py_reduce_in_dygraphr   #   s_     R G""88w
 	
 %%7D 		K    c           
         [         R                  " U S/ SQS5        SnUc  SOUR                  n[        R                  " U40 [        5       D6nUR                  USU /0SU /0UU[        U5      S.S9  g )	Nr   )float16float32float64int32int64int8uint8boolr   r   xout)ring_idroot_idreduce_type)typeinputsoutputsattrs)r   check_variable_and_dtypeidr   LayerHelperlocals	append_opint)	r   r   r,   r   r   r   r   r*   helpers	            r   _reduce_in_static_moder8   5   s     ((		
 	  G=aehhG""77fh7F
fX!({+
	  	r   NTFc                   [        U5      (       a  gU(       d  U(       a  [        S5      e[        R                  " 5       (       a'  Uc
  [	        5       OUn[        X5      n[        XX#XE5      $ Ub   S5       e[        XX#XE5      $ )a[  

Perform specific reduction (for example, sum, max) on a tensor across devices and send to the destination device.

Args:
    tensor (Tensor): The input tensor on each rank. The result will overwrite this tenor after communication. Support
        float16, float32, float64, int32, int64, int8, uint8 or bool as the input data type.
    dst (int, optional): Rank of the destination device. If none is given, use `0` as default.
    op (ReduceOp.SUM|ReduceOp.MAX|ReduceOp.MIN|ReduceOp.PROD, optional): The reduction used. If none is given, use ReduceOp.SUM as default.
    group (Group|None, optional): Communicate in which group. If none is given, use the global group as default.
    sync_op (bool, optional): Indicate whether the communication is sync or not. If none is given, use true as default.
    use_calc_stream (bool, optional): Indicate whether the communication is done on calculation stream. If none is given, use false as default. This
        option is designed for high performance demand, be careful to turn it on except you are clearly know its meaning.

Returns:
    Return a task object.

Warning:
    This API only supports the dygraph mode now.

Examples:
    .. code-block:: python

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

        >>> dist.init_parallel_env()
        >>> local_rank = dist.get_rank()
        >>> if local_rank == 0:
        ...     data = paddle.to_tensor([[4, 5, 6], [4, 5, 6]])
        >>> else:
        ...     data = paddle.to_tensor([[1, 2, 3], [1, 2, 3]])
        >>> task = dist.stream.reduce(data, dst=0, sync_op=False)
        >>> task.wait()  # type: ignore[union-attr]
        >>> out = data.numpy()
        >>> print(out)
        >>> # [[5, 7, 9], [5, 7, 9]] (2 GPUs, out for rank 0)
        >>> # [[1, 2, 3], [1, 2, 3]] (2 GPUs, out for rank 1)
Nz5use_calc_stream can only be true in sync op behavior.z3Group can not be used in static graph mode for now.)r	   RuntimeErrorr   in_dynamic_moder   r   r   r8   )r   dstr   r   r   r   r   s          r   r   r   X   s    ` #5))C
 	
   ""',}!#%4S@!r'
 	
 } 	
A	
} &G
 	
r   )r   r   r<   r6   r   r   r   zGroup | Noner   r'   r   r'   returnztask | None)
__future__r   typingr   paddler   paddle.baser   &paddle.distributed.communication.groupr   r   r	   'paddle.distributed.communication.reducer
   r   r   paddle.base.corer   r   r   r   r8   SUMr    r   r   <module>rG      s    #    # 
 M%<A$ J LL!D
D
	D
 	D
 	D

 D
 D
 D
r   