
    &`i                         d dl mZmZmZmZmZmZ d dlZd dlm	Z	 d dl
mZ d 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 d d
lmZ d dlmZ d dlmZ erd dlmZ  G d de          ZdS )    )TYPE_CHECKINGAnyCallableDictListOptionalN)DataIterator)DEFAULT_MODULE_ID)MultiRLModuleSpec)INPUT_ENV_SPACES)OfflineData)OfflineEvaluationRunner)OfflinePolicyEvaluationRunnerOfflinePolicyPreEvaluator)OfflinePreLearner)override)RunnerGroup)AlgorithmConfigc                   J    e Zd Z	 	 	 	 	 	 	 	 ddddee         dee         d	ee         d
ededeeeef                  deeef         dee	         deeef         ddf fdZ
 ee          dddddddded         dedee         deeef         dee	         deeeef                  deeef         ddf fd            Zed             Zedefd            Zedefd            Zedefd            Zed             Zed             Zed             Zed             Z xZS )OfflineEvaluationRunnerGroupFNr   Tconfigr   local_runnerlogdirtune_trial_id	pg_offset_setupspacesmodule_statemodule_speckwargsreturnc
                 \    t                                          ||||||||	|	  	         d S )N)	r   r   r   r   r   r   r   r   r   )super__init__)selfr   r   r   r   r   r   r   r   r   r    	__class__s              /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/offline/offline_evaluation_runner_group.pyr$   z%OfflineEvaluationRunnerGroup.__init__   sK    " 	%'%# 	 
	
 
	
 
	
 
	
 
	
    )r   num_runnersr   r   r   r   r)   c          	      $   |j         p|j        dk    rt          nt          | _        | j        j        p|j        dk    rt          nt          | _	        d| j        _
        | j	        | j        _        d| j        _
        |dk    r|rt          d|d          t                                          |||d|||           t          |          | _        |pt           |j        |j        fi}|| j        _        |p7| j                            t*          |t                    i| j        j        	          }|| j        _        | j        dk    rb|                     d
           }| j        9|                    dt9          j                                                               || j        _        | j         !                    | j        j"        d||          | _#        |                     d|d | j#        D                        | $                                 d S )N	eval_lossFTr   z:Cannot run `OfflineEvaluationRunnerGroup with num_runners=zI and a local runner. Either use no remote runners or only remote runners.)r   r)   r   validater   r   r   )r   )r   inference_onlyc                 L    t          j                                                    S N)rayget_runtime_contextget_node_id)_s    r'   <lambda>z5OfflineEvaluationRunnerGroup._setup.<locals>.<lambda>w   s    #133??AA r(   )num_samplesreturn_iterator
num_shardsr   set_dataset_iteratorc                     g | ]}d |iS )iterator ).0r:   s     r'   
<listcomp>z7OfflineEvaluationRunnerGroup._setup.<locals>.<listcomp>   s*       +3X&  r(   )funcr   r    )%offline_eval_runner_classoffline_evaluation_typer   r   _runner_clsr   prelearner_classr   r   _pre_learner_or_evaluator_cls
_is_frozen
ValueErrorr#   r   r   _offline_datar   observation_spaceaction_spacer   get_multi_rl_module_specr
   %offline_eval_rl_module_inference_onlyr   num_remote_runnersforeach_runnerr   insertr0   r1   r2   locality_hintsoffline_datasample"offline_eval_batch_size_per_runner_offline_data_iteratorsr,   )
r%   r   r)   r   r   r   r   r    runner_node_idsr&   s
            r'   r   z#OfflineEvaluationRunnerGroup._setup4   sn    "; 
-<< $#. 	 .2[-I .
-<< * 	*
 "''+'I$!% ??|?" " " "   	#%#% 	 		
 		
 		
 +6V*D*D*D 
v79LM
 %+!)4 *
8\8\%v.>'?@;L 9] 9
 9

 *5& "Q&&"11AA O  ,&&q#*A*C*C*O*O*Q*QRRR0?D-;?;L;S;SF "%	 <T <
 <
