
    &`i                         d dl mZmZ d dlmZmZ d dlmZ d dl	m
Z
mZmZ  ed           G d de                      Ze G d	 d
e                      Ze G d de                      ZdS )    )ABCabstractmethod)AnyDict)get_train_context)
DeprecatedDeveloperAPI	PublicAPIstable)	stabilityc                   v   e Zd ZdZedeeef         fd            Zedefd            Z	edefd            Z
ed             Zedefd            Zedefd            Zedefd	            Zedefd
            Zedefd            Zedefd            Zedefd            Zeed                         ZdS )TrainContextz(Abstract interface for training context.returnc                 ,    ddl m} t          |          )zB[Deprecated] User metadata dict passed to the Trainer constructor.r   )!_GET_METADATA_DEPRECATION_MESSAGE)ray.train.contextr   DeprecationWarning)selfr   s     l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/train/v2/api/context.pyget_metadatazTrainContext.get_metadata   s&     	HGGGGG !BCCC    c                 R    ddl m} t          |                    d                    )z4[Deprecated] Trial name for the corresponding trial.r   *_TUNE_SPECIFIC_CONTEXT_DEPRECATION_MESSAGEget_trial_namer   r   r   formatr   r   s     r   r   zTrainContext.get_trial_name   s;     	QPPPPP 6==>NOO
 
 	
r   c                 R    ddl m} t          |                    d                    )z2[Deprecated] Trial id for the corresponding trial.r   r   get_trial_idr   r   s     r   r    zTrainContext.get_trial_id   s:     	QPPPPP 6==nMM
 
 	
r   c                 R    ddl m} t          |                    d                    )z9[Deprecated] Trial resources for the corresponding trial.r   r   get_trial_resourcesr   r   s     r   r"   z TrainContext.get_trial_resources'   s;     	QPPPPP 6==>STT
 
 	
r   c                 R    ddl m} t          |                    d                    )a  [Deprecated] Log directory corresponding to the trial directory for a Tune session.
        This is deprecated for Ray Train and should no longer be called in Ray Train workers.

        If this directory is needed, please pass it into the `train_loop_config` directly.
        r   r   get_trial_dirr   r   s     r   r$   zTrainContext.get_trial_dir0   s:     	QPPPPP 6==oNN
 
 	
r   c                     dS )z,Experiment name for the corresponding trial.N r   s    r   get_experiment_namez TrainContext.get_experiment_name=   s	     	r   c                     dS )a  Get the current world size (i.e. total number of workers) for this run.

        .. testcode::

            import ray.train
            from ray.train.torch import TorchTrainer

            NUM_WORKERS = 2

            def train_fn_per_worker(config):
                assert ray.train.get_context().get_world_size() == NUM_WORKERS

            trainer = TorchTrainer(
                train_fn_per_worker,
                scaling_config=ray.train.ScalingConfig(num_workers=NUM_WORKERS),
            )
            trainer.fit()

        Nr&   r'   s    r   get_world_sizezTrainContext.get_world_sizeB   	    * 	r   c                     dS )a  Get the world rank of this worker.

        .. testcode::

            import ray.train
            from ray.train.torch import TorchTrainer

            def train_fn_per_worker(config):
                if ray.train.get_context().get_world_rank() == 0:
                    print("Worker 0")

            trainer = TorchTrainer(
                train_fn_per_worker,
                scaling_config=ray.train.ScalingConfig(num_workers=2),
            )
            trainer.fit()

        Nr&   r'   s    r   get_world_rankzTrainContext.get_world_rankY   	    ( 	r   c                     dS )a  Get the local rank of this worker (rank of the worker on its node).

        .. testcode::

            import ray.train
            from ray.train.torch import TorchTrainer

            def train_fn_per_worker(config):
                if ray.train.get_context().get_local_rank() == 0:
                    print("Local rank 0 worker")

            trainer = TorchTrainer(
                train_fn_per_worker,
                scaling_config=ray.train.ScalingConfig(num_workers=2),
            )
            trainer.fit()

        Nr&   r'   s    r   get_local_rankzTrainContext.get_local_ranko   r.   r   c                     dS )a!  Get the local world size of this node (i.e. number of workers on this node).

        Example:

            .. testcode::

                import ray.train
                from ray.train.torch import TorchTrainer

                def train_fn_per_worker():
                    print(ray.train.get_context().get_local_world_size())

                trainer = TorchTrainer(
                    train_fn_per_worker,
                    scaling_config=ray.train.ScalingConfig(num_workers=2),
                )
                trainer.fit()

        Nr&   r'   s    r   get_local_world_sizez!TrainContext.get_local_world_size   r+   r   c                     dS )a  Get the rank of this node.

        Example:

            .. testcode::

                import ray.train
                from ray.train.torch import TorchTrainer

                def train_fn_per_worker():
                    print(ray.train.get_context().get_node_rank())

                trainer = TorchTrainer(
                    train_fn_per_worker,
                    scaling_config=ray.train.ScalingConfig(num_workers=1),
                )
                trainer.fit()

        Nr&   r'   s    r   get_node_rankzTrainContext.get_node_rank   r+   r   c                     dS )aE  Returns the :class:`~ray.train._internal.storage.StorageContext` storage
        context which gives advanced access to the filesystem and paths
        configured through `RunConfig`.

        NOTE: This is a DeveloperAPI, and the `StorageContext` interface may change
        without notice between minor versions.
        Nr&   r'   s    r   get_storagezTrainContext.get_storage   s	     	r   N)__name__
__module____qualname____doc__r   r   strr   r   r   r    r"   r$   r   r(   intr*   r-   r0   r2   r4   r	   r6   r&   r   r   r   r   
   s       22Dd38n D D D ZD 
 
 
 
 Z
 
c 
 
 
 Z
 
 
 Z
 

s 

 

 

 Z

 S    ^     ^,     ^*     ^* c    ^, s    ^,   ^ \  r   r   c                   `    e Zd ZdZdefdZdefdZdefdZdefdZ	defdZ
