Ë
    T^(h5-  ã                   ó`   — d Z ddlmZ ddlmZ  ej
                  e«      Z G d„ de«      ZdgZ	y)zPhi-3 model configurationé   )ÚPretrainedConfig)Úloggingc                   óœ   ‡ — e Zd ZdZdZdgZdddddœZdgdgfd	d
gd	gfd	gd	gfdœZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zd„ Z	d„ Z
ˆ xZS )Ú
Phi3Configa   
    This is the configuration class to store the configuration of a [`Phi3Model`]. It is used to instantiate a Phi-3
    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
    [microsoft/Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-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 32064):
            Vocabulary size of the Phi-3 model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`Phi3Model`].
        hidden_size (`int`, *optional*, defaults to 3072):
            Dimension of the hidden representations.
        intermediate_size (`int`, *optional*, defaults to 8192):
            Dimension of the 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://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
            `num_attention_heads`.
        resid_pdrop (`float`, *optional*, defaults to 0.0):
            Dropout probability for mlp outputs.
        embd_pdrop (`int`, *optional*, defaults to 0.0):
            The dropout ratio for the embeddings.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio after computing the attention scores.
        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 4096):
            The maximum sequence length that this model might ever be used with.
        original_max_position_embeddings (`int`, *optional*, defaults to 4096):
            The maximum sequence length that this model was trained with. This is used to determine the size of the
            original RoPE embeddings when using long scaling.
        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 value used for the RMSNorm.
        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`. Whether to tie weight embeddings or not.
        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*):
            The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
            contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be `longrope` and
            the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
            divided by the number of attention heads divided by 2.
        partial_rotary_factor (`float`, *optional*, defaults to 1.0):
            Percentage of the query and keys which will have rotary embedding. Must be between 0.0 and 1.0.
        bos_token_id (`int`, *optional*, defaults to 1):
            The id of the "beginning-of-sequence" token.
        eos_token_id (`int`, *optional*, defaults to 32000):
            The id of the "end-of-sequence" token.
        pad_token_id (`int`, *optional*, defaults to 32000):
            The id of the padding token.
        sliding_window (`int`, *optional*):
            Sliding window attention window size. If `None`, no sliding window is applied.

    Example:

    ```python
    >>> from transformers import Phi3Model, Phi3Config

    >>> # Initializing a Phi-3 style configuration
    >>> configuration = Phi3Config.from_pretrained("microsoft/Phi-3-mini-4k-instruct")

    >>> # Initializing a model from the configuration
    >>> model = Phi3Model(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úphi3Úpast_key_valuesÚcolwise_repÚrowwise_rep)zlayers.*.self_attn.qkv_projzlayers.*.self_attn.o_projzlayers.*.mlp.gate_up_projzlayers.*.mlp.down_projÚ	input_idsÚinputs_embedsÚhidden_statesÚattention_mask)Úembed_tokensÚlayersÚnormc                 ó€  •— || _         || _        || _        || _        || _        |€|}|| _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        | j%                  «        | j'                  «        || _        t+        ‰| �X  d||||dœ|¤Ž y )N)Úbos_token_idÚeos_token_idÚpad_token_idÚtie_word_embeddings© )Ú
vocab_sizeÚhidden_sizeÚintermediate_sizeÚnum_hidden_layersÚnum_attention_headsÚnum_key_value_headsÚresid_pdropÚ
embd_pdropÚattention_dropoutÚ
hidden_actÚmax_position_embeddingsÚ original_max_position_embeddingsÚinitializer_rangeÚrms_norm_epsÚ	use_cacheÚ
rope_thetaÚrope_scalingÚpartial_rotary_factorÚ_rope_scaling_adjustmentÚ_rope_scaling_validationÚsliding_windowÚsuperÚ__init__)Úselfr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r   r'   r(   r)   r   r   r   r,   ÚkwargsÚ	__class__s                            €úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/phi3/configuration_phi3.pyr.   zPhi3Config.__init__|   sä   ø€ ð6 %ˆŒØ&ˆÔØ!2ˆÔØ!2ˆÔØ#6ˆÔ àÐ&Ø"5Ðà#6ˆÔ Ø&ˆÔØ$ˆŒØ!2ˆÔØ$ˆŒØ'>ˆÔ$Ø0PˆÔ-Ø!2ˆÔØ(ˆÔØ"ˆŒØ$ˆŒØ(ˆÔØ%:ˆÔ"Ø×%Ñ%Ô'Ø×%Ñ%Ô'Ø,ˆÔä‰Ñð 	
Ø%Ø%Ø%Ø 3ñ		
ð
 ó	
ó    c                 ó„   — | j                   €y| j                   j                  dd«      }|�|dv rd| j                   d<   yyy)zc
        Adjust the `type` of the `rope_scaling` configuration for backward compatibility.
        NÚtype)ÚsuÚyarnÚlongrope)r(   Úget)r/   Úrope_scaling_types     r2   r*   z#Phi3Config._rope_scaling_adjustment¹   sU   € ð ×ÑÐ$Øà ×-Ñ-×1Ñ1°&¸$Ó?Ðð Ð(Ð->À.Ñ-PØ(2ˆD×Ñ˜fÒ%ð .QÐ(r3   c                 óX  — | j                   €yt        | j                   t        «      rt        | j                   «      dk7  rt	        d| j                   › �«      ‚| j                   j                  dd«      }| j                   j                  dd«      }| j                   j                  dd«      }|�|dvrt	        d|› �«      ‚t        |t        «      rt        d	„ |D «       «      st	        d
|› �«      ‚t        | j                  | j                  z  | j                  z  «      }t        |«      |dz  k(  st	        d|dz  › dt        |«      › �«      ‚t        |t        «      rt        d„ |D «       «      st	        d|› �«      ‚t        |«      |dz  k(  st	        d|dz  › dt        |«      › �«      ‚y)z<
        Validate the `rope_scaling` configuration.
        Nr   ze`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, got r5   Úshort_factorÚlong_factor)r8   z=`rope_scaling`'s type field must be one of ['longrope'], got c              3   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­w©N©Ú
