
     `i<:                         d dl mZ d dlmZ ddlmZmZ  ej        e          Z	 G d de          Z
 G d de          Z G d	 d
e          Zg dZdS )   )PretrainedConfig)logging   )CONFIG_MAPPING
AutoConfigc                   P     e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z xZS )JanusVisionConfiga
  
    This is the configuration class to store the configuration of a [`JanusVisionModel`]. It is used to instantiate a
    `JanusVisionModel` according to the specified arguments, defining the model architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.
    Args:
        hidden_size (`int`, *optional*, defaults to 1024):
            Dimensionality of the encoder layers and the pooler layer.
        num_hidden_layers (`int`, *optional*, defaults to 24):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 16):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        patch_size (`int`, *optional*, defaults to 16):
            The size (resolution) of each patch.
        image_size (`int`, *optional*, defaults to 384):
            The size (resolution) of each image.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            Dropout probability for attention weights.
        layer_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the layer normalization layers.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"`, and `"gelu_new"` are supported.
        mlp_ratio (`float`, *optional*, defaults to 4.0):
            Ratio of MLP hidden dimensionality to embedding dimensionality.
        attention_bias (`bool`, *optional*, defaults to `True`):
            Whether to add a bias to the queries, keys, and values in the attention layers.
        hidden_dropout_rate (`float`, *optional*, defaults to 0.0):
            The dropout probability for fully connected layers in the encoder.
        projection_dim (`int`, *optional*, defaults to 2048):
            Dimensionality of the MLP projection head.
        projection_dropout (`float`, *optional*, defaults to 0.0):
            Dropout probability for the projection layer.
        use_qk_norm (`bool`, *optional*, defaults to `False`):
            Whether to normalize the query and key matrices.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated normal initializer for initializing all weight matrices.
        depth (`int`, *optional*, defaults to 2):
            Number of hidden layers in the aligner module.
        num_image_tokens (`int`, *optional*, defaults to 576):
            Number of image tokens.
    janus_vision_modelvision_config         r             ư>gelu      @T   F{Gz?r   @  c                 6    t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        d S N )super__init__hidden_sizenum_hidden_layersnum_attention_headsnum_channels
