o
    `۷i                     @   s   U d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZmZmZ er?d dlmZ dad	ed
< e  Zde Zde ZeddG dd dZedddefddZdS )    N)TYPE_CHECKINGAnyDictOptional)session)StorageContext)V2_MIGRATION_GUIDE_MESSAGE_v2_migration_warnings_enabled)	_copy_doc_log_deprecation_warning)
DeprecatedDeveloperAPI	PublicAPI)PlacementGroupFactoryzOptional[TrainContext]_default_contextz`get_metadata` was an experimental API that accessed the metadata passed to `<Framework>Trainer(metadata=...)`. This API can be replaced by passing the metadata directly to the training function (e.g., via `train_loop_config`). z`{}` is deprecated because the concept of a `Trial` will soon be removed in Ray Train.Ray Train will no longer assume that it's running within a Ray Tune `Trial` in the future. stable)	stabilityc                   @   s  e Zd ZdZeejdefddZeejde	fddZeej
de	fddZ
eejde	fd	d
Zeejde	fddZeejde	fddZeeejdefddZeee deejdeeef fddZeede deejdefddZeede deejdefddZeede deejd"ddZeede deejdefdd Zd!S )#TrainContextzJContext containing metadata that can be accessed within Ray Train workers.returnc                 C      t  S N)r   get_experiment_nameself r   G/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/train/context.pyr   *      z TrainContext.get_experiment_namec                 C   r   r   )r   get_world_sizer   r   r   r   r   .   r   zTrainContext.get_world_sizec                 C   r   r   )r   get_world_rankr   r   r   r   r   2   r   zTrainContext.get_world_rankc                 C   r   r   )r   get_local_rankr   r   r   r   r   6   r   zTrainContext.get_local_rankc                 C   r   r   )r   get_local_world_sizer   r   r   r   r    :   r   z!TrainContext.get_local_world_sizec                 C   r   r   )r   get_node_rankr   r   r   r   r!   >   r   zTrainContext.get_node_rankc                 C   r   r   )r   get_storager   r   r   r   r"   B   s   zTrainContext.get_storage)messagewarningc                 C   r   r   )r   get_metadatar   r   r   r   r%   I      zTrainContext.get_metadataget_trial_namec                 C   r   r   )r   r'   r   r   r   r   r'   Q   r&   zTrainContext.get_trial_nameget_trial_idc                 C   r   r   )r   r(   r   r   r   r   r(   Y   r&   zTrainContext.get_trial_idget_trial_resourcesr   c                 C   r   r   )r   r)   r   r   r   r   r)   a   s   z TrainContext.get_trial_resourcesget_trial_dirc                 C   r   r   )r   r*   r   r   r   r   r*   k   r&   zTrainContext.get_trial_dirN)r   r   )__name__
__module____qualname____doc__r
   r   r   strr   intr   r   r    r!   r   r"   r   r   !_GET_METADATA_DEPRECATION_MESSAGEr	   r%   r   r   *_TUNE_SPECIFIC_CONTEXT_DEPRECATION_MESSAGEformatr'   r(   r)   r*   r   r   r   r   r   &   sb    r   r   c                  C   sr   ddl m}  |  rddlm} t rtdt  | S t tdu r&t	 atW  d   S 1 s2w   Y  dS )zGet or create a singleton training context.

    The context is only available within a function passed to Ray Train.

    See the :class:`~ray.train.TrainContext` API reference to see available methods.
    r   )_in_tune_session)get_contextz`ray.train.get_context()` should be switched to `ray.tune.get_context()` when running in a function passed to Ray Tune. This will be an error in the future. N)
%ray.tune.trainable.trainable_fn_utilsr4   ray.tuner5   r	   r   r   _context_lockr   r   )r4   get_tune_contextr   r   r   r5   t   s   $r5   )	threadingtypingr   r   r   r   ray.train._internalr   ray.train._internal.storager   ray.train.constantsr   r	   ray.train.utilsr
   r   ray.util.annotationsr   r   r   #ray.tune.execution.placement_groupsr   r   __annotations__Lockr8   r1   r2   r   r5   r   r   r   r   <module>   s.   
 	M