o
    
۾i8                     @   s@   d dl mZ G dd deZG dd deZG dd deZdS )	    )PretrainedConfigc                       sV   e Zd ZdZdZ									
																	d fdd	Z  ZS )HunYuanVLVisionConfig
hunyuan_vlvision_configgelu    bilinearh㈵>r      N         T                   @     c                    s   t  jdi | || _|| _|| _|| _|| _|| _|s!|| _n|| _|	| _	|
| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _d S )N )super__init__
hidden_acthidden_sizeintermediate_sizeinterpolate_modelearnable_mlp_pooling_sizenum_attention_headsnum_key_value_headsnum_channelsnum_hidden_layersout_hidden_size
patch_sizeremove_prenormspatial_merge_sizetemporal_patch_sizerms_norm_epsresize_resolutionimg_max_token_nummax_image_sizemin_image_sizevideo_max_image_sizevideo_min_image_sizeanyres_vit_max_image_sizemax_vit_seq_lentext_hidden_size)selfr   r   r   r   r(   r   r   r    r!   r"   r#   r$   r%   r&   r'   r)   r*   r+   r-   r.   r,   r/   r0   r1   kwargs	__class__r   ^/home/ubuntu/.local/lib/python3.10/site-packages/vllm/transformers_utils/configs/hunyuan_vl.pyr      s6   
zHunYuanVLVisionConfig.__init__)r   r   r   r	   r
   r   r   Nr   r   r   r   Tr   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname__
