
    &`i(                         d dl mZmZmZ d dlmZ d dlmZmZm	Z	 e	 	 ddeeee
f                  de
fd            Zeddeee
ef                  de
fd
            Zed             Zedd            ZdS )    )CallableOptionalUnion)DeveloperAPI)try_import_jaxtry_import_tftry_import_torchNtfname	frameworkc                    t          |           r| S t          | t                    r|                                 n| }|dk    rl|dv rdS t	                      \  }}t          || d          }||S |dv r|j        S |dk    r|j        S |dk    r|j        S |dk    r|j	        S |dk    r|j
        S n|d	k    r^|dv rdS t                      \  }}|dv r|j        j        S |dk    r|j        j        S |dk    r|j        j        S |dk    r|j        j        S nS|d
v sJ d                    |                      |dv rdS t%                      \  }}}	t          |j        |d          }||S t'          d                    | |                    )a  Returns a framework specific activation function, given a name string.

    Args:
        name: One of "relu" (default), "tanh", "elu",
            "swish" (or "silu", which is the same), or "linear" (same as None).
        framework: One of "jax", "tf|tf2" or "torch".

    Returns:
        A framework-specific activtion function. e.g. tf.nn.tanh or
            torch.nn.ReLU. None if name in ["linear", None].

    Raises:
        ValueError: If name is an unknown activation function.
    torch)linearNN)swishsilurelutanhelusoftmaxjaxr
   tf2Unsupported framework `{}`!)Unknown activation ({}) for framework={}!)callable
isinstancestrlowerr	   getattrSiLUReLUTanhELUSoftmaxr   nnr   r   	hard_tanhr   formatr   
ValueError)
r   r   
name_lower_r%   fnr   tf1r
   tfvs
             j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/models/utils.pyget_activation_fnr/      s   ( ~~ !+D#!6!6@DJ G)))4 ""2 Rt$$>I***7N6!!7N6!!7N5  6M9$$: %	e		)))4!!Q***6<6;6!!6##5  6: ! M)))+H+O+O,
 ,
))) )))4$R RUJ-->I
3::4KK      r   c                    t          |           s| | S |dk    rt          | t                    r|                                 n| }t	                      \  }}|                    d          st          d|  d          t          |j        |d          }||S t          d| d          |dk    rDt                      \  }}}t          |j
        j        | d          }||S t          d	|  d
          dS )a  Returns the framework-specific initializer class or function.

    This function relies fully on the specified initializer classes and
    functions in the frameworks `torch` and `tf2` (see for `torch`
    https://pytorch.org/docs/stable/nn.init.html and for `tf2` see
    https://www.tensorflow.org/api_docs/python/tf/keras/initializers).

    Note, for framework `torch` the in-place initializers are needed, i.e. names
    should end with an underscore `_`, e.g. `glorot_uniform_`.

    Args:
        name: Name of the initializer class or function in one of the two
            supported frameworks, i.e. `torch` or `tf2`.
        framework: The framework string, either `torch  or `tf2`.

    Returns:
        A framework-specific function or class defining an initializer to be used
        for network initialization,

    Raises:
        `ValueError` if the `name` is neither class or function in the specified
        `framework`. Raises also a `ValueError`, if `name` does not define an
        in-place initializer for framework `torch`.
    Nr   r*   zNot an in-place initializer: Torch weight initializers need to be provided as their in-place version, i.e. <initializaer_name> + '_'. See https://pytorch.org/docs/stable/nn.init.html. User provided .zUnknown initializer name: z$ is not a method in `torch.nn.init`!r   zUnknown initializer: z1 is not a initializer in `tf.keras.initializers`!)r   r   r   r   r	   endswithr(   r   initr   kerasinitializers)r   r   r)   r*   r%   r+   r
   s          r.   get_initializer_fnr7   W   sS   8 ~~ G%/c%:%:DTZZ\\\
 ""2 ""3'' 	) "&	) ) )   RWj$//>I #Z # # #   
e		
 !??2q RX*D$77>I + + + +   
	r0   c                 j   dddgdgdddgdgdddgdgg}dddgdgdddgdgdddgdgg}dddgdgdddgdgd	ddgdgd