isinstanceÚintÚfloat©Ú.0Úxs     r2   ú	<genexpr>z6Phi3Config._rope_scaling_validation.<locals>.<genexpr>Ù   s   è ø€ ÒS°A”J˜q¤3¬ ,×/ÑSùó   ‚ "zC`rope_scaling`'s short_factor field must be a list of numbers, got é   z5`rope_scaling`'s short_factor field must have length z, got c              3   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­wr?   r@   rD   s     r2   rG   z6Phi3Config._rope_scaling_validation.<locals>.<genexpr>å   s   è ø€ ÒR°A”J˜q¤3¬ ,×/ÑRùrH   zB`rope_scaling`'s long_factor field must be a list of numbers, got z4`rope_scaling`'s long_factor field must have length )r(   rA   ÚdictÚlenÚ
ValueErrorr9   ÚlistÚallrB   r   r   r)   )r/   r:   Úrope_scaling_short_factorÚrope_scaling_long_factorÚrotary_ndimss        r2   r+   z#Phi3Config._rope_scaling_validationÆ   sè  € ð ×ÑÐ$Øä˜$×+Ñ+¬TÔ2´c¸$×:KÑ:KÓ6LÐPQÒ6QÜðØ×(Ñ(Ð)ð+óð ð !×-Ñ-×1Ñ1°&¸$Ó?ÐØ$(×$5Ñ$5×$9Ñ$9¸.È$Ó$OÐ!Ø#'×#4Ñ#4×#8Ñ#8¸ÈÓ#MÐ ØÐ$Ð(9ÀÑ(MÜÐ\Ð]nÐ\oÐpÓqÐqäÐ0´$Ô7ÜÑSÐ9RÔSÔSäØUÐVoÐUpÐqóð ô ˜4×+Ñ+¨t×/GÑ/GÑGÈ$×JdÑJdÑdÓeˆÜÐ,Ó-°ÀÑ1BÒBÜØGÈÐXYÑHYÐGZÐZ`ÔadÐe~Óað  aAð  Bóð ô Ð/´Ô6ÜÑRÐ9QÔRÔRäØTÐUmÐTnÐoóð ô Ð+Ó,°ÀÑ0AÒAÜØFÀ|ÐWXÑGXÐFYÐY_Ô`cÐd|Ó`}Ð_~Ðóð ð Br3   )i@}  i   i    é    rS   Nç        rT   rT   Úsilué   rV   g{®Gáz”?gñhãˆµøä>TFg     ˆÃ@Ng      ð?é   é }  rX   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeÚkeys_to_ignore_at_inferenceÚbase_model_tp_planÚbase_model_pp_planr.   r*   r+   Ú__classcell__)r1   s   @r2   r   r      s»   ø„ ñRðh €JØ#4Ð"5Ðà'4Ø%2Ø%2Ø"/ñ	Ðð &˜¨Ð(9Ð:Ø#Ð%5Ð6¸Ð8IÐJØ!Ð" _Ð$5Ð6ñÐð ØØØØØ ØØØØØ $Ø)-ØØØØ!ØØØ!ØØØØõ1;
òz3ö'r3   r   N)
r\   Úconfiguration_utilsr   Úutilsr   Ú
get_loggerrY   Úloggerr   Ú__all__r   r3   r2   ú<module>rg      s=   ðñ   å 3Ý ð 
ˆ×	Ñ	˜HÓ	%€ôTÐ!ô Tðn ˆ.�r3   