
    &`i                        d dl Z d dlZd dlZd dlmZmZmZmZ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mZmZmZmZ  ej        e          Zerd dlmZ eeefZde	ee         eee                  ef         dee         fd	Zddddddd
deee                  ded         dee         dee         dee         dee         deee                  dee         fdZ dee         fdZ!dS )    N)TYPE_CHECKING
CollectionListOptionalTypeUnion)CallbackCallbackList)RAY_TUNE_CALLBACKS_ENV_VAR)	CSVLoggerCSVLoggerCallback
JsonLoggerJsonLoggerCallbackLegacyLoggerCallback	TBXLoggerTBXLoggerCallback)AirVerbosity	callbacksreturnc                 B    g }| D ]}|t          |j                  z  }|S N)list_SAVED_FILE_TEMPLATES)r   	templatescallbacks      k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/utils/callback.py%_get_artifact_templates_for_callbacksr      s5     I : :T(8999		    )air_verbosity
entrypointmetricmodeconfigprogress_metricsr   r   r    r!   r"   r#   r$   c          	      ^   | pg } t                      }|                     |           d}d}	d}
ddlm t	          fd| D                       }|r,|*t
                              d           fd| D             }|} |.ddlm}  ||d	|||||
          }| 	                    |           n$|s" ||          }| 	                    |           t          |           D ]\  }}t          |t                    r1t          |j        v rd}t          |j        v rd}	t           |j        v rd}
Kt          |t"                    rd}ct          |t$                    rd}	{t          |t&                    rd}
t(          j                            dd          dk    r|s!| 	                    t#                                 |	s!| 	                    t%                                 |
sM	 | 	                    t'                                 n*# t.          $ r t
                              d           Y nw xY w| S )a  Create default callbacks for `Tuner.fit()`.

    This function takes a list of existing callbacks and adds default
    callbacks to it.

    Specifically, three kinds of callbacks will be added:

    1. Loggers. Ray Tune's experiment analysis relies on CSV and JSON logging.
    2. Syncer. Ray Tune synchronizes logs and checkpoint between workers and
       the head node.
    2. Trial progress reporter. For reporting intermediate progress, like trial
       results, Ray Tune uses a callback.

    These callbacks will only be added if they don't already exist, i.e. if
    they haven't been passed (and configured) by the user. A notable case
    is when a Logger is passed, which is not a CSV or JSON logger - then
    a CSV and JSON logger will still be created.

    Lastly, this function will ensure that the Syncer callback comes after all
    Logger callbacks, to ensure that the most up-to-date logs and checkpoints
    are synced across nodes.

    Fr   )TrialProgressCallbackc              3   8   K   | ]}t          |          V  d S r   
isinstance.0cr&   s     r   	<genexpr>z,_create_default_callbacks.<locals>.<genexpr>T   s?       & &12
1+,,& & & & & &r   Nz?AIR_VERBOSITY is set, ignoring passed-in TrialProgressCallback.c                 4    g | ]}t          |          |S  r(   r*   s     r   
<listcomp>z-_create_default_callbacks.<locals>.<listcomp>\   s9     
 
 

16K(L(L

 
 
r   )_detect_reporter   )num_samplesr    r!   r"   r#   r$   )r!   r$   T"TUNE_DISABLE_AUTO_CALLBACK_LOGGERS01zThe TensorboardX logger cannot be instantiated because either TensorboardX or one of it's dependencies is not installed. Please make sure you have the latest version of TensorboardX installed: `pip install -U tensorboardx`)_initialize_env_callbacksextendray.tune.progress_reporterr&   anyloggerwarningray.tune.experimental.outputr1   append	enumerater)   r   r   logger_classesr   r   r   r   r   osenvirongetImportError)r   r   r    r!   r"   r#   r$   env_callbackshas_csv_loggerhas_json_loggerhas_tbx_loggerhas_trial_progress_callbacknew_callbacks_detect_air_reporterair_progress_reportertrial_progress_callbackir   r&   s                     @r   _create_default_callbacksrO   '   s   B RI .//M]###NON@@@@@@"% & & & &6?& & & # # # "}'@M	
 	
 	

 
 
 
 
 
 
 "	 	
 	
 	
 	
 	
 	
 !5 4!-!
 !
 !
 	.////( 2"7"7,<#
 #
 #
 	0111 !++ " "8h 455 	"H333!%X444"&H333!%"344 	"!NN"455 	""OO"344 	"!N 
z~~:C@@CGG 	2.00111 	3/11222 		  !2!4!45555   O     s   !!H $H*)H*c            	      ^   g } t           j                            t          d          }|s| S |                    d          D ]}|                                }|s	 |                    dd          \  }}t          j        |          }t          ||          }t          |t                    s't          d| dt          |          j                    |            }|                     |           # t           t"          t$          t          f$ r}t%          d| d          |d	}~ww xY w| S )
zInitialize callbacks from environment variable.

    Returns:
        List of callbacks initialized from environment variable.
     ,.r2   zCallback class 'z&' must be a subclass of Callback, got z Failed to import callback from ''N)rA   rB   rC   r   splitstriprsplit	importlibimport_modulegetattr
issubclassr	   	TypeErrortype__name__r>   rD   AttributeError
ValueError)	r   callbacks_strcallback_pathmodule_path
class_namemodulecallback_clsr   es	            r   r7   r7      sn    IJNN#=rBBM &,,S11 Y Y%++-- 		Y&3&:&:3&B&B#K,[99F"6:66LlH55 C} C C%),%7%7%@C C   $|~~HX&&&&^ZC 	Y 	Y 	YPPPPQQWXX	Y s   BC44D*D%%D*)"rX   loggingrA   typingr   r   r   r   r   r   ray.tune.callbackr	   r
   ray.tune.constantsr   ray.tune.loggerr   r   r   r   r   r   r   	getLoggerr^   r;   r=   r   DEFAULT_CALLBACK_CLASSESstrr   dictrO   r7   r/   r   r   <module>rq      s<        				 I I I I I I I I I I I I I I I I 4 4 4 4 4 4 4 4 9 9 9 9 9 9                  
	8	$	$ :999999  T(^T$x.%9<GH	#Y    /3 $ !26o o oX'o N+o 	o
 SMo 3-o TNo z#/o 
(^o o o od4>      r   