ddgdgg}dddgdgdddgdgdddgdgg}dddgdgdddgdgg}t          |           } t          |           dv r"| dd         ddgk    s| dd         ddgk    r|S t          |           dv r"| dd         ddgk    s| dd         ddgk    r|S t          |           dv r"| dd         d	d	gk    s| dd         d	d	gk    r|S t          |           dv r"| dd         ddgk    s| dd         ddgk    r|S t          |           dv r"| dd         ddgk    s| dd         ddgk    r|S t          |           g dk    rd}nd}t          d                    |           |z   dz             )a  Returns a default Conv2D filter config (list) for a given image shape.

    Args:
        shape (Tuple[int]): The input (image) shape, e.g. (84,84,3).

    Returns:
        List[list]: The Conv2D filter configuration usable as `conv_filters`
            inside a model config dict.
                             @         )r=      N`   T   *   
   )      rD   zThis is the default atari obs shape. You may want to look at one of RLlib's Atari examples for an example of how to wrap an Atari env.  z/No default CNN configuration for obs shape {}. a  You can specify `conv_filters` manually through your AlgorithmConfig's model_config. Default configurations are only available for inputs of the following shapes: [42, 42, K], [84, 84, K], [64, 64, K], [10, 10, K]. You may want to use a custom RLModule or a ConnectorV2 for that.)listlenr(   r'   )shapefilters_96x96filters_84x84filters_64x64filters_42x42filters_10x10
atari_helps          r.   get_filter_configrU      s    
aVQ	aVQ	r2hM 
aVQ	aVQ	r2hM 
aVQ	aVQ	aVQ	q!fa	M 
aVQ	aVQ	r2hM 
aVQ	aVQM
 KKE
5zzVrrr2h!6!6%)Bx:O:O	Uv		5!9R#8#8E!""I"b<Q<Q	Uv		5!9R#8#8E!""I"b<Q<Q	Uv		5!9R#8#8E!""I"b<Q<Q	Uv		5!9R#8#8E!""I"b<Q<Q;;---''V J
 J=DDUKKGG
 
 	
r0   c                    t          |           r| S |dk    r_t                      \  }}|
J d            ddlm} | dv r|j                                        S | dk    r|j                                        S |dk    r@t                      \  }}|
J d            | dv r|j        j	        S | dk    r|j        j
        S nk|d	v sJ d
                    |                      t                      \  }}}|
J d            | dv r|j        j        j        S | dk    r|j        j        j        S t!          d                    | |                    )a  Returns a framework specific initializer, given a name string.

    Args:
        name: One of "xavier_uniform" (default), "xavier_normal".
        framework: One of "jax", "tf|tf2" or "torch".

    Returns:
        A framework-specific initializer function, e.g.
            tf.keras.initializers.GlorotUniform or
            torch.nn.init.xavier_uniform_.

    Raises:
        ValueError: If name is an unknown initializer.
    r   Nz1`flax` not installed. Try `pip install jax flax`.r   )Ndefaultxavier_uniformxavier_normalr   z/`torch` not installed. Try `pip install torch`.r   r   z9`tensorflow` not installed. Try `pip install tensorflow`.r   )r   r   
flax.linenlinenr6   rX   rY   r	   r4   xavier_uniform_xavier_normal_r'   r   r5   GlorotUniformGlorotNormalr(   )r   r   r*   flaxr%   r,   r
   r-   s           r.   get_initializerra      s   " ~~ E ""4!T666?11333_$$?00222G ""2~~P~~~6667**_$$7)) % M)))+H+O+O,
 ,
))) %RNNF NN6668(66_$$8(55
3::4KK  r0   )Nr
   )r   )r
   )typingr   r   r   ray.rllib.utils.annotationsr   ray.rllib.utils.frameworkr   r   r	   r   r/   r7   rU   ra    r0   r.   <module>rf      s6   , , , , , , , , , , 4 4 4 4 4 4 U U U U U U U U U U +/L L
53'
(LL L L L^ M MXeCM&:; M M M M M` D
 D
 D
N 2 2 2 2 2 2r0   