ó
    pyüi®â  ã                   óì  • % S SK r S SKrS SKJr  S SKJr  S SKJrJrJ	r	  SSK
JrJr  \R                  " \5      r\" 5       (       a  S SKr\(       a  SSKJr  S r    S!S	\S
   S\S   S\S-  S\S-  S\S\4   4
S jjr     S"S	\S
   S\S   S\S-  S\S-  S\S\S\4   4S jjr    S!S	\S
   S\S   S\S-  S\S-  S\S\4   4
S jjr   S#S	S
S\S   S\S-  S\S-  S\S\4   4
S jjr   S#S	S
S\S   S\S-  S\S-  S\S\4   4
S jjr   S#S	S
S\S   S\S-  S\S-  S\S\4   4
S jjr\\\\\\S.r\\\S\S\4   4   4   \ S'    " S S\	5      r! " S S5      r"S$S	\"S\#S-  4S  jjr$g)%é    N)ÚCallable©Úwraps)ÚTYPE_CHECKINGÚOptionalÚ	TypedDicté   )Úis_torch_availableÚlogging)ÚPreTrainedConfigc                 óP   ^ ^^• SS jmSS jm[        T 5      SUUU 4S jj5       nU$ )aD  
Decorator function to update the RoPE parameters in the forward pass, if the model is using a dynamic RoPE
(i.e. a RoPE implementation that may recompute its frequencies in the forward pass).

Args:
    rope_forward (Callable):
        The forward pass of the RoPE implementation.

Returns:
    The decorated forward pass.
