Ë
    T^(h�S  ã                   óŠ   — d dl mZ d dlmZ  ej                  e«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z	g d	¢Z
y
)é   )ÚPretrainedConfig)Úloggingc                   ó–   ‡ — e Zd ZdZddddddddœZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dded	ed
ededededededede	de	fˆ fd„Z
ˆ xZS )ÚLlama4VisionConfigaµ  
    This is the configuration class to store the configuration of a [`Llama4VisionModel`]. It is used to instantiate a
    Llama4 vision 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 Llama4 109B.

    e.g. [meta-llama/Llama-4-Scout-17B-16E](https://huggingface.co/meta-llama/Llama-4-Scout-17B-16E)

    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 768):
            Dimensionality of the encoder layers and the pooler layer.
        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"` `"quick_gelu"` are supported.
        num_hidden_layers (`int`, *optional*, defaults to 34):
            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):
            Number of channels in the input image.
        intermediate_size (`int`, *optional*, defaults to 5632):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        vision_output_dim (`int`, *optional*, defaults to 7680):
            Dimensionality of the vision model output. Includes output of transformer
            encoder with intermediate layers and global transformer encoder.
        image_size (`int`, *optional*, defaults to 448):
            The size (resolution) of each image *tile*.
        patch_size (`int`, *optional*, defaults to 14):
            The size (resolution) of each patch.
        norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the layer normalization layers.
        vision_feature_layer (``, *optional*, defaults to -1): TODO
        vision_feature_select_strategy (`int`, *optional*, defaults to `"default"`): TODO
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        pixel_shuffle_ratio (`int`, *optional*, defaults to 0.5): TODO
        projector_input_dim (`int`, *optional*, defaults to 4096): TODO
        projector_output_dim (`int`, *optional*, defaults to 4096): TODO
        multi_modal_projector_bias (`int`, *optional*, defaults to `False`): TODO
        projector_dropout (`int`, *optional*, defaults to 0.0): TODO
        attention_dropout (`int`, *optional*, defaults to 0.0): TODO
        rope_theta (`int`, *optional*, defaults to 10000): TODO
    ÚcolwiseÚrowwiseÚcolwise_rep)zmodel.layers.*.self_attn.q_projzmodel.layers.*.self_attn.k_projzmodel.layers.*.self_attn.v_projzmodel.layers.*.self_attn.o_projzvision_adapter.mlp.fc1zvision_adapter.mlp.fc2zpatch_embedding.linearÚllama4_vision_modelÚvision_configÚhidden_sizeÚ
hidden_actÚnum_hidden_layersÚnum_attention_headsÚnum_channelsÚintermediate_sizeÚvision_output_dimÚ
image_sizeÚ
patch_sizeÚnorm_epsÚinitializer_rangec                 ó<  •— || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        || _        || _        || _        || _        || _        || _        || _        || _        t)        ‰| �T  di |¤Ž y )N© )r   r   r   r   r   r   r   r   r   r   r   Úpixel_shuffle_ratioÚprojector_input_dimÚprojector_output_dimÚmulti_modal_projector_biasÚprojector_dropoutÚattention_dropoutÚvision_feature_layerÚvision_feature_select_strategyÚ
rope_thetaÚsuperÚ__init__)Úselfr   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   r   r   r   r!   ÚkwargsÚ	__class__s                         €úm/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/llama4/configuration_llama4.pyr#   zLlama4VisionConfig.__init__T   s°   ø€ ð0 'ˆÔØ$ˆŒØ!2ˆÔØ(ˆÔØ!2ˆÔØ$ˆŒØ!2ˆÔØ$ˆŒØ ˆŒØ#6ˆÔ Ø!2ˆÔØ#6ˆÔ Ø#6ˆÔ Ø$8ˆÔ!Ø*DˆÔ'Ø!2ˆÔØ!2ˆÔØ$8ˆÔ!Ø.LˆÔ+Ø$ˆŒÜ‰ÑÑ"˜6Ó"ó    )i   Úgelué"   é   r   i   i   iÀ  é   çñhãˆµøä>éÿÿÿÿÚdefaultç{®Gáz”?g      à?é   r1   Fç        r2   i'  )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úbase_model_tp_planÚ
model_typeÚbase_config_keyÚintÚstrÚfloatr#   Ú__classcell__©r&   s   @r'   r   r      sè   ø„ ñ,ð^ ,5Ø+4Ø+4Ø+4Ø"+Ø"+Ø"/ñÐð '€JØ%€Oð Ø Ø!#Ø#%ØØ!%Ø!%ØØØØØ'0Ø#'ØØ Ø!Ø#(ØØØñ+,#àð,#ð ð,#ð ð	,#ð
 !ð,#ð ð,#ð ð,#ð ð,#ð ð,#ð ð,#ð ð,#ð !÷,#ñ ,#r(   r   c                   óÞ   ‡ — e Zd ZdZdZdgZi dd“dd“dd“dd	“d
