ó
    Î‘®iÁ  ã                  ó*  • S SK Jr  S SKJr  S SKJrJr  S SKJr  S SK	J
r
Jr  S SKJrJr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              SS jr            SS jr\R4                  SSS4           SS jjrg)é    )Úannotations)ÚTYPE_CHECKING)Ú_C_opsÚ	framework)Údata_feeder)Ú_get_global_groupÚ_warn_cur_rank_not_in_group)ÚReduceOpÚ_get_reduce_opÚ_to_inplace_op)Úin_pir_mode)ÚTensor)Útask)ÚGroupé   )Ú	_ReduceOpc                óÈ   • [        U5      nU(       a  UR                  R                  X5      $ UR                  R                  XU5      nU(       a  UR                  " 5         U$ )N)r   Úprocess_groupÚall_reduce_on_calc_streamÚ
all_reduceÚwait)ÚtensorÚopÚgroupÚsync_opÚuse_calc_streamÚop_typer   s          Úr/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/stream/all_reduce.pyÚ_all_reduce_in_dygraphr   '   sQ   € ô ˜RÓ €GæØ×"Ñ"×<Ñ<¸VÓMÐMà×Ñ×)Ñ)¨&¸7ÓC€DÞØ	Š	Œà€Kó    c                óˆ  • [         R                  " U S/ SQS5        Uc  SOUR                  n[        U[        5      (       d  [        S5      e[        5       (       a#  [        U5      n[        R                  " XU5        g [        U5      n[        R                  " U40 [        5       D6nUR                  USU /0SU /0XSS.S	9  g )
Nr   )	Úfloat16Úfloat32Úfloat64Úint32Úint64Úint8Úuint8ÚboolÚuint16r   r   z3The type of 'ring_id' for all_reduce should be int.ÚXÚOut)Úring_idr   )ÚtypeÚinputsÚoutputsÚattrs)r   Úcheck_variable_and_dtypeÚidÚ
isinstanceÚintÚ
ValueErrorr   r   r   Úall_reduce_r   r   ÚLayerHelperÚlocalsÚ	append_op)r   r   r   r   r   r-   r   Úhelpers           r   Ú_all_reduce_in_static_moder<   :   sÂ   € ô ×(Ò(ØØò
	
ð 	ôð" ‘=‰a e§h¡h€Gägœs×#Ñ#ÜÐNÓOÐOä‡}}Ü% bÓ)ˆÜ×Ò˜6¨BÔ/Øô ˜RÓ €GÜ×"Ò" 7Ñ7¬f«hÑ7€FØ
×ÑØØfXˆØ˜˜Ð!Ø!Ñ>ð	 ò r    NTFc                óð   • [        U5      (       a  gU(       d  U(       a  [        S5      e[        R                  " 5       (       a  Uc
  [	        5       OUn[        XX#U5      $ Ub   S5       e[        XX#U5      $ )aL  

Perform specific reduction (for example, sum, max) on inputs across devices.

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.
    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.

Examples:
    .. code-block:: python

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

        >>> dist.init_parallel_env()
        >>> local_rank = dist.get_rank()
        >>> data = None
        >>> 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.all_reduce(data, sync_op=False)
        >>> task.wait()  # type: ignore[union-attr]
        >>> out = data
        >>> print(out)
        [[5, 7, 9], [5, 7, 9]]
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<   )r   r   r   r   r   s        r   r   r   h   sˆ   € ôV # 5×)Ñ)Øæ–ÜØCó
ð 	
ô × Ò ×"Ñ"Ø',¡}Ô!Ô#¸%ˆÜ%Ø˜¨ó
ð 	
ð ‰}ð 	
ØAó	
ˆ}ô *Ø˜¨ó
ð 	
r    )r   r   r   r   r   r   r   r)   r   r)   Úreturnr   )r   r   r   r   r   r   r   r)   r   r)   r@   ÚNone)r   r   r   r   r   zGroup | Noner   r)   r   r)   r@   ztask | None)Ú
__future__r   Útypingr   Úpaddler   r   Úpaddle.baser   Ú&paddle.distributed.communication.groupr   r	   Ú'paddle.distributed.communication.reducer
   r   r   Úpaddle.frameworkr   r   Úpaddle.base.corer   r   r   r   r   r<   ÚSUM© r    r   Ú<module>rL      s   ðõ #å  ç $Ý #÷÷ñ õ
 )æÝÝ%Ý<å&ðØðàðð ðð ð	ð
 ðð 
ôð&+Øð+àð+ð ð+ð ð	+ð
 ð+ð 
ô+ð` —L‘LØØØ!ð>
Øð>
àð>
ð ð>
ð ð	>
ð
 ð>
ð ö>
r    