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   T/home/ubuntu/veenaModal/venv/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@     


"&
 