
    i)                     v    d Z ddlmZ ddlmZ ddlmZ ddlmZ  ed      e G d	 d
e                    Z	d
gZ
y)zPhi-3 model configuration    )strict   )PreTrainedConfig)RopeParameters)auto_docstringz microsoft/Phi-3-mini-4k-instruct)
checkpointc                       e Zd ZU 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Ze	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	dz  e
d<   dZee	z  e
d<   dZee	z  e
d<   dZee	z  e
d<   dZee
d<   dZe	e
d<   dZe	e
d<   d Zee
d!<   d"Zee
d#<   d$Zee
d%<   d&Zee
d'<   dZeez  dz  e
d(<   d)Z e	dz  e
d*<   d+Z!e	e"e	   z  dz  e
d,<   d+Z#e	dz  e
d-<   dZ$e	dz  e
d.<    fd/Z%	 d4d0e	ez  d1e&dz  fd2Z' fd3Z( xZ)S )5
Phi3Configa  
    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.

    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_gather_outputrowwise_split_input)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normi@}  
vocab_sizei   hidden_sizei    intermediate_size    num_hidden_layersnum_attention_headsNnum_key_value_headsg        resid_pdrop
embd_pdropattention_dropoutsilu
hidden_acti   max_position_embeddings original_max_position_embeddingsg{Gz?initializer_rangegh㈵>rms_norm_epsT	use_cacheFtie_word_embeddingsrope_parameters   bos_token_idi }  eos_token_idpad_token_idsliding_windowc                 ^    | j                   | j                  | _         t        |   di | y )N )r   r   super__post_init__)selfkwargs	__class__s     |/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/transformers/models/phi3/configuration_phi3.pyr1   zPhi3Config.__post_init__S   s-    ##+'+'?'?D$''    default_thetaignore_keysc                    |j                  dd       }|xs | j                  | _        | j                  | j                  ni | _        | j                  j                  d|j                  d|             | j                  j                  d|j                  dd             | j	                          | j                  j                  dd       }||dv rd| j                  d<   |S )Nrope_scaling
rope_thetapartial_rotary_factorg      ?	rope_type)suyarnlongrope)popr(   
setdefaultgetstandardize_rope_params)r2   r7   r8   r3   r:   rope_parameters_types         r5   convert_rope_params_to_dictz&Phi3Config.convert_rope_params_to_dictY   s     zz.$7+Ct/C/C7;7K7K7Wt33]_ 	''fjj}6]^''(?LcehAij$$&  $3377TJ+0D0V0:D  -r6   c                 8   t         |           t        | j                  t              st        d| j                         | j                  j                  dd      }| j                  j                  dd      }| j                  j                  dd      }t        | j                  | j                  z  | j                  d   z        }|dvrt        d|       |^t        |t              rt        d	 |D              st        d
|       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y)z?
        Validate the `rope_parameters` configuration.
        z/`rope_parameters` must be a dictionary but got r=   Nshort_factorlong_factorr<   )defaultr@   z@`rope_parameters`'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     r5   	<genexpr>z+Phi3Config.validate_rope.<locals>.<genexpr>   s     Z
1sEl3Z    "zF`rope_parameters`'s short_factor field must be a list of numbers, got    z8`rope_parameters`'s short_factor field must have length z, got c              3   H   K   | ]  }t        |t        t        f        y wrL   rM   rQ   s     r5   rT   z+Phi3Config.validate_rope.<locals>.<genexpr>   s     Y
1sEl3YrU   zE`rope_parameters`'s long_factor field must be a list of numbers, got z7`rope_parameters`'s long_factor field must have length )r0   validate_roperN   r(   dict
ValueErrorrC   rO   r   r   listalllen)r2   rE   rope_parameters_short_factorrope_parameters_long_factorrotary_ndimsr4   s        r5   rX   zPhi3Config.validate_ropek   s    	 $..5NtOcOcNdeff#3377TJ'+';';'?'?PT'U$&*&:&:&>&>}d&S# 8 884;O;OPg;hh
  '>>_`t_uvww'37>Z=YZZ \]y\z{  348II N|_`O`Naaghk  mI  iJ  hK  L  '26=Y=XYY [\w[xy  23|q7HH Ml^_N_M``fgj  lG  hH  gI  J  I 3r6   )g     @N)*__name__
__module____qualname____doc__
model_typekeys_to_ignore_at_inferencebase_model_tp_planbase_model_pp_planr   rO   __annotations__r   r   r   r   r   r   rP   r   r   r!   strr"   r#   r$   r%   r&   boolr'   r(   r   rY   r*   r+   r[   r,   r-   r1   setrF   rX   __classcell__)r4   s   @r5   r
   r
      s   ( J#4"5'>%:%<"7	 &(9:#%568IJ!"_$56 JK!s!s!!&*t*"K"!J!%(us{(J#'S',0$c0#u#L%It %%48O^d*T18 L#* +0L#S	/D(0$L#*$!%NC$J%( PT 5[BE*$* *r6   r
   N)rd   huggingface_hub.dataclassesr   configuration_utilsr   modeling_rope_utilsr   utilsr   r
   __all__r/   r6   r5   <module>rs      sM      . 3 1 # =>{! {  ?{| .r6   