model_typebase_config_keyr   __classcell__r   r   r4   r6   r   	   s8    r   c                       sf   e Zd ZdZdZdgZ									
														ddef fddZdd Z  Z	S )HunYuanVLTextConfiga*  
    This is the configuration class to store the configuration of a [`HunYuanVLTextConfig`]. It is used to instantiate an
    HunYuan 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 HunYuan-7B.
    Hunyuan-7B-Instruct [tencent/Hunyuan-7B-Instruct](https://huggingface.co/tencent/Hunyuan-7B-Instruct).

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


    Args:
        vocab_size (`int`, *optional*, defaults to 290943):
            Vocabulary size of the HunYuan model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`HunYuanVLTextConfig`]
        hidden_size (`int`, *optional*, defaults to 4096):
            Dimension of the hidden representations.
        intermediate_size (`int`, *optional*, defaults to 11008):
            Dimension of the MLP representations or shared MLP representations.
        num_hidden_layers (`int`, *optional*, defaults to 32):
            Number of hidden layers in the Transformer decoder.
        num_attention_heads (`int`, *optional*, defaults to 32):
            Number of attention heads for each attention layer in the Transformer decoder.
        num_key_value_heads (`int`, *optional*):
            This is the number of key_value heads that should be used to implement Grouped Query Attention. If
            `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
            `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
            converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
            by meanpooling all the original heads within that group. For more details checkout [this
            paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
            `num_attention_heads`.
        hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the decoder.
        max_position_embeddings (`int`, *optional*, defaults to 2048):
            The maximum sequence length that this model might ever be used with.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        rms_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the rms normalization layers.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models). Only
            relevant if `config.is_decoder=True`.
        pad_token_id (`int`, *optional*, defaults to 0):
            Padding token id.
        bos_token_id (`int`, *optional*, defaults to 1):
            Beginning of stream token id.
        eos_token_id (`int`, *optional*, defaults to 2):
            End of stream token id.
        eod_token_id (int, *optional*, defaults to 3):
            Token ID representing the end-of-document marker. Used to indicate the termination of a text sequence.
            Example: In multi-document processing, this token helps the model distinguish between separate documents.
        pretraining_tp (`int`, *optional*, defaults to 1):
            Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
            document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
            necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
            issue](https://github.com/pytorch/pytorch/issues/76232).
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether to tie weight embeddings
        rope_theta (`float`, *optional*, defaults to 10000.0):
            The base period of the RoPE embeddings.
        rope_scaling (`Dict`, *optional*):
            Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
            strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
            `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
            `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
            these scaling strategies behave:
            https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
            experimental feature, subject to breaking API changes in future versions.
        attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
            Whether to use a bias in the query, key, value and output projection layers during self-attention.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        head_dim (`int`, *optional*, defaults to 128):
            The attention head dimension.
    hunyuan_vl_textpast_key_valuesp r    +      Nsilur   {Gz?r
   Tr   r   r   r   F     @        r   c                    s   || _ || _|| _|| _|| _|| _|| _|d u r|}|| _|| _|	| _	|
| _
|| _|| _|| _|| _|| _|| _t jd||||d| d S )N)pad_token_idbos_token_ideos_token_idtie_word_embeddingsr   )
vocab_sizemax_position_embeddingsr   r   r"   r   head_dimr    r   initializer_ranger(   pretraining_tp	use_cache
rope_thetarope_scalingattention_biasattention_dropoutr   r   )r2   rK   r   r   r"   r   r    r   rL   rN   r(   rP   rG   rH   rI   eod_token_idrO   rJ   rQ   rR   rS   rT   rM   r3   r4   r   r6   r      s6   
zHunYuanVLTextConfig.__init__c                 C   s   | j du rdS t| j trt| j dkrtd| j  | j dd}| j dd}| j dd}|du s9|dvr@td| |du rL|du rLtd	|dur`t|trY|d
kr`td| |durtt|trm|d
krvtd| dS dS )z<
        Validate the `rope_scaling` configuration.
        Nr   zi`rope_scaling` must be a dictionary with with two fields, `type` and `factor` or `type` and `alpha`, got typefactoralpha)lineardynamiczF`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got zI`rope_scaling`'s factor or alpha field must be have one, got both of noneg      ?z9`rope_scaling`'s factor field must be a float > 1.0, got z8`rope_scaling`'s alpha field must be a float > 1.0, got )rR   
isinstancedictlen
ValueErrorgetfloat)r2   rope_scaling_typerope_scaling_factorrope_scaling_alphar   r   r6   _rope_scaling_validation   sR   
z,HunYuanVLTextConfig._rope_scaling_validation)r@   r   rA   rB   rB   NrC   r   rD   r
   Tr   r   r   r   r   FrE   NFrF   N)
r7   r8   r9   __doc__r:   keys_to_ignore_at_inferenceintr   rd   r<   r   r   r4   r6   r=   I   s<    K9r=   c                       sZ   e Zd ZdZeedZdgZ									
d fdd	Z fddZ	 fddZ
  ZS )HunYuanVLConfigr   )r   text_configr?   N6 7 8 9 : ; c	           
         s   t  jdi |	 t|tr| jd di || _n|d u r%| jd  | _t|tr6| jd di || _n|d u rE| jd di |	| _|| _|| _|| _	|| _
|| _|| _| jj| j_|	dd | _d S )Nr   ri   attn_implementationr   )r   r   r[   r\   sub_configsr   ri   image_token_idim_start_id	im_end_idim_newline_idvideo_start_idvideo_end_idr   r1   pop_attn_implementation)
r2   ri   r   rs   rt   rr   ru   rv   rw   r3   r4   r   r6   r     s"   

zHunYuanVLConfig.__init__c                    sN   t  dd }d ur|dvr||jv rt||| d S t  || d S )N__dict__ri   )dtype_attn_implementation_internal)r   __getattribute__r_   rz   setattr__setattr__)r2   keyvalueri   r4   r   r6   r   ,  s   
zHunYuanVLConfig.__setattr__c                    sD   dt  dv r|dvrt  d}||jv rt||S t  |S )Nri   rz   )_name_or_pathr:   r{   r|   )r   r}   rz   getattr)r2   r   ri   r4   r   r6   r}   7  s
   

z HunYuanVLConfig.__getattribute__)NNrj   rk   rl   rm   rn   ro   )r7   r8   r9   r:   r   r=   rq   rf   r   r   r}   r<   r   r   r4   r6   rh      s"    *rh   N)transformersr   r   r=   rh   r   r   r   r6   <module>   s
   @ 2