o
    1 i                     @   s~   d dl Z d dlmZmZ d dlmZ d dlmZ edee dZ	e 
eZeddd	e	d
e	fddZedddddZdS )    N)OptionalTypeVar)get_train_fn_utils)	PublicAPIT)boundalpha)Z	stabilitydatareturnc                 C   s   t  | S )a]  Broadcast small (<1kb) data from the rank 0 worker to all other workers.

    Serves as a barrier, meaning that all workers must call this method before
    the training function can continue.

    Example:

        .. testcode:

            from ray.train import get_context
            from ray.train.collective import broadcast_from_rank_zero
            from ray.train.torch import TorchTrainer

            def train_func():
                ...
                if get_context().get_world_rank() == 0:
                    data = {"some_key": "some_value"}
                else:
                    data = None
                data = broadcast_from_rank_zero(data)
                ...

            trainer = TorchTrainer(train_func)
            trainer.fit()

    Args:
        data: The small (1kb) data to broadcast from the rank 0 worker to all
            other workers.

    Returns:
        The data broadcasted from the rank 0 worker.

    Raises:
        ValueError: If the data is too big.
        pickle.PicklingError: If the data is not pickleable.
        TypeError: If the data is not pickleable.
    )r   broadcast_from_rank_zero)r	    r   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/train/collective/collectives.pyr      s   'r   c                   C   s
   t   S )a  Create a barrier across all workers.

    All workers must call this method before the training function can continue.

    Example:

        .. testcode:

            from ray.train import get_context
            from ray.train.collective import barrier
            from ray.train.torch import TorchTrainer

            def train_func():
                ...
                print(f"Rank {get_context().get_world_rank()} is waiting at the barrier.")
                barrier()
                print(f"Rank {get_context().get_world_rank()} has passed the barrier.")
                ...

            trainer = TorchTrainer(train_func)
            trainer.fit()
    )r   barrierr   r   r   r   r   7   s   
r   )r
   N)loggingtypingr   r   Z/ray.train.v2._internal.execution.train_fn_utilsr   Zray.util.annotationsr   objectr   	getLogger__file__loggerr   r   r   r   r   r   <module>   s    
)