c                 óB  • [         R                  " U5      S-   nUc4  U R                  nU R                  nSnU R                  R
                  S   nO>U R                  U   n[        X S35      nU S3nU R                  R
                  U   S   nXH:”  aX  [        X S35      (       d!  [        U   n	U	" U R                  UUS-   US9u  p«U R                  U S	3W
S
S9  [        X S3U
5        gUR                  U5      nU R                  U S	3US
S9  [        X S3U5        g)zbLongrope uses long factor if sequence is larger than original pretraining length, short otherwise.r	   NÚ Ú original_max_position_embeddingsÚ_original_inv_freqÚ_Ú_long_inv_freq©Úseq_lenÚ
layer_typeÚinv_freqF©Ú
persistentÚlong_inv_freqÚoriginal_inv_freq)ÚtorchÚmaxÚ	rope_typer   ÚconfigÚrope_parametersÚgetattrÚhasattrÚROPE_INIT_FUNCTIONSÚregister_bufferÚsetattrÚto)ÚselfÚposition_idsÚdevicer   r   r   r   Úprefixr   Úrope_init_fnr   r   s               Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/modeling_rope_utils.pyÚlongrope_frequency_updateÚ6dynamic_rope_update.<locals>.longrope_frequency_update/   sO  € ä—)’)˜LÓ)¨AÑ-ˆàÑØŸ™ˆIØ $× 6Ñ 6ÐØˆFØ/3¯{©{×/JÑ/JÐKmÑ/nÑ,àŸ™ zÑ2ˆIÜ '¨°Ð<NÐ.OÓ PÐØ"�| 1Ð%ˆFØ/3¯{©{×/JÑ/JÈ:Ñ/VØ2ñ0Ð,ð Ó5Ü˜4 <¨~Ð!>×?Ñ?Ü2°9Ñ=�Ù#/Ø—K‘KØØ<¸qÑ@Ø)ñ	$Ñ �ð × Ñ  F 8¨8Ð!4°mÐPUÐ ÑVÜ�D˜H MÐ2°MÕBð !2× 4Ñ 4°VÓ <ÐØ× Ñ  F 8¨8Ð!4Ð6GÐTYÐ ÑZÜ�D˜HÐ$5Ð6Ð8IÕJó    c                 óp  • [         R                  " U5      S-   nUc'  U R                  nU R                  nU R                  nSnO;U R                  U   n[        X S3U R                  5      n[        X S35      nU S3nXF:”  aF  [        U   n	U	" U R                  UUUS9u  o l        U R                  U S3U
S	S
9  [        X S3U5        X@R                  :  a^  X`R                  :”  aN  UR                  U5      nU R                  U S3US	S
9  [        X S3U5        [        X S3U R                  5        ggg)zó
dynamic RoPE layers should recompute `inv_freq` in the following situations:
1 - growing beyond the cached sequence length (allow scaling)
2 - the current sequence length is in the original scale (avoid losing precision with small sequences)
r	   Nr   Ú_max_seq_len_cachedr   r   r   r   Fr   r   )r   r   r   Úmax_seq_len_cachedr   r!   r#   r   Úattention_scalingr$   r%   Úoriginal_max_seq_lenr&   )r'   r(   r)   r   r   r   r2   r   r*   r+   r   s              r,   Údynamic_frequency_updateÚ5dynamic_rope_update.<locals>.dynamic_frequency_updateR   si  € ô —)’)˜LÓ)¨AÑ-ˆØÑØŸ™ˆIØ!%×!8Ñ!8ÐØ $× 6Ñ 6ÐØ‰FàŸ™ zÑ2ˆIÜ!(¨°Ð=PÐ/QÐSW×SjÑSjÓ!kÐÜ '¨°Ð<NÐ.OÓ PÐØ"�| 1Ð%ˆFàÓ'Ü.¨yÑ9ˆLÙ/;Ø—‘ØØØ%ñ	0Ñ,ˆHÔ,ð × Ñ  F 8¨8Ð!4°hÈ5Ð ÑQÜ�D˜LÐ(;Ð<¸gÔFà×.Ñ.Ó.Ð3E×HaÑHaÓ3að !2× 4Ñ 4°VÓ <ÐØ× Ñ  F 8¨8Ð!4Ð6GÐTYÐ ÑZÜ�D˜HÐ$5Ð6Ð8IÔJÜ�D˜LÐ(;Ð<¸d×>WÑ>WÕXð 4bÐ.r/   c                 óÔ   >• Uc  U R                   OU R                   U   nUb  SU0O0 nSU;   a  T" X4SUR                  0UD6  OUS:X  a  T" X4SUR                  0UD6  T" XU40 UD6$ )Nr   Údynamicr)   Úlongrope)r   r)   )	r'   Úxr(   r   r   Úkwargsr5   r-   Úrope_forwards	         €€€r,   ÚwrapperÚ$dynamic_rope_update.<locals>.wrapperx   s{   ø€ à&0Ñ&8�D—N’N¸d¿n¹nÈZÑ>Xˆ	Ø/9Ñ/E�, 
Ñ+È2ˆØ˜	Ó!Ù$ TÑSÀÇÁÐSÈFÓSØ˜*Ó$Ù% dÑTÀÇÁÐTÈVÒTÙ˜D \Ñ<°VÑ<Ð<r/   ©Nr   )r<   r=   r5   r-   s   ` @@r,   Údynamic_rope_updater@   "   s6   ú€ ô!KôF$YôL ˆ<Ó÷=ð =ó ð=ð €Nr/   r   r   r)   ztorch.devicer   r   Úreturnztorch.Tensorc           	      ó°  • U R                  5         Ub  U R                  U   OU R                  nUS   nUS   nUR                  SS5      n[        U SS5      =(       d    U R                  U R
                  -  n[        X‡-  5      n	Sn
SU[        R                  " SU	S[        R                  S	9R                  U[        R                  S
9U	-  -  -  nXµ-  nXº4$ )a  
Computes the inverse frequencies with linear scaling. Credits to the Reddit user /u/kaiokendev
Args:
    config ([`~transformers."PreTrainedConfig"`]):
        The model configuration. This function assumes that the config will provide at least the following
        properties:

        *   rope_theta (`float`, *optional*): The base wavelength from which the inverse frequencies will be derived. Defaults to `config.default_theta` if omitted.
        *   hidden_size (`int`): The numerator when deriving a head_dim, if not provided directly.
        *   num_attention_heads (`int`): The denominator when deriving a head_dim, if not provided directly.

        Additionally, this function will make use of the following properties if they are found in the config:

        *   head_dim (`int`, *optional*): The size of the key-value heads in the model. If None, this value will be
            derived as hidden_size // num_attention_heads.
        *   partial_rotary_factor (`float`, *optional*): If less than 1.0, inverse frequencies will be returned for
            the first fraction of the head_dim. Defaults to 1.0.
    device (`torch.device`):
        The device to use for initialization of the inverse frequencies.
    seq_len (`int`, *optional*):
        The current sequence length. Unused for this type of RoPE.

Returns:
    Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
    post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
NÚfactorÚ
rope_thetaÚpartial_rotary_factorç      ð?Úhead_dimr   é   ©Údtype©r)   rJ   )Ústandardize_rope_paramsr    Úgetr!   Úhidden_sizeÚnum_attention_headsÚintr   ÚarangeÚint64r&   Úfloat)r   r)   r   r   Úrope_parameters_dictrC   ÚbaserE   rG   ÚdimÚattention_factorr   s               r,   Ú'_compute_linear_scaling_rope_parametersrX   …   sæ   € ðB ×"Ñ"Ô$ØAKÑAW˜6×1Ñ1°*Ò=Ð]c×]sÑ]sÐØ! (Ñ+€Fð   Ñ-€DØ0×4Ñ4Ð5LÈcÓRÐÜ�v˜z¨4Ó0×d°F×4FÑ4FÈ&×JdÑJdÑ4d€HÜ
ˆhÑ.Ó
/€CØÐð �dœuŸ|š|¨A¨s°A¼U¿[¹[ÑI×LÑLÐTZÔbg×bmÑbmÐLÐnÐqtÑtÑuÑv€Hð
 Ñ€HØÐ%Ð%r/   Úhead_dim_keyc           	      óh  • U R                  5         Ub  U R                  U   OU R                  n[        XS5      =(       d    U R                  U R                  -  nUS   nUR                  SS5      nUR                  SS5      n	Sn
[        X–-  S-  5      nSU[        R                  " SSU-  S[        R                  S9R                  U[        R                  S	9U-  -  -  nUS-  U-
  nUS:”  a:  [        R                  " U[        R                  " U[        R                  US
94SS9nOUnXè-  nXê4$ )aŽ  
Computes the inverse frequencies with proportional RoPE.

Args:
    config ([`~transformers.PretrainedConfig`]):
        The model configuration. This function assumes that the config will provide at least the following
        properties:

        *   rope_theta (`float`, *optional*): The base wavelength from which the inverse frequencies will be derived. Defaults to `config.default_theta` if omitted.
        *   hidden_size (`int`): The numerator when deriving a head_dim, if not provided directly.
        *   num_attention_heads (`int`): The denominator when deriving a head_dim, if not provided directly.

        Additionally, this function will make use of the following properties if they are found in the config:

        *   head_dim (`int`, *optional*): The size of the key-value heads in the model. If None, this value will be
            derived as hidden_size // num_attention_heads.
        *   partial_rotary_factor (`float`, *optional*, defaults to 1.0): The proportion of the embedding dimension
            to apply rotary positional encoding, e.g., [0.0, 0.25, 0.5, 0.75, 1.0]. Unlike other RoPE functions
            that use this parameter, proportional RoPE will always return an encoding that is the size of
            `head_dim`.
    device (`torch.device`):
        The device to use for initialization of the inverse frequencies.
    seq_len (`int`, *optional*):
        The current sequence length. Unused for this type of RoPE.

Returns:
    Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
    post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
NrD   rC   rF   rE   rH   r   rI   rK   ©rJ   r)   )rV   )rL   r    r!   rN   rO   rM   rP   r   rQ   rR   r&   rS   ÚcatÚzerosÚfloat32)r   r)   r   r   rY   rT   rG   rU   rC   Úrope_proportionrW   Úrope_anglesÚinv_freq_rotatedÚnope_anglesr   s                  r,   Ú%_compute_proportional_rope_parametersrc   »   sB  € ðJ ×"Ñ"Ô$ØAKÑAW˜6×1Ñ1°*Ò=Ð]c×]sÑ]sÐä�v¨TÓ2×f°f×6HÑ6HÈF×LfÑLfÑ6f€HØ Ñ-€DØ!×%Ñ% h°Ó4€FØ*×.Ñ.Ð/FÈÓL€OàÐä�oÑ0°AÑ5Ó6€KàØÜ�LŠL˜˜A ™O¨Q´e·k±kÑB×EÑEÈVÔ[`×[fÑ[fÐEÐgÐjrÑrñ	tñÐð
 ˜a‘- +Ñ-€KØ�QƒÜ—9’9à Ü—’˜K¬u¯}©}ÀVÑLðð ñ
‰ð $ˆàÑ€HØÐ%Ð%r/   c           	      óö  • U R                  5         Ub  U R                  U   OU R                  nUS   nUR                  SS5      n[        U SU R                  U R
                  -  5      n[        Xv-  5      nUS   n	Sn
Uc  U R                  nO~[        U[        R                  5      (       aJ  [        R                  " U[        R                  " U R                  UR                  UR                  S95      nO[        X R                  5      nXYU-  U R                  -  U	S-
  -
  XˆS-
  -  -  -  nSU[        R                   " S	US[        R"                  S
9R%                  U[        R&                  S9U-  -  -  nXº4$ )a�	  
Computes the inverse frequencies with NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla

Args:
    config ([`~transformers."PreTrainedConfig"`]):
        The model configuration. This function assumes that the config will provide at least the following
        properties:

        *   rope_theta (`float`, *optional*): The base wavelength from which the inverse frequencies will be derived. Defaults to `config.default_theta` if omitted.
        *   hidden_size (`int`): The numerator when deriving a head_dim, if not provided directly.
        *   num_attention_heads (`int`): The denominator when deriving a head_dim, if not provided directly.
        *   max_position_embeddings (`int`): The default sequence length used to update the dynamic RoPE at
            inference time
        *   rope_parameters (`dict[str, float]`): The standard RoPE scaling parameters, from which `factor`
            will be accessed. The value of `factor` is used to determine the new base frequency, along with the
            current sequence length (seq_len), the maximum positional embeddings (max_position_embeddings), and the
            computed dimensionality (dim) of the rotary embeddings. If seq_len <= max_position_embeddings, this
            factor has no effect. If seq_len <= max_position_embeddings, this factor effectively stretches the
            context window using an exponent derived from `dim`.

        Additionally, this function will make use of the following properties if they are found in the config:

        *   head_dim (`int`, *optional*): The size of the key-value heads in the model. If None, this value will be
            derived as hidden_size // num_attention_heads.
        *   partial_rotary_factor (`float`, *optional*): If less than 1.0, inverse frequencies will be returned for
            the first fraction of the head_dim. Defaults to 1.0.
    device (`torch.device`):
        The device to use for initialization of the inverse frequencies.
    seq_len (`int`, *optional*):
        The current sequence length, used to update the dynamic RoPE at inference time. If `None` or shorter than
        max_position_embeddings, this value will be overridden by max_position_embeddings.

Returns:
    Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
    post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
rD   rE   rF   rG   rC   r[   r	   rH   r   rI   rK   )rL   r    rM   r!   rN   rO   rP   Úmax_position_embeddingsÚ
isinstancer   ÚTensorÚmaximumÚtensorrJ   r)   r   rQ   rR   r&   rS   )r   r)   r   r   rT   rU   rE   rG   rV   rC   rW   r   s               r,   Ú_compute_dynamic_ntk_parametersrj     sm  € ðV ×"Ñ"Ô$ØAKÑAW˜6×1Ñ1°*Ò=Ð]c×]sÑ]sÐà Ñ-€DØ0×4Ñ4Ð5LÈcÓRÐÜ�v˜z¨6×+=Ñ+=À×A[ÑA[Ñ+[Ó\€HÜ
ˆhÑ.Ó
/€CØ! (Ñ+€FØÐð �Ø×0Ñ0‰Ü	�GœUŸ\™\×	*Ñ	*Ü—-’-ØÜ�LŠL˜×7Ñ7¸w¿}¹}ÐU\×UcÑUcÑdó
‰ô
 �g×=Ñ=Ó>ˆð ˜WÑ$ v×'EÑ'EÑEÈ&ÐSTÉ*ÑUÐ[^ÐhiÑbiÑ[jÑkÑk€DØ�dœuŸ|š|¨A¨s°A¼U¿[¹[ÑI×LÑLÐTZÔbg×bmÑbmÐLÐnÐqtÑtÑuÑv€HØÐ%Ð%r/   c                 óà  ^• U R                  5         Ub  U R                  U   OU R                  nUS   nUR                  SS5      n[        U SU R                  U R
                  -  5      n[        Xv-  5      nUS   n	UR                  S5      n
UR                  S5      nUR                  S5      nUS	   nU	c  U R                  U-  n	SS jnU
c1  U(       a"  U(       a  [        U" X›5      U" Xœ5      -  5      n
OU" U	5      n
UR                  S5      =(       d    SnUR                  S5      =(       d    S
nS mU4S jnS nU[        R                  " SUS5      R                  U[        R                  S9U-  -  nSU-  nSU	U-  -  nU R                  R                  SS5      nU" UUX…UU5      u  nnS
U" UUUS-  5      R                  U[        R                  S9-
  nUS
U-
  -  UU-  -   nUU
4$ )a�  
Computes the inverse frequencies with NTK scaling. Please refer to the
[original paper](https://huggingface.co/papers/2309.00071)

Args:
    config ([`~transformers."PreTrainedConfig"`]):
        The model configuration. This function assumes that the config will provide at least the following
        properties:

        *   rope_theta (`float`, *optional*): The base wavelength from which the inverse frequencies will be derived. Defaults to `config.default_theta` if omitted.
        *   hidden_size (`int`): The numerator when deriving a head_dim, if not provided directly.
        *   num_attention_heads (`int`): The denominator when deriving a head_dim, if not provided directly.
        *   max_position_embeddings (`int`): The maximum length of the positional embeddings.
        *   rope_parameters (`dict[str, float | int]`): The standard RoPE scaling parameters, from which the following
            keys will be accessed:
            *   `attention_factor` (`float`, *optional*): The scaling factor to be applied to the computed cos/sin.
                If None, the value is inferred from `factor`, `mscale`, and `mscale_all_dim` as available.
            *   `beta_fast` (`float`, *optional*, defaults to 32): Parameter to set the boundary for extrapolation
                (only) in the linear ramp function.
            *   `beta_slow` (`float`, *optional*, defaults to 1): Parameter to set the boundary for interpolation
                (only) in the linear ramp function.
            *   `factor` (`float`, *optional*): The scaling factor applied when interpolating the position IDs to
                extend the possible context length. Additionally, if `attention_factor` is None, the log of this
                value is used to compute a value for `attention_factor`, possibly in conjunciton with `mscale` and
                `mscale_all_dim`, if provided.
            *   `mscale` (`float`, *optional*): If `attention_factor` is None and both `mscale` and
                `mscale_all_dim` are provided, `mscale` acts scalar augmenting `log(factor)` when computing the
                numerator for the inferred value of `attention_factor`. If not provided, `attention_factor` will be
                calculated based on `factor` only.
            *   `mscale_all_dim` (`float`, *optional*): If `attention_factor` is None and both `mscale` and
                `mscale_all_dim` are provided, `mscale_all_dim` acts scalar augmenting `log(factor)` when computing
                the denominator for the inferred value of `attention_factor`. If not provided, `attention_factor`
                will be calculated based on `factor` only.
            *   `original_max_position_embeddings` (`int`): The original max position embeddings used during pretraining.
            *   `truncate` (`bool`, *optional*): Whether to truncate the correction range.

        Additionally, this function will make use of the following properties if they are found in the config:

        *   head_dim (`int`, *optional*): The size of the key-value heads in the model. If None, this value will be
            derived as hidden_size // num_attention_heads.
        *   partial_rotary_factor (`float`, *optional*, defaults to 1.0): If less than 1.0, inverse frequencies
            will be returned for the first fraction of the head_dim.
    device (`torch.device`):
        The device to use for initialization of the inverse frequencies.
    seq_len (`int`, *optional*):
        The current sequence length. Unused for this type of RoPE.

Returns:
    Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
    post-processing scaling factor applied to the computed cos/sin.
rD   rE   rF   rG   rC   rW   ÚmscaleÚmscale_all_dimr   r	   c                 óN   • U S::  a  gSU-  [         R                  " U 5      -  S-   $ )Nr	   rF   gš™™™™™¹?)ÚmathÚlog)Úscalerl   s     r,   Ú
get_mscaleÚ,_compute_yarn_parameters.<locals>.get_mscale•  s(   € Ø�A‹:ØØ�V‰|œdŸhšh u›oÑ-°Ñ3Ð3r/   Ú	beta_fasté    Ú	beta_slowc                 ó”   • U[         R                  " X0S-  [         R                  -  -  5      -  S[         R                  " U5      -  -  $ )zPInverse dimension formula to find the dimension based on the number of rotationsrH   )ro   rp   Úpi)Únum_rotationsrV   rU   re   s       r,   Úfind_correction_dimÚ5_compute_yarn_parameters.<locals>.find_correction_dim§  s@   € à”d—h’hÐ6È!Ñ:KÌdÏgÉgÑ:UÑVÓWÑWÐ\]Ô`d×`hÒ`hÐimÓ`nÑ\nÑoÐor/   c                 óÂ   >• T" XX45      nT" XX45      nU(       a,  [         R                  " U5      n[         R                  " U5      n[        US5      [	        XrS-
  5      4$ )z.Find dimension range bounds based on rotationsr   r	   )ro   ÚfloorÚceilr   Úmin)	Úlow_rotÚhigh_rotrV   rU   re   ÚtruncateÚlowÚhighrz   s	           €r,   Úfind_correction_rangeÚ7_compute_yarn_parameters.<locals>.find_correction_range«  sR   ø€ á! '°ÓNˆÙ" 8°$ÓPˆÞÜ—*’*˜S“/ˆCÜ—9’9˜T“?ˆDÜ�3˜‹{œC ¨A¡gÓ.Ð.Ð.r/   c                 ó    • X:X  a  US-  n[         R                  " U[         R                  S9U -
  X-
  -  n[         R                  " USS5      nU$ )Ngü©ñÒMbP?rI   r   r	   )r   rQ   r^   Úclamp)r   r   rV   Úlinear_funcÚ	ramp_funcs        r,   Úlinear_ramp_factorÚ4_compute_yarn_parameters.<locals>.linear_ramp_factor´  sH   € Ø‹:Ø�5‰LˆCä—|’| C¬u¯}©}Ñ=ÀÑCÈÉ	ÑRˆÜ—K’K ¨Q°Ó2ˆ	ØÐr/   r   rH   rK   r‚   T)r	   )rL   r    rM   r!   rN   rO   rP   re   rS   r   rQ   r&   )r   r)   r   r   rT   rU   rE   rG   rV   rC   rW   rl   rm   r   rr   rt   rv   r…   r‹   Ú	pos_freqsÚinv_freq_extrapolationÚinv_freq_interpolationr‚   rƒ   r„   Úinv_freq_extrapolation_factorr   rz   s                              @r,   Ú_compute_yarn_parametersr‘   G  s/  ø€ ðt ×"Ñ"Ô$ØAKÑAW˜6×1Ñ1°*Ò=Ð]c×]sÑ]sÐà Ñ-€DØ0×4Ñ4Ð5LÈcÓRÐÜ�v˜z¨6×+=Ñ+=À×A[ÑA[Ñ+[Ó\€HÜ
ˆhÑ.Ó
/€Cà! (Ñ+€FØ+×/Ñ/Ð0BÓCÐØ!×%Ñ% hÓ/€FØ)×-Ñ-Ð.>Ó?€NØ';Ð<^Ñ'_Ð$ð
 �~Ø×/Ñ/Ð2RÑRˆô4ð ÑÞ–nÜ$¡Z°Ó%?Á*ÈVÓBdÑ%dÓeÑá)¨&Ó1Ðð %×(Ñ(¨Ó5×;¸€IØ$×(Ñ(¨Ó5×:¸€Iòpõ/òð œŸš a¨¨aÓ0×3Ñ3¸6ÌÏÉÐ3ÐUÐX[Ñ[Ñ\€IØ  9™_ÐØ  F¨YÑ$6Ñ7Ðà×%Ñ%×)Ñ)¨*°dÓ;€HÙ% i°¸CÐGgÐiqÓr�I€Cˆð %&Ñ(:¸3ÀÀcÈQÁhÓ(O×(RÑ(RÐZ`Ôhm×hsÑhsÐ(RÐ(tÑ$tÐ!à !Ð&CÑ"CÑDØ
 Ð#@Ñ
@ñ	Að ð Ð%Ð%Ð%r/   c                 óH  • U R                  5         Ub  U R                  U   OU R                  nUS   nUR                  SS5      n[        U SU R                  U R
                  -  5      n[        Xv-  5      nUS   n	US   n
UR                  S5      nUR                  S5      nUS	   nUc  U R                  U-  nUcM  US::  a  SnOD[        R                  " S
[        R                  " U5      [        R                  " U5      -  -   5      nU(       a*  X-:”  a%  [        R                  " U	[        R                  US9nO$[        R                  " U
[        R                  US9n[        R                  " SUS[        R                  US9R!                  5       U-  nSXåU-  -  -  nUU4$ )ay  
Computes the inverse frequencies with LongRoPE scaling. Please refer to the
[original implementation](https://github.com/microsoft/LongRoPE)

Args:
    config ([`~transformers."PreTrainedConfig"`]):
        The model configuration. This function assumes that the config will provide at least the following
        properties:

        *   rope_theta (`float`, *optional*): The base wavelength from which the inverse frequencies will be derived. Defaults to `config.default_theta` if omitted.
        *   hidden_size (`int`): The numerator when deriving a head_dim, if not provided directly.
        *   num_attention_heads (`int`): The denominator when deriving a head_dim, if not provided directly.
        *   max_position_embeddings (`int`): The maximum length of the positional embeddings.
        *   original_max_position_embeddings (`int`, *optional*): The original max position embeddings used during
            pretraining. If not provided, defaults to `max_position_embeddings`.
        *   rope_parameters (`dict[str, float]`): The standard RoPE scaling parameters, from which the following keys
            will be accessed:
            *   `attention_factor` (`float`, *optional*): The scaling factor to be applied on the attention
                computation. If unspecified, it defaults to value recommended by the implementation, inferred from
                the value of `factor`.
            *   `factor` (`float`, *optional*): The scaling factor to apply to the RoPE embeddings. If both
                `max_position_embeddings` and `original_max_position_embeddings` are provided, this value will be
                overridden s the ratio between those values.
            *   `long_factor` (`float`, *optional*): The scale factor applied when computing the inverse
                frequencies if `seq_len` is provided and greater than `original_max_position_embeddings`.
            *   `short_factor` (`float`, *optional*): The scale factor applied when computing the inverse
                frequencies if `seq_len` is None or less-than-or-equal-to `original_max_position_embeddings`.

        Additionally, this function will make use of the following properties if they are found in the config:

        *   head_dim (`int`, *optional*): The size of the key-value heads in the model. If None, this value will be
            derived as hidden_size // num_attention_heads.
        *   partial_rotary_factor (`float`, *optional*, defaults to 1.0): If less than 1.0, inverse frequencies
            will be returned for the first fraction of the head_dim.
    device (`torch.device`):
        The device to use for initialization of the inverse frequencies.
    seq_len (`int`, *optional*):
        The current sequence length.

Returns:
    Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
    post-processing scaling factor applied to the computed cos/sin.
rD   rE   rF   rG   Úlong_factorÚshort_factorrC   rW   r   r	   r[   r   rH   )rL   r    rM   r!   rN   rO   rP   re   ro   Úsqrtrp   r   ri   r^   rQ   rR   rS   )r   r)   r   r   rT   rU   rE   rG   rV   r“   r”   rC   rW   r   Úext_factorsÚinv_freq_shaper   s                    r,   Ú_compute_longrope_parametersr˜   Î  s’  € ðd ×"Ñ"Ô$ØAKÑAW˜6×1Ñ1°*Ò=Ð]c×]sÑ]sÐà Ñ-€DØ0×4Ñ4Ð5LÈcÓRÐÜ�v˜z¨6×+=Ñ+=À×A[ÑA[Ñ+[Ó\€HÜ
ˆhÑ.Ó
/€Cà& }Ñ5€KØ'¨Ñ7€LØ!×%Ñ% hÓ/€FØ+×/Ñ/Ð0BÓCÐØ';Ð<^Ñ'_Ð$ð
 �~Ø×/Ñ/Ð2RÑRˆð ÑØ�S‹=Ø"Ñä#Ÿyšy¨¬T¯XªX°fÓ-=ÄÇÂÐIiÓ@jÑ-jÑ)jÓkÐö �7Ó=Ü—l’l ;´e·m±mÈFÑS‰ä—l’l <´u·}±}ÈVÑTˆÜ—\’\ ! S¨!´5·;±;ÀvÑN×TÑTÓVÐY\Ñ\€NØ�k¨.Ñ$8Ñ8Ñ9€HàÐ%Ð%Ð%r/   c           	      óÄ  • U R                  5         Ub  U R                  U   OU R                  nUS   nUR                  SS5      n[        U SS5      =(       d    U R                  U R
                  -  n[        Xv-  5      nSn	SU[        R                  " SUS[        R                  S9R                  U[        R                  S	9U-  -  -  n
US
   nUS   nUS   nUS   nXì-  nXí-  nS[        R                  -  U
-  n[        R                  " UU:„  X«-  U
5      nUU-  U-
  XÜ-
  -  nSU-
  U-  U-  UU-  -   nUU:  ) UU:„  ) -  n[        R                  " UUU5      nUU	4$ )a,
  
Computes the inverse frequencies for llama 3.1.

Args:
    config ([`~transformers."PreTrainedConfig"`]):
        The model configuration. This function assumes that the config will provide at least the following
        properties:

        *   rope_theta (`float`, *optional*): The base wavelength from which the inverse frequencies will be derived. Defaults to `config.default_theta` if omitted.
        *   hidden_size (`int`): The numerator when deriving a head_dim, if not provided directly.
        *   num_attention_heads (`int`): The denominator when deriving a head_dim, if not provided directly.
        *   rope_parameters (`dict[str, float | int]`): The standard RoPE scaling parameters, from which the following
            keys will be accessed:
            *   `factor` (`float`, *optional*): The scaling factor applied to the inverse frequencies when 1) the
                wavelength is greater than `low_freq_wavelen` prior to smoothing, and 2) to all inverse frequencies
                during smoothing.
            *   `high_freq_factor` (`float`): The scale factor used to compute `high_freq_wavelen` and
                the value for the denominator of the smoothing factor prior to the `low_freq_factor` shift.
            *   `low_freq_factor` (`float`): The scale factor used to compute `low_freq_wavelen` and
                the shift applied to the numerator and denominator of the smoothing factor.
                frequencies if `seq_len` is None or less-than-or-equal-to `original_max_position_embeddings`.
            *   `original_max_position_embeddings` (`int`): The original max position embeddings used
                during pretraining. If not provided, the function falls back to `max_position_embeddings`.

        Additionally, this function will make use of the following properties if they are found in the config:

        *   head_dim (`int`, *optional*): The size of the key-value heads in the model. If None, this value will be
            derived as hidden_size // num_attention_heads.
        *   partial_rotary_factor (`float`, *optional*): If less than 1.0, inverse frequencies will be returned for
            the first fraction of the head_dim. Defaults to 1.0.
    device (`torch.device`):
        The device to use for initialization of the inverse frequencies.
    seq_len (`int`, *optional*):
        The current sequence length. Unused for this type of RoPE.
Returns:
    Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
    post-processing scaling factor applied to the computed cos/sin.
NrD   rE   rF   rG   r   rH   rI   rK   rC   Úlow_freq_factorÚhigh_freq_factorr   r	   )rL   r    rM   r!   rN   rO   rP   r   rQ   rR   r&   rS   ro   rx   Úwhere)r   r)   r   r   rT   rU   rE   rG   rV   rW   r   rC   rš   r›   Úold_context_lenÚlow_freq_wavelenÚhigh_freq_wavelenÚwavelenÚinv_freq_llamaÚsmooth_factorÚsmoothed_inv_freqÚis_medium_freqs                         r,   Ú_compute_llama3_parametersr¥   &  sª  € ðZ ×"Ñ"Ô$ØAKÑAW˜6×1Ñ1°*Ò=Ð]c×]sÑ]sÐð   Ñ-€DØ0×4Ñ4Ð5LÈcÓRÐÜ�v˜z¨4Ó0×d°F×4FÑ4FÈ&×JdÑJdÑ4d€HÜ
ˆhÑ.Ó
/€CØÐð �dœuŸ|š|¨A¨s°A¼U¿[¹[ÑI×LÑLÐTZÔbg×bmÑbmÐLÐnÐqtÑtÑuÑv€Hà! (Ñ+€FØ*Ð+<Ñ=€OØ+Ð,>Ñ?ÐØ*Ð+MÑN€Oà&Ñ8ÐØ'Ñ:Ðà”$—'‘'‰k˜HÑ$€Gô —[’[ Ð+;Ñ!;¸XÑ=NÐPXÓY€Nà$ wÑ.°Ñ@ÐEUÑEgÑh€MØ˜]Ñ*¨nÑ<¸vÑEÈÐXfÑHfÑfÐØÐ!2Ñ2Ð3¸ÐBRÑ8RÐ6SÑS€NÜ—[’[ Ð1BÀNÓS€NàÐ+Ð+Ð+r/   )Úlinearr8   Úyarnr9   Úllama3Úproportional.r#   c                   óæ   • \ rS rSr% Sr\S-  \S'   \S-  \S'   \S-  \S'   \S-  \S'   \S-  \S'   \S-  \S	'   \S-  \S
'   \S-  \S'   \	\   S-  \S'   \	\   S-  \S'   \S-  \S'   \S-  \S'   Sr
g)ÚRopeParametersi‚  uu
  
Args:
    rope_theta (`float`, *optional*, defaults to `RotaryEmbeddingConfigMixin.default_theta`):
        The base period of the RoPE embeddings. Optional in serialized configs â€” if omitted,
        the model's `default_theta` (typically 10000.0) is used.
    rope_type (`str`, *optional*, defaults to "default"):
        The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
        'llama3'], with 'default' being the original RoPE implementation.
    partial_rotary_factor (`float`, *optional*):
        The percentage of the query and key head embedding on which RoPE will be applied.
    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 'yarn', '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
NrD   r   rE   rC   r   rW   rt   rv   r”   r“   rš   r›   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rS   Ú__annotations__ÚstrrP   ÚlistÚ__static_attributes__r¬   r/   r,   r«   r«   ‚  sŒ   ‡ ñ'ðR ˜‘ÓØ�T‰zÓØ  4™<Ó'Ø�D‰LÓØ&)¨D¡jÓ0Ø˜d‘lÓ"Ø�t‰|ÓØ�t‰|ÓØ�u‘+ Ñ$Ó$Ø�e‘˜tÑ#Ó#Ø˜T‘\Ó!Ø˜d‘lÖ"r/   r«   c                   ó@  • \ rS rSrSrSr\" 5       rS rS r	SS jr
SS\S	\S-  4S
 jjrSS\S	\S-  4S jjrSS\S	\S-  4S jjrSS\S	\S-  4S jjrSS\S	\S-  4S jjrSS\S	\S-  4S jjrSS\S	\S-  4S jjr\  SS\S\S\S\S-  S	\S-  4
S jj5       rSrg)ÚRotaryEmbeddingConfigMixiniº  zS
A Mixin containing the functionality to standardize and validate RoPE parameters.
g     ˆÃ@c                 óæ  • UR                  SS 5      nU=(       d    U R                  U l        U R                  b  U R                  O0 U l        UR                  S[        U SU R                  5      5      nU R                  R	                  SU5        UR                  S[        U SS 5      5      nUb1  U R                  R	                  SU5        U R                  S1-  U l        U R                  5         U$ )NÚrope_scalingrD   rE   )Úpopr    r!   Údefault_thetaÚ
setdefaultrM   Úignore_keys_at_rope_validationrL   )r'   r;   r¹   rD   rE   s        r,   Úconvert_rope_params_to_dictÚ6RotaryEmbeddingConfigMixin.convert_rope_params_to_dictÂ  sÛ   € Ø—z‘z .°$Ó7ˆØ+×C¨t×/CÑ/CˆÔØ7;×7KÑ7KÑ7W˜t×3Ò3Ð]_ˆÔð —Z‘Z ¬g°d¸LÈ$×J\ÑJ\Ó.]Ó^ˆ
Ø×Ñ×'Ñ'¨°jÔAà &§
¡
Ð+BÄGÈDÐRiÐkoÓDpÓ qÐØ Ñ,Ø× Ñ ×+Ñ+Ð,CÐEZÔ[Ø26×2UÑ2UÐYpÐXqÑ2qˆDÔ/à×$Ñ$Ô&Øˆr/   c                 ó‚  • [        U SS5      n[        U SS5      n[        U SS5      =(       d    0 n[        U SS5      nU(       d  U(       d  [        R                  S5        gUb3  U0 :X  d-  [        UR	                  5       5      R                  U5      (       d–  UR                  SUR                  SS	5      5        UR                  SU5        Ub  X#S'   US   S
;   aQ  [        U S5      (       a  U R                  U R                  S'   O³U R                  R                  SU R                  5        OŒ[        U5       H}  nX5   R                  SX5   R                  SS	5      5        X5   R                  SU5        Ub  X#U   S'   X5   S   S
;   d  MT  U R                  U   R                  SU R                  5        M     X0l
        g)zÒ
Helper to standardize the config's rope params field by ensuring the params are defined for each
later type. For old model the fn will duplicate a single rope param in each layer type (backward compatibility)
rD   NrE   r    Úlayer_typeszG`standardize_rope_params` was called but no RoPE parameters were found.r   ÚtypeÚdefault)r¨   r§   r9   r   )r!   ÚloggerÚwarningÚsetÚkeysÚissubsetr¼   rM   r"   r   r    re   )r'   rD   rE   r    rÁ   r   s         r,   rL   Ú2RotaryEmbeddingConfigMixin.standardize_rope_params×  s¶  € ô ˜T <°Ó6ˆ
Ü '¨Ð.EÀtÓ LÐÜ! $Ð(9¸4Ó@×FÀBˆÜ˜d M°4Ó8ˆö  ¦:ä�N‰NÐdÔeØàÑ  O°rÓ$9ÄÀ_×EYÑEYÓE[ÓA\×AeÑAeÐfq×ArÑArØ×&Ñ& {°O×4GÑ4GÈÐPYÓ4ZÔ[Ø×&Ñ& |°ZÔ@Ø$Ñ0Ø;PÐ 7Ñ8ð ˜{Ñ+Ð/MÓMÜ˜4Ð!C×DÑDð PT×OtÑOt�D×(Ñ(Ð)KÒLà×(Ñ(×3Ñ3Ð4VÐX\×XtÑXtÔuøô " +Ö.�
ØÑ+×6Ñ6°{ÀOÑD_×DcÑDcÐdjÐluÓDvÔwØÑ+×6Ñ6°|ÀZÔPØ(Ñ4ØK` JÑ/Ð0GÑHà"Ñ.¨{Ñ;Ð?]Õ]Ø×(Ñ(¨Ñ4×?Ñ?Ø:¸D×<XÑ<Xöñ /ð  /Õr/   c                 óº  • [        U SS5      nU(       d  g[        U SS5      b8  [        UR                  5       5      R                  U R                  5      (       a  OSU0nUR                  5        Hh  nUR                  SUR                  SS5      5      n[        U SU S	3S5      nX2S'   Ub  U" X R                  S
9  MO  [        R                  SU S35        Mj     g)zI
Validate the RoPE config arguments, given a `"PreTrainedConfig"` object
r    NrÁ   Úfull_attentionr   rÂ   rÃ   Ú
_validate_Ú_rope_parameters©Úignore_keyszMMissing validation function in 'RotaryEmbeddingConfigMixin' for 'rope_type'='Ú')
r!   rÆ   rÇ   rÈ   rÁ   ÚvaluesrM   r½   rÄ   rÅ   )r'   rT   r    r   Úvalidation_fns        r,   Úvalidate_ropeÚ(RotaryEmbeddingConfigMixin.validate_rope  sç   € ô  ' tÐ->ÀÓEÐÞ#Øä�4˜¨Ó-Ñ9¼cÐBV×B[ÑB[ÓB]Ó>^×>gÑ>gØ×Ñ÷?
ñ ?
ð à$4Ð6JÐ#KÐ à3×:Ñ:Ö<ˆOØ'×+Ñ+¨K¸×9LÑ9LÈVÐU^Ó9_Ó`ˆIÜ# D¨J°y°kÐAQÐ*RÐTXÓYˆMØ+4˜KÑ(àÑ(Ù˜o×;^Ñ;^Ô_ä—‘ØcÐdmÐcnÐnoÐpöò  =r/   Nr    rÏ   c                 ón   • S1nS1n[        UR                  5       5      nUS   nU R                  XeX4US9  g )Nr   rD   ©Úoptional_keysrÏ   )rÆ   rÇ   Ú_check_received_keys)r'   r    rÏ   Úrequired_keysr×   Úreceived_keysr   s          r,   Ú!_validate_default_rope_parametersÚ<RotaryEmbeddingConfigMixin._validate_default_rope_parameters$  sH   € Ø$˜ˆØ%˜ˆÜ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ!Ø mÐ^ið 	"ò 	
r/   c                 óô   • SS1nS1n[        UR                  5       5      nUS   nU R                  XeX4US9  US   nUb!  [        U[        [
        45      (       a  US:  a  [        R                  SU 35        g g ©Nr   rC   rD   rÖ   rF   úB`rope_parameters`'s factor field must be a float or int >= 1, got ©rÆ   rÇ   rØ   rf   rS   rP   rÄ   rÅ   ©r'   r    rÏ   rÙ   r×   rÚ   r   rC   s           r,   Ú _validate_linear_rope_parametersÚ;RotaryEmbeddingConfigMixin._validate_linear_rope_parameters-  ó�   € Ø$ hÐ/ˆØ%˜ˆÜ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ!Ø mÐ^ið 	"ñ 	
ð ! Ñ*ˆØ‰>¤¨F´U¼C°L×!AÑ!AÀVÈcÃ\Ü�N‰NÐ_Ð`fÐ_gÐhÕið FRr/   c                 óô   • SS1nS1n[        UR                  5       5      nUS   nU R                  XeX4US9  US   nUb!  [        U[        [
        45      (       a  US:  a  [        R                  SU 35        g g rÞ   rà   rá   s           r,   Ú!_validate_dynamic_rope_parametersÚ<RotaryEmbeddingConfigMixin._validate_dynamic_rope_parameters:  rä   r/   c           	      óš  • 1 Skn1 Skn[        UR                  5       5      nUS   nU R                  XeX4US9  US   nUb!  [        U[        [
        45      (       a  US:  a  [        R                  SU 35        UR                  S5      nUb3  [        U[        5      (       a  US	:  a  [        R                  S
U 35        UR                  S5      n	U	b3  [        U	[        [
        45      (       d  [        R                  SU	 35        UR                  S5      n
U
b3  [        U
[        [
        45      (       d  [        R                  SU
 35        U	=(       d    SU
=(       d    S:  a  [        R                  SU	 SU
 S35        U R                  S   nU R                  U-  nXÇ:w  a'  US:w  a   [        R                  SU SU SU S35        g g g )N>   rC   r   r   >   rl   r‚   rt   rv   rD   rm   rW   r   rÎ   rC   rF   rß   rW   r   zO`rope_parameters`'s attention_factor field must be a float greater than 0, got rt   z@`rope_parameters`'s beta_fast field must be a float or int, got rv   z@`rope_parameters`'s beta_slow field must be a float or int, got ru   r	   zR`rope_parameters`'s beta_fast field must be greater than beta_slow, got beta_fast=z( (defaults to 32 if None) and beta_slow=z (defaults to 1 if None)r   zKThe explicitly set RoPE scaling factor (config.rope_parameters['factor'] = zä) does not match the ratio implicitly set by other parameters (implicit factor = post-yarn context length / pre-yarn context length = config.max_position_embeddings / config.rope_parameters['original_max_position_embeddings'] = z). Using the explicit factor (z�) in YaRN. This may cause unexpected behaviour in model usage, please correct the 'original_max_position_embeddings' fields in the model config.)rÆ   rÇ   rØ   rf   rS   rP   rÄ   rÅ   rM   r    re   Úwarning_once)r'   r    rÏ   rÙ   r×   rÚ   r   rC   rW   rt   rv   r   Úimplicit_factors                r,   Ú_validate_yarn_rope_parametersÚ9RotaryEmbeddingConfigMixin._validate_yarn_rope_parametersG  së  € ÚSˆò
ˆô ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ! )¸MÐfqÐ!Ñrà  Ñ*ˆØ‰>¤¨F´U¼C°L×!AÑ!AÀVÈcÃ\Ü�N‰NÐ_Ð`fÐ_gÐhÔià*×.Ñ.Ð/AÓBÐØÑ'´Ð<LÌe×1TÑ1TÐXhÐklÓXlÜ�N‰NØaÐbrÐasÐtôð $×'Ñ'¨Ó4ˆ	ØÑ ¬°IÄÄs¸|×)LÑ)LÜ�N‰NÐ]Ð^gÐ]hÐiÔjØ#×'Ñ'¨Ó4ˆ	ØÑ ¬°IÄÄs¸|×)LÑ)LÜ�N‰NÐ]Ð^gÐ]hÐiÔjà�O˜ 	§¨QÓ/Ü�N‰NØdÐenÐdoð p:Ø:C¸ÐD\ð^ôð ,0×+?Ñ+?Ð@bÑ+cÐ(Ø×6Ñ6Ð9YÑYˆØÓ$¨¸AÓ)=Ü×ÑØ]Ð^dÐ]eð fqð #Ð#Ð#AÀ&Àð J~ð	~õð *>Ð$r/   c                 óÜ  • 1 Skn1 Skn[        UR                  5       5      nUS   nU R                  XeX4US9  UR                  SS5      n[	        U SU R
                  U R                  -  5      n[        X‡-  5      n	UR                  S5      n
[        U
[        5      (       a  [        S	 U
 5       5      (       d  [        R                  S
U
 35        [        U
5      U	S-  :w  a'  [        R                  SU	S-   S[        U
5       35        UR                  S5      n[        U[        5      (       a  [        S U 5       5      (       d  [        R                  SU 35        [        U5      U	S-  :w  a'  [        R                  SU	S-   S[        U5       35        UR                  S5      nUS   nUc  Ub  [        R                  S5        OUUc  Uc  [        R                  S5        O9[        U[        [        45      (       a  US:  a  [        R                  SU 35        UR                  S5      nUb;  [        U[        [        45      (       a  US:  a  [        R                  SU 35        g g g )N>   r   r“   r”   r   >   rC   rD   rW   r   rÎ   rE   rF   rG   r”   c              3   óN   #   • U  H  n[        U[        [        45      v •  M     g 7fr?   ©rf   rP   rS   ©Ú.0r:   s     r,   Ú	<genexpr>ÚPRotaryEmbeddingConfigMixin._validate_longrope_rope_parameters.<locals>.<genexpr>‡  s!   é € Ð6iÒ\hÐWX´zÀ!ÄcÌ5À\×7RÐ7RÒ\hùó   ‚#%zF`rope_parameters`'s short_factor field must be a list of numbers, got rH   z8`rope_parameters`'s short_factor field must have length z, got r“   c              3   óN   #   • U  H  n[        U[        [        45      v •  M     g 7fr?   rï   rð   s     r,   rò   ró   �  s!   é € Ð5gÒ[fÐVW´jÀÄSÌ%ÀL×6QÐ6QÒ[fùrô   zE`rope_parameters`'s long_factor field must be a list of numbers, got z7`rope_parameters`'s long_factor field must have length rC   r   av  This model config has set a `rope_parameters['original_max_position_embeddings']` field, to be used together with `max_position_embeddings` to determine a scaling factor. Please set the `factor` field of `rope_parameters`with this ratio instead -- we recommend the use of this field over `original_max_position_embeddings`, as it is compatible with most model architectures.z4Missing required keys in `rope_parameters`: 'factor'rß   rW   g        zV`rope_parameters`'s attention_factor field must be a float or int greater than 0, got )rÆ   rÇ   rØ   rM   r!   rN   rO   rP   rf   r´   ÚallrÄ   rÅ   Úlenré   rS   )r'   r    rÏ   rÙ   r×   rÚ   r   rE   rG   rV   r”   r“   rC   r   rW   s                  r,   Ú"_validate_longrope_rope_parametersÚ=RotaryEmbeddingConfigMixin._validate_longrope_rope_parameters{  sZ  € ÚhˆÚDˆÜ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ! )¸MÐfqÐ!Ñrà /× 3Ñ 3Ð4KÈSÓ QÐÜ˜4 ¨T×-=Ñ-=À×AYÑAYÑ-YÓZˆÜ�(Ñ2Ó3ˆà&×*Ñ*¨>Ó:ˆÜ˜<¬×.Ñ.´3Ñ6iÑ\hÓ6i×3iÑ3iÜ�N‰NÐcÐdpÐcqÐrÔsÜˆ|Ó  q¡Ó(Ü�N‰NØJÈ3ÐRSÉ8È*ÐTZÔ[^Ð_kÓ[lÐZmÐnôð &×)Ñ)¨-Ó8ˆÜ˜;¬×-Ñ-´#Ñ5gÑ[fÓ5g×2gÑ2gÜ�N‰NÐbÐcnÐboÐpÔqÜˆ{Ó˜s a™xÓ'Ü�N‰NØIÈ#ÐQRÉ(ÈÐSYÔZ]Ð^iÓZjÐYkÐlôð !×$Ñ$ XÓ.ˆØ+:Ð;]Ñ+^Ð(ð ‰>Ð>ÑJÜ×ÑðEõð ‰^Ð @Ñ HÜ�N‰NÐQÕRÜ˜F¤U¬C L×1Ñ1°V¸c³\Ü�N‰NÐ_Ð`fÐ_gÐhÔià*×.Ñ.Ð/AÓBÐØÑ'´Ð<LÌuÔVYÈl×1[Ñ1[Ð_oÐruÓ_uÜ�N‰NØhÐiyÐhzÐ{õð `vÐ'r/   c                 óê  • 1 SknUS   n[        UR                  5       5      nU R                  XEX2S9  US   nUb!  [        U[        [
        45      (       a  US:  a  [        R                  SU 35        US   nUS   nUb  [        U[        [
        45      (       d  [        R                  S	U 35        Ub  [        U[        [
        45      (       d  [        R                  S
U 35        X‡::  a  [        R                  SU SU 35        US   n	U	b  [        U	[
        5      (       d  [        R                  SU	 35        X�R                  :¼  a&  [        R                  SU	 SU R                   35        g g )N>   rC   r   rD   rš   r›   r   r   rÎ   rC   rF   rß   rš   r›   zF`rope_parameters`'s low_freq_factor field must be a float, or int got zG`rope_parameters`'s high_freq_factor field must be a float or int, got zf`rope_parameters`'s high_freq_factor field must be greater than low_freq_factor, got high_freq_factor=z and low_freq_factor=r   zS`rope_parameters`'s original_max_position_embeddings field must be an integer, got zj`rope_parameters`'s original_max_position_embeddings field must be less than max_position_embeddings, got z and max_position_embeddings=)	rÆ   rÇ   rØ   rf   rS   rP   rÄ   rÅ   re   )
r'   r    rÏ   rÙ   r   rÚ   rC   rš   r›   r   s
             r,   Ú _validate_llama3_rope_parametersÚ;RotaryEmbeddingConfigMixin._validate_llama3_rope_parameters­  sŽ  € ò
ˆð $ KÑ0ˆ	Ü˜O×0Ñ0Ó2Ó3ˆØ×!Ñ! )¸MÐ!Ñcà  Ñ*ˆØ‰>¤¨F´U¼C°L×!AÑ!AÀVÈcÃ\Ü�N‰NÐ_Ð`fÐ_gÐhÔià)Ð*;Ñ<ˆØ*Ð+=Ñ>ÐØÑ"¬*°_ÄuÌcÀl×*SÑ*SÜ�N‰NÐcÐdsÐctÐuÔvØÑ#¬:Ð6FÌÔPSÈ×+UÑ+UÜ�N‰NØYÐZjÐYkÐlôð Ó.Ü�N‰NØxØ#Ð$Ð$9¸/Ð9JðLôð
 ,;Ð;]Ñ+^Ð(Ø+Ñ3¼:ÐFfÔhk×;lÑ;lÜ�N‰NØeØ3Ð4ð6ôð ,×/KÑ/KÓKÜ�N‰NØ|Ø3Ð4Ð4QÐRV×RnÑRnÐQoðqõð Lr/   c                 ó¼   • SS1nUS   n[        UR                  5       5      nU R                  XEX2S9  UR                  S5      nUc  [        R                  S5        g g )Nr   rD   rÎ   rE   zó`rope_parameters`'s partial_rotary_factor is None. This will default to 1.0 in the computation, making this equivalent to the linear_scaling RoPE type. Provide a value in the range [0.0, 1.0) to make use of the proportional RoPE funcitonality.)rÆ   rÇ   rØ   rM   rÄ   rÅ   )r'   r    rÏ   rÙ   r   rÚ   rE   s          r,   Ú&_validate_proportional_rope_parametersÚARotaryEmbeddingConfigMixin._validate_proportional_rope_parametersØ  sk   € Ø$ lÐ3ˆØ# KÑ0ˆ	Ü˜O×0Ñ0Ó2Ó3ˆØ×!Ñ! )¸MÐ!Ñcà /× 3Ñ 3Ð4KÓ LÐØ Ñ(Ü�N‰NðCõð )r/   r   rÚ   rÙ   r×   c                 ó@  • SU;   a  US1-  nUR                  S5        U=(       d
    [        5       nSU;  a  UR                  S5        Ub  U[        U5      -  nX!-
  nU(       a  [        SU  SU 35      eX-
  U-
  nU(       a  [        R	                  SU  SU 35        gg)z\Compare the received keys in `config.rope_parameters` against the expected and optional keysrÂ   r   rE   Nz<Missing required keys in `rope_parameters` for 'rope_type'='z': z8Unrecognized keys in `rope_parameters` for 'rope_type'=')ÚaddrÆ   ÚKeyErrorrÄ   rÅ   )r   rÚ   rÙ   r×   rÏ   Úmissing_keysÚunused_keyss          r,   rØ   Ú/RotaryEmbeddingConfigMixin._check_received_keysæ  s½   € ð �]Ó"Ø˜f˜XÑ%ˆMØ×Ñ˜kÔ*à%×.¬«ˆØ"¨-Ó7Ø×ÑÐ5Ô6ð Ñ"ØœS Ó-Ñ-ˆMà$Ñ4ˆÞÜÐYÐZcÐYdÐdgÐhtÐguÐvÓwÐwà#Ñ3°mÑCˆÞÜ�N‰NÐUÐV_ÐU`Ð`cÐdoÐcpÐqÕrð r/   )r½   r    )r'   r   r?   )NN)r­   r®   r¯   r°   r±   r»   rÆ   r½   r¾   rL   rÓ   ÚdictrÛ   râ   ræ   rë   rø   rû   rþ   Ústaticmethodr³   rØ   rµ   r¬   r/   r,   r·   r·   º  s>  † ñð €MÙ%(£UÐ"òò*./ô`ñ:
Àð 
ÐTWÐZ^ÑT^õ 
ñjÀð jÐSVÐY]ÑS]õ jñjÀð jÐTWÐZ^ÑT^õ jñ2¸dð 2ÐQTÐW[ÑQ[õ 2ñh0À$ð 0ÐUXÐ[_ÑU_õ 0ñd)Àð )ÐSVÐY]ÑS]õ )ñVÀdð ÐY\Ð_cÑYcõ ð ð
 %)Ø"&ñsØðsàðsð ðsð ˜T‘zð	sð
 ˜4‘Zôsó ósr/   r·   rÏ   c                 óz   • [         R                  " S[        5        U R                  5         U R	                  5         g)ze
This is a deprecated function.
It has been kept for backward compatibility with custom code models.
aX  `rope_config_validation` is deprecated and has been removed. Its functionality has been moved to RotaryEmbeddingConfigMixin.validate_rope method. PreTrainedConfig inherits this class, so please call self.validate_rope() instead. Also, make sure to use the new rope_parameters syntax. You can call self.standardize_rope_params() in the meantime.N)ÚwarningsÚwarnÚFutureWarningrL   rÓ   )r   rÏ   s     r,   Úrope_config_validationr    s5   € ô
 ‡M‚Mð	Gô
 	ôð ×"Ñ"Ô$Ø
×ÑÕr/   )NNNN)NNNNrG   )NNNr?   )%ro   r	  Úcollections.abcr   Ú	functoolsr   Útypingr   r   r   Úutilsr
   r   Ú
get_loggerr­   rÄ   r   Úconfiguration_utilsr   r@   rP   r³   ÚtuplerS   rX   rc   rj   r‘   r˜   r¥   r#   r  r²   r«   r·   rÆ   r  r¬   r/   r,   Ú<module>r     s  ðô Û Ý $Ý ß 5Ñ 5ç .ð 
×	Ò	˜HÓ	%€ñ ×ÑÛæÝ5ò`ðH ,0Ø'+ØØ!ñ	3&ØÐ'Ñ(ð3&à�^Ñ$ð3&ð �4‰Zð3&ð �d‘
ð	3&ð
 ˆ>˜5Ð Ñ!õ3&ðn ,0Ø'+ØØ!Ø"ñC&ØÐ'Ñ(ðC&à�^Ñ$ðC&ð �4‰ZðC&ð �d‘
ð	C&ð
 ðC&ð ˆ>˜5Ð Ñ!õC&ðN ,0Ø'+ØØ!ñ	C&ØÐ'Ñ(ðC&à�^Ñ$ðC&ð �4‰ZðC&ð �d‘
ð	C&ð
 ˆ>˜5Ð Ñ!õC&ðP (,ØØ!ñ	D&ØðD&à�^Ñ$ðD&ð �4‰ZðD&ð �d‘
ð	D&ð
 ˆ>˜5Ð Ñ!õD&ðR (,ØØ!ñ	U&ØðU&à�^Ñ$ðU&ð �4‰ZðU&ð �d‘
ð	U&ð
 ˆ>˜5Ð Ñ!õU&ðt (,ØØ!ñ	L,ØðL,à�^Ñ$ðL,ð �4‰ZðL,ð �d‘
ð	L,ð
 ˆ>˜5Ð Ñ!õL,ðf 6Ø.Ø$Ø,Ø(Ø9ñOÐ �T˜#˜x¨¨U°>À5Ð3HÑ-IÐ(IÑJÐJÑKó ô5#�Yô 5#÷pHsñ HsñV
Ð#=ð ÈCÐRVÉJö r/   