a
    h                     @   sD   d dl mZ ddlmZ G dd deZG dd deZddgZdS )	   )PretrainedConfig   )Qwen2Configc                       s@   e Zd ZdZdZdeeeeeeeeeeed fddZ  Z	S )Ovis2VisionConfiga
  
    This is the configuration class to store the configuration of a [`Ovis2VisionModel`]. It is used to instantiate a
    Ovis2VisionModel model according to the specified arguments, defining the model architecture. Instantiating a configuration
    with the defaults will yield a similar configuration to that of Ovis2.

    Args:
        hidden_size (`int`, *optional*, defaults to 1024):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 2816):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 24):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 8):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_channels (`int`, *optional*, defaults to 3):
            Number of channels in the input images.
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 14):
            The size (resolution) of each patch.
        rms_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the RMSNorm layers.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        qkv_bias (`bool`, *optional*, defaults to `False`):
            Whether to add a learnable bias to the query, key, and value sequences at each attention head.
        mlp_bias (`bool`, *optional*, defaults to `False`):
            Whether to add a learnable bias to the MLP layers.
        hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"` and `"gelu_new"` `"quick_gelu"` are supported.
        vocab_size (`int`, *optional*, defaults to 16384):
            Vocabulary size of the Vision Transformer.
        hidden_stride (`int`, *optional*, defaults to 1):
            The stride of the hidden layer in the Vision Transformer.
        num_visual_indicator_tokens (`int`, *optional*, defaults to 5):
            Number of visual indicator tokens.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated normal initializer for initializing all weight matrices.
        tokenize_function (`str`, *optional*, defaults to `"softmax"`):
            The function used to tokenize the visual indicator tokens.
    vision_config            r         h㈵>        Fsilu @        {Gz?softmax)hidden_sizeintermediate_sizenum_hidden_layersnum_attention_headsnum_channels
image_size
patch_sizerms_norm_epsattention_dropoutqkv_biasmlp_biasc                    s|   t  jf i | || _|| _|| _|| _|| _|| _|| _|	| _	|| _
|
| _|| _|| _|| _|| _|| _|| _|| _d S )N)super__init__r   r   r   r   r   r   r   r   
hidden_actr   r   r   
vocab_sizehidden_stridenum_visual_indicator_tokenstokenize_functioninitializer_range)selfr   r   r   r   r   r   r   r   r   r   r   r"   r#   r$   r%   r'   r&   kwargs	__class__ i/var/www/html/assistant/venv/lib/python3.9/site-packages/transformers/models/ovis2/configuration_ovis2.pyr!   B   s$    zOvis2VisionConfig.__init__)r   r   r	   r
   r   r   r   r   r   FFr   r   r   r   r   r   )
__name__
__module____qualname____doc__Zbase_config_keyintfloatboolr!   __classcell__r,   r,   r*   r-   r      s@   +                 r   c                       s@   e Zd ZdZdZeedZdddg dddf fd	d
	Z  Z	S )Ovis2ConfigaQ  
    This is the configuration class to store the configuration of a [`Ovis2ForConditionalGeneration`]. It is used to instantiate a
    Ovis2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
    with the defaults will yield a similar configuration to that of Ovis2.

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

    e.g. [thisisiron/Ovis2-1B-hf](https://huggingface.co/thisisiron/Ovis2-1B-hf)

    Args:
        vision_config (`Union[AutoConfig, dict]`,  *optional*, defaults to `Ovis2VisionConfig`):
            The config object or dictionary of the vision backbone.
        text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `Qwen2Config`):
            The config object or dictionary of the text backbone.
        image_token_id (`int`, *optional*, defaults to 151665):
            The image token id to encode the image prompt.
        visual_indicator_token_ids (`List[int]`, *optional*, defaults to `[151666, 151667, 151668, 151669, 151670]`):
            The visual indicator token ids to encode the image prompt.
        vocab_size (`int`, *optional*, defaults to 151643):
            Vocabulary size of the text model.
        hidden_size (`int`, *optional*, defaults to 1536):
            Dimensionality of the encoder layers and the pooler layer.

    ```python
    >>> from transformers import Ovis2ForConditionalGeneration, Ovis2Config

    >>> # Initializing a Ovis2 style configuration
    >>> configuration = Ovis2Config()

    >>> # Initializing a model from the Ovis2-2B style configuration
    >>> model = Ovis2ForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```
    Zovis2)text_configr   NiqP )irP isP itP iuP ivP i[P i   c                    s   t |trtf i || _nt |tr,|| _|d u rDtt|d| _t |tr`tf i || _n"t |trr|| _n|d u rt | _|| _|| _|| _	|| _
t jf i | d S )N)r%   )
isinstancedictr   r   lenr   r7   r#   r   image_token_idvisual_indicator_token_idsr    r!   )r(   r   r7   r;   r<   r#   r   r)   r*   r,   r-   r!      s"    




zOvis2Config.__init__)
r.   r/   r0   r1   Z
model_typer   r   Zsub_configsr!   r5   r,   r,   r*   r-   r6   m   s   &
r6   N)Zconfiguration_utilsr   Zqwen2.configuration_qwen2r   r   r6   __all__r,   r,   r,   r-   <module>   s   YI