d“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚLlama4TextConfiga™  
    This is the configuration class to store the configuration of a [`Llama4TextModel`]. It is used to instantiate a
    Llama4 text 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 Llama4 109B.

    e.g. [meta-llama/Llama-4-Scout-17B-16E](https://huggingface.co/meta-llama/Llama-4-Scout-17B-16E)

    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 202048):
            Vocabulary size of the Llama4 text model. Defines the maximum number of different tokens that can be represented
            by the `inputs_ids` passed when calling [`Llama4TextModel`].
        hidden_size (`int`, *optional*, defaults to 5120):
            Dimensionality of the embeddings and hidden states.
        intermediate_size (`int`, *optional*, defaults to 8192):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        intermediate_size_mlp (`int`, *optional*, defaults to 16384): TODO
        num_hidden_layers (`int`, *optional*, defaults to 48):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 40):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_key_value_heads (`int`, *optional*, defaults to 8):
            This is the number of key_value heads that should be used to implement Grouped Query Attention. If not
            specified, will default to `num_attention_heads`.
        head_dim (`int`, *optional*, defaults to 128): TODO
        hidden_act (`str` or `Callable`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the encoder and pooler.
        max_position_embeddings (`int`, *optional*, defaults to 131072):
            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.
        pad_token_id (`int`, *optional*, defaults to 128004):
            The id of the padding token.
        bos_token_id (`int`, *optional*, defaults to 1):
            The id of the beginning of sentence token.
        eos_token_id (`int`, *optional*, defaults to 2):
            The id of the end of sentence token.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether to tie weight embeddings
        rope_theta (`float`, *optional*, defaults to `500000.0`):
            The base period of the RoPE embeddings.
        attention_dropout (`int`, *optional*, defaults to 0.0): TODO
        num_experts_per_tok (`int`, *optional*, defaults to 1): TODO
        num_local_experts (`int`, *optional*, defaults to 16): TODO
        moe_layers (`int`, *optional*): TODO
        interleave_moe_layer_step (`int`, *optional*, defaults to 1): TODO
        use_qk_norm (`int`, *optional*, defaults to `True`): TODO
        output_router_logits (`int`, *optional*, defaults to `False`): TODO
        router_aux_loss_coef (`int`, *optional*, defaults to 0.001): TODO
        router_jitter_noise (`int`, *optional*, defaults to 0.0): TODO
        rope_scaling (`Dict`, *optional*):
            Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
            and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
            accordingly.
            Expected contents:
                `rope_type` (`str`):
                    The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
                    'llama3'], with 'default' being the original RoPE implementation.
                `factor` (`float`, *optional*):
                    Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
                    most scaling types, a `factor` of x will enable the model to handle sequences of length x *
                    original maximum pre-trained length.
                `original_max_position_embeddings` (`int`, *optional*):
                    Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
                    pretraining.
                `attention_factor` (`float`, *optional*):
                    Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
                    computation. If unspecified, it defaults to value recommended by the implementation, using the
                    `factor` field to infer the suggested value.
                `beta_fast` (`float`, *optional*):
                    Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
                    ramp function. If unspecified, it defaults to 32.
                `beta_slow` (`float`, *optional*):
                    Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
                    ramp function. If unspecified, it defaults to 1.
                `short_factor` (`List[float]`, *optional*):
                    Only used with 'longrope'. The scaling factor to be applied to short contexts (<
                    `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
                    size divided by the number of attention heads divided by 2
                `long_factor` (`List[float]`, *optional*):
                    Only used with 'longrope'. The scaling factor to be applied to long contexts (<
                    `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
                    size divided by the number of attention heads divided by 2
                `low_freq_factor` (`float`, *optional*):
                    Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
                `high_freq_factor` (`float`, *optional*):
                    Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
            <TODO>
            <TODO>
        no_rope_layers (`int`, *optional*): TODO
        no_rope_layer_interval (`int`, *optional*, defaults to 4): TODO
        attention_chunk_size (`int`, *optional*, defaults to 8192):
            <TODO>
        attn_temperature_tuning (`int`, *optional*, defaults to 4): TODO
        floor_scale (`int`, *optional*, defaults to 8192): TODO
        attn_scale (`int`, *optional*, defaults to 0.1): TODO
        cache_implementation (`<fill_type>`, *optional*, defaults to `"hybrid"`): <fill_docstring>

    Example:
    Úllama4_textÚpast_key_valueszlayers.*.self_attn.q_projr   zlayers.*.self_attn.k_projzlayers.*.self_attn.v_projzlayers.*.self_attn.o_projr   zlayers.*.input_layernorm.weightÚsequence_parallelz(layers.*.post_attention_layernorm.weightznorm.weightz-layers.*.feed_forward.shared_expert.gate_projÚlocal_colwisez+layers.*.feed_forward.shared_expert.up_projz-layers.*.feed_forward.shared_expert.down_projÚlocal_rowwisez*layers.*.feed_forward.experts.gate_up_projÚlocal_packed_rowwisez'layers.*.feed_forward.experts.down_projzlayers.*.feed_forward.expertsÚlocalzlayers.*.feed_forward.gate_projzlayers.*.feed_forward.up_projzlayers.*.feed_forward.down_projzlayers.*.feed_forwardÚgatherc$                 óÎ  •— t        ‰'| �  d||||dœ|$¤Ž | | _        |"| _        |!| _        || _        |
| _        || _        || _        || _	        || _
        || _        || _        d| _        |#| _        |€|}|| _        |	| _        || _        || _        || _        || _        || _        |�|n| j                  | j                  z  | _        || _        || _        || _        || _        || _        || _        t;        | j                  «      D �%cg c]  }%t=        |%dz   |z  dk7  «      ‘Œ }&}%|r|n|&| _        || _         |�|ntC        t;        |dz
  ||«      «      | _"        || _#        y c c}%w )N)Úpad_token_idÚbos_token_idÚeos_token_idÚtie_word_embeddingsFé   é    r   )$r"   r#   Úattn_temperature_tuningÚ
attn_scaleÚfloor_scaleÚ
vocab_sizeÚmax_position_embeddingsr   r   Úintermediate_size_mlpr   r   Úrope_scalingÚattention_biasÚcache_implementationÚnum_key_value_headsr   r   Úrms_norm_epsÚ	use_cacher!   r   Úhead_dimÚuse_qk_normÚnum_experts_per_tokÚnum_local_expertsÚoutput_router_logitsÚrouter_aux_loss_coefÚrouter_jitter_noiseÚranger:   Úno_rope_layersÚinterleave_moe_layer_stepÚlistÚ
moe_layersÚattention_chunk_size)(r$   rS   r   r   rU   r   r   rY   r\   r   rT   r   rZ   r[   rJ   rK   rL   rM   r!   r   r^   r_   rg   re   r]   r`   ra   rb   rV   rd   Úno_rope_layer_intervalrh   rP   rR   rQ   rX   r%   Ú	layer_idxÚdefault_no_rope_layersr&   s(                                          €r'   r#   zLlama4TextConfig.__init__  sµ  ø€ ôN 	‰Ñð 	
Ø%Ø%Ø%Ø 3ñ		
ð
 ò	
ð (?ˆÔ$Ø$ˆŒØ&ˆÔØ$ˆŒØ'>ˆÔ$Ø&ˆÔØ!2ˆÔØ%:ˆÔ"Ø!2ˆÔØ#6ˆÔ Ø(ˆÔØ#ˆÔØ$8ˆÔ!àÐ&Ø"5Ðà#6ˆÔ Ø$ˆŒØ!2ˆÔØ(ˆÔØ"ˆŒØ$ˆŒØ!2ˆÔØ$,Ð$8™¸d×>NÑ>NÐRV×RjÑRjÑ>jˆŒØ&ˆÔà#6ˆÔ Ø!2ˆÔà$8ˆÔ!Ø$8ˆÔ!Ø#6ˆÔ äPUÐVZ×VlÑVlÓPmö"
ØCLŒC�˜Q‘Ð"8Ñ8¸AÑ=Õ>ð"
Ðð "
ñ
 1?™nÐDZˆÔà)BˆÔ&ð Ð%ñ ä”eÐ5¸Ñ9Ð;LÐNgÓhÓið 	Œð
 %9ˆÕ!ùò"
s   Ä	E")#i@ i   é    i @  é0   é(   é   é€   Úsilui   r0   r-   TNrN   é   Fi ¡ r2   rN   r+   NrN   TFgü©ñÒMbP?r2   NNé   rl   rs   rl   gš™™™™™¹?Úhybrid)	r3   r4   r5   r6   r8   Úkeys_to_ignore_at_inferencer7   r#   r=   r>   s   @r'   r@   r@   ƒ   sf  ø„ ñiðV €JØ#4Ð"5ÐðØ# Yðà# Yðð 	$ Yðð 	$ Yð	ð
 	*Ð+>ðð 	3Ð4Gðð 	Ð*ðð 	8¸ðð 	6°ðð 	8¸ðð 	5Ð6Lðð 	2°?ðð 	(¨ðð 	*¨?ðð 	(¨ðð  	*¨?ð!ð" 	  ð#Ðð, ØØØ#ØØØØØØ )ØØØØØØØ!ØØØØØØ"#ØØ"Ø"ØØØØ Ø!Ø !ØØØ%÷I\9ñ \9r(   r@   c                   óF   ‡ — e Zd ZdZdZeedœZddiZ	 	 	 	 	 	 dˆ fd„	Z	ˆ xZ
S )ÚLlama4Configa·  
    This is the configuration class to store the configuration of a [`Llama4Model`]. It is used to instantiate an
    Llama4 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 Llama4 109B.

    e.g. [meta-llama/Llama-4-Scout-17B-16E](https://huggingface.co/meta-llama/Llama-4-Scout-17B-16E)

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


    Args:
        vision_config (`Llama4VisionConfig`, *optional*):
            The Llama4 Vision config.
        text_config (`Llama4TextConfig`, *optional*):
            The Llama4 Text config.
        boi_token_index (`int`, *optional*, defaults to 200080):
            The begin-of-image token index to wrap the image prompt.
        eoi_token_index (`int`, *optional*, defaults to 200081):
            The end-of-image token index to wrap the image prompt.
        image_token_index (`int`, *optional*, defaults to 200092):
            The image token index to encode the image prompt.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether the model's input and output word embeddings should be tied.

    ```python
    >>> from transformers import Llama4Model, Llama4Config

    >>> # Initializing a Llama4 7B style configuration
    >>> configuration = Llama4Config()

    >>> # Initializing a model from the Llama4 7B style configuration
    >>> model = Llama4Model(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úllama4)Útext_configr   zmulti_modal_projector.linear_1r	   c                 óÎ  •— |€%t        «       | _        t        j                  d«       n8t	        |t
        «      rt        di |¤Ž| _        nt	        |t         «      r|| _        || _        || _        || _        |€%t        «       | _
        t        j                  d«       n8t	        |t
        «      rt        di |¤Ž| _
        nt	        |t        «      r|| _
        t        ‰| �0  dd|i|¤Ž y )Nz9vision_config is None, using default llama4 vision configz5text_config is None, using default llama4 text configrM   r   )r   r   ÚloggerÚinfoÚ
