
    &`i                         d dl mZ d dlmZmZmZ d dlZd dlm	Z	m
Z
 d dlmZ  e
            \  ZZ e	            \  ZZZed             Zed             Zedeee         ef         d	ee         fd
            ZdS )    )deque)AnyListUnionN)try_import_tftry_import_torch)DeveloperAPIc                     t           r4t                               |           rt                               |           S t          r9t                              |           rt          j                            |           S t          j        |           S )zCheck if a value is NaN.

    Args:
        value: The value to check.

    Returns:
        True if the value is NaN, False otherwise.
    )torch	is_tensorisnantfmathis_nannpvalues    w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/metrics/stats/utils.py
safe_isnanr      sn      "'' "{{5!!!	 %bll5!! %w~~e$$$8E??    c                 "   t           rRt          | t           j                  r8|                                                                                                 S t          r.t                              |           r|                                 S | S )zConvert a single value to CPU if it's a tensor.

    TensorFlow tensors are always converted to numpy/python values.
    PyTorch tensors are converted to python scalars.
    )	r   
isinstanceTensordetachcpuitemr   r   numpyr   s    r   single_value_to_cpur      ss      E5<00 ||~~!!##((***	 U## {{}}Lr   valuesreturnc                 8   | sg S t           rt          | d         t           j                  rat                               t	          |                     }|                                                                }|                                S t	          |           S )a  Convert a list or deque of GPU tensors to CPU scalars in a single operation.

    This function efficiently processes multiple PyTorch GPU tensors together by
    stacking them and performing a single .cpu() call. Assumes all values are either
    PyTorch tensors (on same device) or already CPU values.

    Args:
        values: A list or deque of values that may be GPU tensors.

    Returns:
        A list of CPU scalar values.
    r   )r   r   r   stacklistr   r   tolist)r   stacked
cpu_tensors      r   batch_values_to_cpur'   ,   s      	  #F1Iu|44 #++d6ll++^^%%))++
  """ <<r   )collectionsr   typingr   r   r   r   r   ray.rllib.utils.frameworkr   r   ray.util.annotationsr	   r   _r   r   r   r'    r   r   <module>r.      s         # # # # # # # # # #     E E E E E E E E - - - - - -q=??2q     
 
 
 d3i&6 7 DI      r   