defdZd	 Zd
S )DistributedTrainContextz4Implementation of TrainContext for distributed mode.r   c                 B    t                                                      S N)get_internal_train_contextr(   r'   s    r   r(   z+DistributedTrainContext.get_experiment_name   s    )++??AAAr   c                 B    t                                                      S r@   )rA   r*   r'   s    r   r*   z&DistributedTrainContext.get_world_size       )++::<<<r   c                 B    t                                                      S r@   )rA   r-   r'   s    r   r-   z&DistributedTrainContext.get_world_rank   rC   r   c                 B    t                                                      S r@   )rA   r0   r'   s    r   r0   z&DistributedTrainContext.get_local_rank   rC   r   c                 B    t                                                      S r@   )rA   r2   r'   s    r   r2   z,DistributedTrainContext.get_local_world_size   s    )++@@BBBr   c                 B    t                                                      S r@   )rA   r4   r'   s    r   r4   z%DistributedTrainContext.get_node_rank   s    )++99;;;r   c                 B    t                                                      S r@   )rA   r6   r'   s    r   r6   z#DistributedTrainContext.get_storage   s    )++77999r   N)r7   r8   r9   r:   r;   r(   r<   r*   r-   r0   r2   r4   r6   r&   r   r   r>   r>      s        >>BS B B B B= = = = == = = = == = = = =Cc C C C C<s < < < <: : : : :r   r>   c                       e Zd ZdZ	 	 	 	 	 ddededededed	efd
ZdefdZdefdZdefdZ	defdZ
defdZdefdZd ZdS )LocalTrainContextz.Implementation of TrainContext for local mode.   r   experiment_name
world_size
world_rank
local_ranklocal_world_size	node_rankc                 Z    || _         || _        || _        || _        || _        || _        d S r@   )rL   rM   rN   rO   rP   rQ   )r   rL   rM   rN   rO   rP   rQ   s          r   __init__zLocalTrainContext.__init__   s4      /$$$ 0"r   r   c                     | j         S r@   )rL   r'   s    r   r(   z%LocalTrainContext.get_experiment_name   s    ##r   c                     | j         S r@   )rM   r'   s    r   r*   z LocalTrainContext.get_world_size   
    r   c                     | j         S r@   )rN   r'   s    r   r-   z LocalTrainContext.get_world_rank   rV   r   c                     | j         S r@   )rO   r'   s    r   r0   z LocalTrainContext.get_local_rank   rV   r   c                     | j         S r@   )rP   r'   s    r   r2   z&LocalTrainContext.get_local_world_size   s    $$r   c                     | j         S r@   )rQ   r'   s    r   r4   zLocalTrainContext.get_node_rank   s
    ~r   c                      t          d          )Nz+Local storage context not yet implemented. )NotImplementedErrorr'   s    r   r6   zLocalTrainContext.get_storage   s    !"OPPPr   N)rK   r   r   rK   r   )r7   r8   r9   r:   r;   r<   rS   r(   r*   r-   r0   r2   r4   r6   r&   r   r   rJ   rJ      s4       88
  !# ## # 	#
 # # # # # # $S $ $ $ $            %c % % % %s    Q Q Q Q Qr   rJ   N)abcr   r   typingr   r   (ray.train.v2._internal.execution.contextr   rA   ray.util.annotationsr   r	   r
   r   r>   rJ   r&   r   r   <module>ra      sA   # # # # # # # #              E D D D D D D D D D Xr r r r r3 r r rj : : : : :l : : :2 &Q &Q &Q &Q &Q &Q &Q &Q &Q &Qr   