isinstanceÚdictÚboi_token_indexÚeoi_token_indexÚimage_token_indexr@   ry   r"   r#   )	r$   r   ry   r   r€   r�   rM   r%   r&   s	           €r'   r#   zLlama4Config.__init__‘  sÉ   ø€ ð Ð Ü!3Ó!5ˆDÔÜ�K‰KÐSÕTÜ˜¤tÔ,Ü!3Ñ!D°mÑ!DˆDÕÜ˜Ô'9Ô:Ø!.ˆDÔà.ˆÔØ.ˆÔØ!2ˆÔØÐÜ/Ó1ˆDÔÜ�K‰KÐOÕPÜ˜¤TÔ*Ü/Ñ>°+Ñ>ˆDÕÜ˜Ô%5Ô6Ø*ˆDÔä‰ÑÑKÐ-@ÐKÀFÓKr(   )NNi� i‘ iœ F)r3   r4   r5   r6   r8   r@   r   Úsub_configsr7   r#   r=   r>   s   @r'   rw   rw   d  sH   ø„ ñ$ðL €JØ"2ÐEWÑX€Kà(¨-ðÐð ØØØØ Ø!÷Lñ Lr(   rw   )rw   r@   r   N)Úconfiguration_utilsr   Úutilsr   Ú
get_loggerr3   r{   r   r@   rw   Ú__all__r   r(   r'   ú<module>r‡      s[   ðõ$ 4Ý ð 
ˆ×	Ñ	˜HÓ	%€ôg#Ð)ô g#ôT^9Ð'ô ^9ôBJLÐ#ô JLòZ E�r(   