$ 	'% 7;7S   	 	
 	
 	
 	r(   c                     | j         j        S )z>Number of seconds to wait for health probe calls to `Runner`s.)r   *offline_eval_runner_health_probe_timeout_sr%   s    r'   runner_health_probe_timeout_sz:OfflineEvaluationRunnerGroup.runner_health_probe_timeout_s   s     {EEr(   c                     | j         S )zClass for each runner.)rA   rV   s    r'   
runner_clsz'OfflineEvaluationRunnerGroup.runner_cls   s     r(   c                     | j         j        S )z)Number of runners to schedule and manage.)r   num_offline_eval_runnersrV   s    r'   r)   z(OfflineEvaluationRunnerGroup.num_runners   s     {33r(   c                     | j         S r/   )rF   rV   s    r'   rO   z)OfflineEvaluationRunnerGroup.offline_data   s    !!r(   c                 |    | j         j        | j         j        | j         j        | j        j        r| j        j        nddS )z!Remote arguments for each runner.r   )num_cpusnum_gpus	resourcesmax_restarts)_remote_config num_cpus_per_offline_eval_runner num_gpus_per_offline_eval_runner(custom_resources_per_offline_eval_runnerr   #restart_failed_offline_eval_runners$max_num_offline_eval_runner_restartsrV   s    r'   _remote_argsz)OfflineEvaluationRunnerGroup._remote_args   sJ     +L+L,U ;B@@	
 	
 		
r(   c                 2    | j         j        p| j         j        S )z'If errors in runners should be ignored.)r   #ignore_offline_eval_runner_failuresrf   rV   s    r'   _ignore_ray_errors_on_runnersz:OfflineEvaluationRunnerGroup._ignore_ray_errors_on_runners   s     K; ?{>	
r(   c                     | j         j        S )z&Maximum requests in flight per runner.)r   .max_requests_in_flight_per_offline_eval_runnerrV   s    r'   "_max_requests_in_flight_per_runnerz?OfflineEvaluationRunnerGroup._max_requests_in_flight_per_runner   s     {IIr(   c                     | j         j        S )z.If runners should validated after constructed.)r   0validate_offline_eval_runners_after_constructionrV   s    r'   $_validate_runners_after_constructionzAOfflineEvaluationRunnerGroup._validate_runners_after_construction   s     {KKr(   )FNNr   TNNN)__name__
__module____qualname__r   boolstrintr   r   r   r$   r   r   r   propertyrW   r   rY   r)   r   rO   rh   rk   rn   rq   __classcell__)r&   s   @r'   r   r      s        (- $'++/'+37
 
!
 tn
 	

  }
 
 
 c3h(
 38n
 /0
 sCx.
 

 
 
 
 
 
: Xk /3','+37+/W W W *+W 	W
 tnW 38nW /0W c3h(W sCx.W 
W W W W W Wr F F XF  H       X  4S 4 4 4 X4 "k " " " X" 
 
 X
 
 
 X
 J J XJ L L XL L L L Lr(   r   ) typingr   r   r   r   r   r   r0   ray.data.iteratorr	   ray.rllib.corer
   (ray.rllib.core.rl_module.multi_rl_moduler   ray.rllib.envr   ray.rllib.offline.offline_datar   +ray.rllib.offline.offline_evaluation_runnerr   2ray.rllib.offline.offline_policy_evaluation_runnerr   r   $ray.rllib.offline.offline_prelearnerr   ray.rllib.utils.annotationsr   $ray.rllib.utils.runners.runner_groupr   %ray.rllib.algorithms.algorithm_configr   r   r;   r(   r'   <module>r      sn   E E E E E E E E E E E E E E E E 



 * * * * * * , , , , , , F F F F F F * * * * * * 6 6 6 6 6 6 O O O O O O        C B B B B B 0 0 0 0 0 0 < < < < < < FEEEEEEiL iL iL iL iL; iL iL iL iL iLr(   