
    Αi                        S SK Jr  S SKJr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Jr  \(       a  S SKJr  S S	KJr  S S
KJr   S         SS jjr S       SS jjrg)    )annotations)TYPE_CHECKINGAnyN)	framework)stream   )convert_object_to_tensorconvert_tensor_to_object)Tensor)task)Groupc                2    [         R                  " U UUUSS9$ )a]  

Broadcast a tensor from the source to all others.
As shown below, one process is started with a GPU and GPU0 owns data 0. Through broadcast operator,
data 0 will be sent to all GPUs from GPU0.

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

Args:
    tensor (Tensor): The tensor to send if current rank is the source, or the tensor to receive otherwise. Its data type
        should be float16, float32, float64, int32, int64, int8, uint8, bool, bfloat16, complex64 or complex128.
    src (int): The source rank in global view.
    group (Group, 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. The 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.broadcast(data, src=1)
        >>> print(data)
        >>> # [[1, 2, 3], [1, 2, 3]] (2 GPUs)
F)groupsync_opuse_calc_stream)r   	broadcast)tensorsrcr   r   s       j/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/broadcast.pyr   r   "   s'    P      c                   [         R                  " 5       (       d   S5       e[        R                  " 5       n/ n[	        U 5      nX1:X  aQ  / nU  H2  n[        U5      u  pUR                  U5        UR                  U	5        M4     [        R                  " U5      n
O[        R                  " U/SS9n
[        XU5        X1:X  a&  [        R                  " U5      R                  S5      nO:[        R                  " U
5      R                  5       n[        R                  " U/SS9n[        XU5        Sn[        U5       H  nX   n[!        XX-    U5      X'   X-  nM     g)a  

Broadcast picklable objects from the source to all others. Similar to broadcast(), but python object can be passed in.

Args:
    object_list (list): The list of objects to send if current rank is the source, or the list of objects to receive otherwise.
    src (int): The source rank in global view.
    group (Group): The group instance return by new_group or None for global default group.

Returns:
    None.

Warning:
    This API only supports the dygraph mode.

Examples:
    .. code-block:: python

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

        >>> dist.init_parallel_env()
        >>> if dist.get_rank() == 0:
        ...     object_list = [{"foo": [1, 2, 3]}]
        >>> else:
        ...     object_list = [{"bar": [4, 5, 6]}]
        >>> dist.broadcast_object_list(object_list, src=1)
        >>> print(object_list)
        >>> # [{"bar": [4, 5, 6]}] (2 GPUs)
z8broadcast_object_list doesn't support static graph mode.int64)dtypeuint8r   N)r   in_dynamic_modedistget_ranklenr	   appendpaddlestackemptyr   concatcastsumitemranger
   )object_listr   r   rankobj_tensorsobj_nums	obj_sizesobj
obj_tensorobj_sizeobj_size_tensorobj_data_tensordata_lenoffsetis                  r   broadcast_object_listr5   S   s8   B $$&& B& ==?DK;H{	C#;C#@ Jz*X&  !,,y1 ,,zAoE*{ --499'B::o.335 ,,zAoE*F8_"%1V%67
 	 r   )NT)
r   r   r   intr   Group | Noner   boolreturnr   )N)r(   z	list[Any]r   r6   r   r7   r9   None)
__future__r   typingr   r   r    paddle.distributeddistributedr   r    paddle.distributed.communicationr   serialization_utilsr	   r
   r   paddle.base.corer   &paddle.distributed.communication.groupr   r   r5    r   r   <module>rD      s    # %  !  3
 %< KO...%1.CG.	.d =ABB!$B-9B	Br   