patch_size
image_sizeattention_dropoutlayer_norm_eps
hidden_act	mlp_ratioattention_biashidden_dropout_rateprojection_dimprojection_dropoutuse_qk_norminitializer_rangedepthnum_image_tokens)selfr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   kwargs	__class__s                       /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/models/janus/configuration_janus.pyr   zJanusVisionConfig.__init__P   s    , 	""6"""&!2#6 ($$!2,$",#6 ,"4&!2
 0    )r   r   r   r   r   r   r   r   r   r   Tr   r   r   Fr   r   r   )__name__
__module____qualname____doc__
model_typebase_config_keyr   __classcell__r0   s   @r1   r	   r	      s        , ,\ &J%O '*1 *1 *1 *1 *1 *1 *1 *1 *1 *1r2   r	   c                        e Zd ZdZdZdZdddddd	d	d
g ddddddddfdededededededededee         dede	f fdZ
 xZS )JanusVQVAEConfiga:
  
    This is the configuration class to store the configuration of a [`JanusVQVAEModel`]. It is used to instantiate a
    `JanusVQVAEModel` according to the specified arguments, defining the model architecture.
    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information. Instantiating a
    configuration with the defaults will yield a similar configuration to the VQModel of the
    [deepseek-community/Janus-Pro-1B](https://huggingface.co/deepseek-community/Janus-Pro-1B).

    Args:
        embed_dim (`int`, *optional*, defaults to 8):
            Dimensionality of each embedding vector.
        num_embeddings (`int`, *optional*, defaults to 16384):
            Number of codebook embeddings.
        double_latent (`bool`, *optional*, defaults to `False`):
            Whether to use double z channels.
        latent_channels (`int`, *optional*, defaults to 256):
            Number of channels for the latent space.
        num_patches (`int`, *optional*, defaults to 32):
            Num of patches the input images can be divided into.
        in_channels (`int`, *optional*, defaults to 3):
            Number of input channels.
        out_channels (`int`, *optional*, defaults to 3):
            Number of out channels.
        base_channels (`int`, *optional*, defaults to 128):
            Base channel count.
        channel_multiplier (`list[int]`, *optional*, defaults to `[1, 1, 2, 2, 4]`):
            Channel multipliers for each resolution.
        num_res_blocks (`int`, *optional*, defaults to 2):
            Number of residual blocks.
        dropout (`float`, *optional*, defaults to 0.0):
            Dropout rate.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        projection_dim (`int`, *optional*, defaults to 2048):
            Dimensionality of the MLP projection head.
        num_hidden_layers (`int`, *optional*, defaults to 2):
            Number of hidden layers in VAVAE MLP Connecter module.
        hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"silu"` and `"gelu_new"` are supported.
        image_token_embed_dim (`int`, *optional*, defaults to 2048):
            Dimension of image embeddings. It should be same as the dimensionality of text embeddings.
    janus_vqgan	vq_config   i @  F       r      )   rC   r   r      r   r   r   r   r   	embed_dimnum_embeddingsdouble_latentlatent_channelsnum_patchesin_channelsout_channelsbase_channelschannel_multipliernum_res_blocksdropoutc                     t                      j        di | || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        d S r   )r   r   rE   rF   rG   rH   rJ   rL   rM   rN   rO   r+   rI   rK   r(   r   r$   image_token_embed_dim)r.   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   r+   r(   r   r$   rQ   r/   r0   s                     r1   r   zJanusVQVAEConfig.__init__   s    ( 	""6"""",*.&*"4,!2&(,!2$%:"""r2   )r3   r4   r5   r6   r7   r8   intboollistfloatr   r9   r:   s   @r1   r<   r<   }   s        * *X J!O ##" (7"#$; $;$; $; 	$;
 $; $; $; $; $; !I$; $; $; $; $; $; $; $; $; $; $; $;r2   r<   c                   <     e Zd ZdZdZeeedZ	 	 	 	 d fd	Z	 xZ
S )JanusConfiga;  
    This is the configuration class to store the configuration of a [`JanusModel`]. It is used to instantiate an
    Janus model according to the specified arguments, defining the model architecture. Instantiating a configuration
    with the defaults will yield a similar configuration to that of the Janus-1B or Janus-7B models.

    e.g. [deepseek-community/Janus-Pro-1B](https://huggingface.co/deepseek-community/Janus-Pro-1B) or
    [deepseek-community/Janus-Pro-7B](https://huggingface.co/deepseek-community/Janus-Pro-7B)

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `LlamaConfig`):
            The config object or dictionary of the text backbone.
        vision_config (`Union[AutoConfig, dict]`,  *optional*, defaults to `JanusVisionConfig`):
            The config object or dictionary of the vision backbone.
        vq_config (`Union[AutoConfig, dict]`,  *optional*, defaults to `JanusVQVAEConfig`):
            The config object or dictionary of the VQVAE backbone.
        image_token_id (`int`, *optional*, defaults to 100581):
            Token index of a placeholder image token.

    Example:

    ```python
    >>> from transformers import JanusForConditionalGeneration, JanusConfig, JanusVisionConfig, JanusVQVAEConfig, LlamaConfig

    >>> # Initializing a Janus vision config
    >>> vision_config = JanusVisionConfig()

    >>> # Initializing a Llama config
    >>> text_config = LlamaConfig()

    >>> # Initializing a VQ config
    >>> vq_config = JanusVQVAEConfig()

    >>> # Initializing a Janus Pro 1B style configuration
    >>> configuration = JanusConfig(vision_config=vision_config, text_config=text_config, vq_config=vq_config)

    >>> # Initializing a model from the Janus Pro 1B style configuration
    >>> model = JanusForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```janus)text_configr   r>   N c                 x   t          |t                    r7|                    dd          |d<   t          |d                  d	i || _        nr|4t
                              d           t          d                     | _        n<t          |t                    r|| _        nt          dt          |                     |.t
                              d           t                      | _        nct          |t                    rt          d	i || _        n<t          |t                    r|| _        nt          dt          |                     |.t
                              d           t                      | _        nct          |t                    rt          d	i || _        n<t          |t                    r|| _        nt          dt          |                     | j        j        | _        | j        j        | j        j        z  | j        _        || _         t'                      j        d	i | d S )
Nr7   llamaz7`text_config` is None. Initializing with default valueszTInvalid type for `text_config`. Must be either `dict` or `LlamaConfig`. Type found: zK`vision_config` is None. Initializing with default JanusVisionConfig valuesz\Invalid type for `vision_config`. Must be either `dict` or `JanusVisionConfig`. Type found: zF`vq_config` is None. Initializing with default JanusVQVAEConfig valueszWInvalid type for `vq_config`. Must be either `dict` or `JanusVQVAEConfig`. Type found: r   )
isinstancedictgetr   rY   loggerinfor   
ValueErrortyper	   r   r<   r>   r+   r!   r    rI   image_token_idr   r   )r.   rY   r   r>   rd   r/   r0   s         r1   r   zJanusConfig.__init__	  s[    k4(( 	(3g(N(NK%-k,.GHWW;WWD KKQRRR-g688D%566 	*D4 $[ 1 14 4  
  KKefff!2!4!4Dt,, 	!2!C!C]!C!CD'899 	!.D6 $] 3 36 6  
 KK`aaa-//DNN	4(( 	-::	::DNN	#344 	&DNN2 $Y2 2  
 "&!3!E%)%7%BdFXFc%c",""6"""""r2   )NNNrZ   )r3   r4   r5   r6   r7   r   r	   r<   sub_configsr   r9   r:   s   @r1   rW   rW      sr        + +Z J!*% K 6# 6# 6# 6# 6# 6# 6# 6# 6# 6#r2   rW   )r<   r	   rW   N)configuration_utilsr   utilsr   autor   r   
get_loggerr3   r`   r	   r<   rW   __all__r   r2   r1   <module>rk      s  , 4 3 3 3 3 3       - - - - - - - - 
	H	%	%\1 \1 \1 \1 \1( \1 \1 \1~T; T; T; T; T;' T; T; T;nk# k# k# k# k#" k# k# k#\ C
B
Br2   