o
    `Û·ið#  ã                   @   sŽ  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZ erLd dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZ h d
£Zh d£Zh d£ZddhZh d£ZG dd„ deƒZde de
e  fdd„Z!d7dd„Z"dd„ Z#ded	 fdd„Z$d8d!d"„Z%d#d$„ Z&d%d&„ Z'd'e	ed(  d)ee e(f fd*d+„Z)d'e	ed(  d)e*fd,d-„Z+d9d0d1„Z,d)e*fd2d3„Z-d4ed)dfd5d6„Z.dS ):é    N)ÚEnum)ÚTYPE_CHECKINGÚDictÚListÚOptionalÚSetÚUnion)ÚTagKeyÚrecord_extra_usage_tag)ÚStorageContext©ÚBaseTrainer©ÚCallback©ÚTrialScheduler©ÚBasicVariantGeneratorÚSearcher>   ÚTorchTrainerÚHorovodTrainerÚXGBoostTrainerÚLightGBMTrainerÚTensorflowTrainer>   Ú
JaxTrainerr   r   r   r   ÚDataParallelTrainer>   ÚAxSearchÚTuneBOHBÚ
HEBOSearchÚZOOptSearchÚOptunaSearchÚBayesOptSearchÚHyperOptSearchÚNevergradSearchÚConcurrencyLimiterÚRepeater>	   ÚPB2ÚFIFOSchedulerÚHyperBandForBOHBÚHyperBandSchedulerÚMedianStoppingRuleÚAsyncHyperBandSchedulerÚPopulationBasedTrainingÚResourceChangingSchedulerÚPopulationBasedTrainingReplayc                   @   s   e Zd ZdZdZdZdZdS )ÚAirEntrypointz	Tuner.fitzTrainer.fitztune.runztune.run_experimentsN)Ú__name__Ú
__module__Ú__qualname__ÚTUNERÚTRAINERÚTUNE_RUNÚTUNE_RUN_EXPERIMENTS© r7   r7   úM/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/air/_internal/usage.pyr/   C   s
    r/   Úallowed_module_path_prefixÚ	whitelistc                 C   s(   | j }| jj}| |¡r||v r|S dS )a  Find the class name of the object. If the object is not
    under `allowed_module_path_prefix` or if its class is not in the whitelist,
    return "Custom".

    Args:
        obj: The object under inspection.
        allowed_module_path_prefix: If the `obj`'s class is not under
            the `allowed_module_path_prefix`, its class name will be anonymized.
        whitelist: If the `obj`'s class is not in the `whitelist`,
            it will be anonymized.
    Returns:
        The class name to be tagged with telemetry.
    ÚCustom)r1   Ú	__class__r0   Ú
startswith)Úobjr9   r:   Úmodule_pathÚcls_namer7   r7   r8   Ú_find_class_nameJ   s
   rA   Útrainerr   c                 C   ó6   ddl m} t| |ƒsJ ‚t| dtƒ}ttj|ƒ d S )Nr   r   ú	ray.train)Úray.train.trainerr   Ú
isinstancerA   ÚAIR_TRAINERSr
   r	   ÚAIR_TRAINER)rB   r   Útrainer_namer7   r7   r8   Útag_air_trainer`   ó   rJ   c                 C   rC   )Nr   )r   rD   )Ú&ray.train.v2.api.data_parallel_trainerr   rF   rA   ÚTRAIN_V2_TRAINERSr
   r	   ÚTRAIN_TRAINER)rB   r   rI   r7   r7   r8   Útag_train_v2_trainerh   rK   rO   Úsearcherc                 C   sj   ddl m}m} t| |ƒrttjdƒ d S t| |ƒr1t| dt 	t
¡ƒ}|t
v r)d S ttj|ƒ d S J dƒ‚)Nr   r   r   zray.tune.searchFzZNot expecting a non-BasicVariantGenerator, non-Searcher type passed in for `tag_searcher`.)Úray.tune.searchr   r   rF   r
   r	   ÚTUNE_SEARCHERrA   ÚTUNE_SEARCHERSÚunionÚTUNE_SEARCHER_WRAPPERS)rP   r   r   Úsearcher_namer7   r7   r8   Útag_searcherp   s   

ÿÿrW   Ú	schedulerr   c                 C   rC   )Nr   r   zray.tune.schedulers)Úray.tune.schedulersr   rF   rA   ÚTUNE_SCHEDULERSr
   r	   ÚTUNE_SCHEDULER)rX   r   Úscheduler_namer7   r7   r8   Útag_scheduler†   rK   r]   c                   C   ó   t tjdƒ d S ©NÚ1)r
   r	   Ú AIR_SETUP_WANDB_INTEGRATION_USEDr7   r7   r7   r8   Útag_setup_wandbŽ   ó   rb   c                   C   r^   r_   )r
   r	   Ú!AIR_SETUP_MLFLOW_INTEGRATION_USEDr7   r7   r7   r8   Útag_setup_mlflow’   rc   re   Ú	callbacksr   Úreturnc                 C   sì   ddl m} ddlm} ddlm} ddlm} ddlm	} ddl
