
    Α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  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              SS jr            SS jr          SS jr   S           SS jjrg)    )annotations)TYPE_CHECKINGN)	framework)data_feeder)_get_global_group)Tensor)task)Group)ExecutionStreamTypec                    Uc
  [        5       OUnU(       a  UR                  R                  U U5      $ UR                  R                  XU5      nU(       a  UR                  " 5         U$ )N)r   process_group%all_gather_into_tensor_on_calc_streamall_gather_into_tensorwait)
out_tensor	in_tensorgroupsync_opuse_calc_streamr	   s         r/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/stream/all_gather.py"_all_gather_into_tensor_in_dygraphr   !   se     $)=eE""HH
 	

 55wD 		K    c                r   Uc
  [        5       OUn[        U 5      S:X  a=  U [        UR                  5       Vs/ s H  n[        R
                  " U5      PM     sn-  n U(       a  UR                  R                  X5      $ UR                  R                  XU5      nU(       a  UR                  " 5         U$ s  snf )Nr   )
r   lenrangenrankspaddle
empty_liker   all_gather_on_calc_stream
all_gatherr   )tensor_listtensorr   r   r   _r	   s          r   _all_gather_in_dygraphr$   9   s     $)=eE
;15;NO;Na))&1;NOO""<<
 	
 ))+wGD		K Ps    B4c                   Sn[         R                  " U40 [        5       D6nUR                  UR                  S9nU  H  n[
        R                  " US/ SQS5        M      [
        R                  " US/ SQS5        Uc  SOUR                  n[        R                  " 5       n	UR                  USU/0SU/0UU	S	.S
9n
U(       a)  [        R                  R                  U
R                  l        U R!                  5         [#        UR$                  5      S:X  a'  U R'                  [(        R*                  " US5      5        g U R'                  [(        R,                  " XiS5      5        g )Nr    )dtyper!   )
float16float32float64int32int64boolint8uint8	complex64
complex128r"   r   xout)ring_idr   )typeinputsoutputsattrs)r   LayerHelperlocals"create_variable_for_type_inferencer&   r   check_variable_and_dtypeiddistget_world_size	append_opr   DefaultStreamvalue	dist_attrexecution_streamclearr   shapeextendr   unstacksplit)r!   r"   r   r   op_typehelperr2   elemr3   r   ops              r   _all_gather_in_static_moderM   Q   s?    G""77fh7F

3
3&,,
3
GC,, 	
 $ ((	
 	$ =aehhG  "F			fX
	 
 
B (;(I(I(O(O%
6<<A6>>#q126<<Q78r   c                   Ub   UR                  5       (       d  [        S5      eU(       d  U(       a  [        S5      e[        R                  " 5       (       a5  [        R
                  " U 5      (       a  [        XX#U5      $ [        XX#U5      $ Ub   S5       e[        R
                  " U 5      (       a  [        S5      e[        XX#5      $ )a  

Gather tensors across devices to a correctly-sized tensor or a tensor list.

Args:
    tensor_or_tensor_list (Union[Tensor, List[Tensor]]): The output. If it is a tensor, it should be correctly-sized. If it is a list, it
        should be empty or contain correctly-sized tensors.
    tensor (Tensor): The input tensor on each rank. The result will overwrite this tenor after communication. Support
        float16, float32, float64, int32, int64, int8, uint, bool, complex64 or complex128 as the input data type.
    group (Group, 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()
        >>> tensor_list = [] # type: ignore
        >>> 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_gather(tensor_list, data, sync_op=False)
        >>> task.wait()  # type: ignore[union-attr]
        >>> print(tensor_list)
        [[[4, 5, 6], [4, 5, 6]], [[1, 2, 3], [1, 2, 3]]] (2 GPUs)
zjThe group should not be None and all ranks which invoke this operation should be the member of this group.z5use_calc_stream can only be true in sync op behavior.z3Group can not be used in static graph mode for now.zLOnly support passing a tensor list to `all_gather` in static graph mode now.)		is_memberRuntimeErrorr   in_dynamic_moder   	is_tensorr   r$   rM   )tensor_or_tensor_listr"   r   r   r   s        r   r    r       s    \ !2!2x
 	
 C
 	
   ""1225%u  *%u  } 	
A	
} 122^  .%u r   )r   r   r   r   r   r
   r   r,   r   r,   returnr	   )r!   list[Tensor]r"   r   r   r
   r   r,   r   r,   rT   r	   )
r!   rU   r"   r   r   r
   r   r,   rT   None)NTF)rS   zTensor | list[Tensor]r"   r   r   zGroup | Noner   r,   r   r,   rT   ztask | None)
__future__r   typingr   r   paddle.distributeddistributedr=   r   paddle.baser   &paddle.distributed.communication.groupr   r   paddle.base.corer	   r
   %paddle.distributed.utils.stream_utilsr   r   r$   rM   r     r   r   <module>r`      s"   #    !  # D%< E  	
  
0  	
  
0<9<9'-<96;<9FJ<9	<9D !L0LL L 	L
 L Lr   