o
    1 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>   ÚXGBoostTrainerZHorovodTrainerÚLightGBMTrainerÚTensorflowTrainerÚTorchTrainer>   Z
JaxTrainerÚDataParallelTrainerr   r   r   r   >   ZAxSearchZ
HEBOSearchZNevergradSearchZBayesOptSearchZTuneBOHBZOptunaSearchZZOOptSearchZHyperOptSearchZConcurrencyLimiterZRepeater>	   ZPB2ZFIFOSchedulerZResourceChangingSchedulerZPopulationBasedTrainingReplayZHyperBandForBOHBZHyperBandSchedulerZMedianStoppingRuleZAsyncHyperBandSchedulerZPopulationBasedTrainingc                   @   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__ZTUNERZTRAINERZTUNE_RUNZTUNE_RUN_EXPERIMENTS© r   r   úc/home/app/PaddleOCR-VL-test/.venv_paddleocr/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.
    ZCustom)r   Ú	__class__r   Ú
startswith)Úobjr    r!   Úmodule_pathÚcls_namer   r   r   Ú_find_class_nameJ   s
   r'   Ú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   Ú
isinstancer'   ÚAIR_TRAINERSr
   r	   ZAIR_TRAINER)r(   r   Útrainer_namer   r   r   Útag_air_trainer`   ó   r/   c                 C   r)   )Nr   )r   r*   )Z&ray.train.v2.api.data_parallel_trainerr   r,   r'   ÚTRAIN_V2_TRAINERSr
   r	   ZTRAIN_TRAINER)r(   r   r.   r   r   r   Útag_train_v2_trainerh   r0   r2   Ú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   r,   r
   r	   ZTUNE_SEARCHERr'   ÚTUNE_SEARCHERSÚunionÚTUNE_SEARCHER_WRAPPERS)r3   r   r   Zsearcher_namer   r   r   Útag_searcherp   s   

ÿÿr8   Ú	schedulerr   c                 C   r)   )Nr   r   zray.tune.schedulers)Úray.tune.schedulersr   r,   r'   ÚTUNE_SCHEDULERSr
   r	   ZTUNE_SCHEDULER)r9   r   Zscheduler_namer   r   r   Útag_scheduler†   r0   r<   c                   C   ó   t tjdƒ d S ©NÚ1)r
   r	   Z AIR_SETUP_WANDB_INTEGRATION_USEDr   r   r   r   Útag_setup_wandbŽ   ó   r@   c                   C   r=   r>   )r
   r	   Z!AIR_SETUP_MLFLOW_INTEGRATION_USEDr   r   r   r   Útag_setup_mlflow’   rA   rB   Ú	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 r   )r   )Ú.0Zcallback_clsr   r   r   Ú
<listcomp>§   s    z$_count_callbacks.<locals>.<listcomp>é   ZCustomLoggerCallbackZCustomCallback)Zray.air.integrations.cometrE   Zray.air.integrations.mlflowrF   Zray.air.integrations.wandbrG   Úray.tuner   Zray.tune.loggerrH   Zray.tune.logger.aimrI   Zray.tune.utils.callbackrJ   ÚcollectionsÚdefaultdictÚintr,   r"   r   )rC   rE   rF   rG   r   rH   rI   rJ   Zbuilt_in_callbacksZcallback_namesÚcallback_countsÚcallbackZcallback_namer   r   r   Ú_count_callbacks–   s6   üû


rT   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)rT   ÚjsonÚdumpsr
   r	   ZAIR_CALLBACKS)rC   rR   Zcallback_counts_strr   r   r   Útag_callbacks¼   s   
þrW   Ú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.
    >   ZabfsZhdfsÚlocalZgcsZs3ZmockZcustomÚotherN)Zcustom_fs_providedZstorage_filesystemÚ	type_namer
   r	   ZAIR_STORAGE_CONFIGURATION)rX   r!   Zstorage_config_tagr   r   r   Ú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)Zray.air.constantsr]   Zray.train.constantsr^   Zray.tune.constantsr_   ÚsortedÚsetr6   ÚosÚenvironÚappendrU   rV   r
   r	   )r]   r^   r_   Zall_ray_air_env_varsZuser_supplied_env_varsÚenv_varZenv_vars_strr   r   r   Útag_ray_air_env_varsï   s    
ÿ

€
rf   Ú
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	   ZAIR_ENTRYPOINTÚvalue)rg   r   r   r   Útag_air_entrypoint  s   ri   )r(   r   )r9   r   )rX   r   )/rO   rU   rb   Úenumr   Útypingr   r   r   r   r   r   Zray._common.usage.usage_libr	   r
   Zray.train._internal.storager   r+   r   rN   r   r:   r   r4   r   r   r-   r1   r5   r7   r;   r   Ústrr'   r/   r2   r8   r<   r@   rB   rQ   rT   ÚboolrW   r\   rf   ri   r   r   r   r   Ú<module>   s@     
þ

"&
 