m} ddlm} ||||f| }d	d
„ |D ƒ}	t t¡}
| pAg } | D ]/}t||ƒsLqD|jj}||	v r]|
|  d7  < qDt||ƒrk|
d  d7  < qD|
d  d7  < qD|
S )zHCreates a map of callback class name -> count given a list of callbacks.r   )ÚCometLoggerCallback)ÚMLflowLoggerCallback)ÚWandbLoggerCallbackr   )ÚLoggerCallback)ÚAimLoggerCallback)ÚDEFAULT_CALLBACK_CLASSESc                 S   s   g | ]}|j ‘qS r7   )r0   )Ú.0Úcallback_clsr7   r7   r8   Ú
<listcomp>§   s    z$_count_callbacks.<locals>.<listcomp>é   ÚCustomLoggerCallbackÚCustomCallback)Úray.air.integrations.cometrh   Úray.air.integrations.mlflowri   Úray.air.integrations.wandbrj   Úray.tuner   Úray.tune.loggerrk   Úray.tune.logger.aimrl   Úray.tune.utils.callbackrm   ÚcollectionsÚdefaultdictÚintrF   r<   r0   )rf   rh   ri   rj   r   rk   rl   rm   Úbuilt_in_callbacksÚcallback_namesÚcallback_countsÚcallbackÚcallback_namer7   r7   r8   Ú_count_callbacks–   s6   üû


rƒ   c                 C   s2   | sdS t | ƒ}|rt |¡}ttj|ƒ dS dS )a  Records built-in callback usage via a JSON str representing a
    dictionary mapping callback class name -> counts.

    User-defined callbacks will increment the count under the `CustomLoggerCallback`
    or `CustomCallback` key depending on which of the provided interfaces they subclass.
    NOTE: This will NOT track the name of the user-defined callback,
    nor its implementation.

    This will NOT report telemetry if no callbacks are provided by the user.

    Returns:
        bool: True if usage was recorded, False otherwise.
    FN)rƒ   ÚjsonÚdumpsr
   r	   ÚAIR_CALLBACKS)rf   r€   Úcallback_counts_strr7   r7   r8   Útag_callbacks¼   s   
þrˆ   Ústorager   c                 C   s>   h d£}| j r
d}n| jj|v r| jj}nd}ttj|ƒ dS )a§  Records the storage configuration of an experiment.

    The storage configuration is set by `RunConfig(storage_path, storage_filesystem)`.

    The possible storage types (defined by `pyarrow.fs.FileSystem.type_name`) are:
    - 'local' = pyarrow.fs.LocalFileSystem. This includes NFS usage.
    - 'mock' = pyarrow.fs._MockFileSystem. This is used for testing.
    - ('s3', 'gcs', 'abfs', 'hdfs'): Various remote storage schemes
        with default implementations in pyarrow.
    - 'custom' = All other storage schemes, which includes ALL cases where a
        custom `storage_filesystem` is provided.
    - 'other' = catches any other cases not explicitly handled above.
    >   Ús3ÚgcsÚabfsÚhdfsÚmockÚlocalÚcustomÚotherN)Úcustom_fs_providedÚstorage_filesystemÚ	type_namer
   r	   ÚAIR_STORAGE_CONFIGURATION)r‰   r:   Ústorage_config_tagr7   r7   r8   Útag_storage_typeÕ   s   
r—   c                  C   s|   ddl m}  ddlm} ddlm} ttƒ  | ||¡ƒ}g }|D ]}|t	j
v r,| |¡ q |r<t |¡}ttj|ƒ dS dS )ac  Records usage of environment variables exposed by the Ray AIR libraries.

    NOTE: This does not track the values of the environment variables, nor
    does this track environment variables not explicitly included in the
    `all_ray_air_env_vars` allow-list.

    Returns:
        bool: True if at least one environment var is supplied by the user.
    r   )ÚAIR_ENV_VARS)ÚTRAIN_ENV_VARS)ÚTUNE_ENV_VARSTF)Úray.air.constantsr˜   Úray.train.constantsr™   Úray.tune.constantsrš   ÚsortedÚsetrT   ÚosÚenvironÚappendr„   r…   r
   r	   )r˜   r™   rš   Úall_ray_air_env_varsÚuser_supplied_env_varsÚenv_varÚenv_vars_strr7   r7   r8   Útag_ray_air_env_varsï   s    
ÿ

€
r§   Ú
entrypointc                 C   s   | t v sJ ‚ttj| jƒ dS )z.Records the entrypoint to an AIR training run.N)r/   r
   r	   ÚAIR_ENTRYPOINTÚvalue)r¨   r7   r7   r8   Útag_air_entrypoint  s   r«   )rB   r   )rX   r   )r‰   r   )/r{   r„   r    Úenumr   Útypingr   r   r   r   r   r   Úray._common.usage.usage_libr	   r
   Úray.train._internal.storager   rE   r   rw   r   rY   r   rQ   r   r   rG   rM   rS   rU   rZ   r/   ÚstrrA   rJ   rO   rW   r]   rb   re   r}   rƒ   Úboolrˆ   r—   r§   r«   r7   r7   r7   r8   Ú<module>   s@     
þ

"&
 