+
    QV-jÒâ  ã                   ó„  a € R  t0 t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHtH	t	H
t
 ^RIHtHt ]P                  ! ]4      t]! 4       '       d   ^ RIt]'       d   ^RIHt R tR!R R	 lltR"R
 R lltR!R R lltR#R R lltR#R R lltR#R R lltR]R]R]R]R]R]/t] ^ k  ! R R]
4      t ! R R4      tR$R R lltR# )%é    N)ÚCallable©Úwraps)ÚTYPE_CHECKINGÚOptionalÚ	TypedDict)Úis_torch_availableÚlogging)ÚPreTrainedConfigc                óP   a aa€ RR loRR lo\        S 4      RVVV 3R ll4       pV# )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                ó–  € \         P                  ! V4      ^,           pVf9   V P                  pV P                  pRpV P                  P
                  R,          pMJV P                  V,          p\        W R24      pV R2pV P                  P
                  V,          R,          pWH8”  di   \        W R24      '       g-   \        V,          p	V	! V P                  VV^,           VR7      w  r«V P                  V R2X
R	R
7       \        W R2V
4       R# VP                  V4      pV P                  V R2VR	R
7       \        W R2V4       R# )zbLongrope uses long factor if sequence is larger than original pretraining length, short otherwise.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   &&&&        Úq/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/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                  ! V4      ^,           pVf(   V P                  pV P                  pV P                  pRpM?V P                  V,          p\        W R2V P                  4      p\        W R24      pV R2pWF8”  dQ   \        V,          p	V	! V P                  VVVR7      w  q n        V P                  V R2V
RR	7       \        W R2V4       W@P                  8  de   W`P                  8”  dS   VP                  V4      pV P                  V R2VRR	7       \        W R
2V4       \        W R2V P                  4       R# R# R# )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)
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   r1   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                 óä   <€ Vf   V P                   MV P                   V,          pVe   RV/M/ pRV9   d   S! W3RVP                  /VB  MVR8X  d   S! W3RVP                  /VB  S! WV3/ VB # )Nr   Údynamicr(   Úlongrope)r   r(   )	r&   Úxr'   r   r   Úkwargsr4   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<   r4   r,   s   f @@r+   Údynamic_rope_updater?   "   s6   ú€ ô!KôF$YôL ˆ<Ó÷=ð =ó ð=ð €Nr.   c                ó¦   € V ^8„  d   QhR\         R,          R\         R,          R\        R,          R\        R,          R\        R	\        3,          /# ©
é   r   r   r(   útorch.devicer   Nr   Úreturnútorch.Tensor©r   ÚintÚstrÚtupleÚfloat)Úformats   "r+   Ú__annotate__rL   …   sW   € ÷ 3&ñ 3&ÜÐ'Õ(ð3&ä�^Õ$ð3&ô �4�Zð3&ô �d•
ð	3&ô
 ˆ>œ5Ð Õ!ñ3&r.   c           	     ó  € V P                  4        Ve   V P                  V,          MV P                  pVR,          pVR,          pVP                  RR4      p\        V RR4      ;'       g    V P                  V P
                  ,          p\        W‡,          4      p	Rp
RV\        P                  ! ^ V	^\        P                  R7      P                  V\        P                  R7      V	,          ,          ,          pWµ,          pWº3# )	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_dim©Údtype©r(   rT   )Ústandardize_rope_paramsr   Úgetr    Úhidden_sizeÚnum_attention_headsrG   r   ÚarangeÚint64r%   rJ   )r   r(   r   r   Úrope_parameters_dictrN   ÚbaserP   rR   ÚdimÚattention_factorr   s   &&&&        r+   Ú'_compute_linear_scaling_rope_parametersr`   …   sé   € ðB ×"Ñ"Ô$ØAKÒAW˜6×1Ñ1°*Ö=Ð]c×]sÑ]sÐØ! (Õ+€Fð   Õ-€DØ0×4Ñ4Ð5LÈcÓRÐÜ�v˜z¨4Ó0×dÐ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.   c                ó²   € V ^8„  d   QhR\         R,          R\         R,          R\        R,          R\        R,          R\        R	\        R
\        3,          /# )rB   r   r   r(   rC   r   Nr   Úhead_dim_keyrD   rE   rF   )rK   s   "r+   rL   rL   »   si   € ÷ C&ñ C&ÜÐ'Õ(ðC&ä�^Õ$ðC&ô �4�ZðC&ô �d•
ð	C&ô
 ðC&ô ˆ>œ5Ð Õ!ñC&r.   c           	     óæ  € V P                  4        Ve   V P                  V,          MV P                  p\        WR4      ;'       g    V P                  V P                  ,          pVR,          pVP                  RR4      pVP                  RR4      p	Rp
\        W–,          ^,          4      pRV\        P                  ! ^ ^V,          ^\        P                  R7      P                  V\        P                  R7      V,          ,          ,          pV^,          V,
          pV^ 8”  dA   \        P                  ! V\        P                  ! V\        P                  VR7      3^ R	7      pMTpWè,          pWê3# )
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).
NrO   rN   rQ   rP   rS   rU   ©rT   r(   )r^   )rV   r   r    rX   rY   rW   rG   r   rZ   r[   r%   rJ   ÚcatÚzerosÚfloat32)r   r(   r   r   rb   r\   rR   r]   rN   Úrope_proportionr_   Úrope_anglesÚinv_freq_rotatedÚnope_anglesr   s   &&&&&          r+   Ú%_compute_proportional_rope_parametersrl   »   sE  € ðJ ×"Ñ"Ô$ØAKÒAW˜6×1Ñ1°*Ö=Ð]c×]sÑ]sÐä�v¨TÓ2×fÐ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                ó¦   € V ^8„  d   QhR\         R,          R\         R,          R\        R,          R\        R,          R\        R	\        3,          /# rA   rF   )rK   s   "r+   rL   rL     s^   € ÷ C&ñ C&ÜÐ'Õ(ðC&ä�^Õ$ðC&ô �4�ZðC&ô �d•
ð	C&ô
 ˆ>œ5Ð Õ!ñC&r.   c           	     óŽ  € V P                  4        Ve   V P                  V,          MV P                  pVR,          pVP                  RR4      p\        V RV P                  V P
                  ,          4      p\        Wv,          4      pVR,          p	Rp
Vf   V P                  pM‚\        V\        P                  4      '       dN   \        P                  ! V\        P                  ! V P                  VP                  VP                  R7      4      pM\        W P                  4      pWYV,          V P                  ,          V	^,
          ,
          Wˆ^,
          ,          ,          ,          pRV\        P                   ! ^ V^\        P"                  R7      P%                  V\        P&                  R7      V,          ,          ,          pWº3# )	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).
rO   rP   rQ   rR   rN   rd   rS   rU   )rV   r   rW   r    rX   rY   rG   Úmax_position_embeddingsÚ
isinstancer   ÚTensorÚmaximumÚtensorrT   r(   r   rZ   r[   r%   rJ   )r   r(   r   r   r\   r]   rP   rR   r^   rN   r_   r   s   &&&&        r+   Ú_compute_dynamic_ntk_parametersrt     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                ó�   € V ^8„  d   QhRRR\         R,          R\        R,          R\        R,          R\        R	\        3,          /# rA   rF   )rK   s   "r+   rL   rL   G  sX   € ÷ D&ñ D&ØðD&ä�^Õ$ðD&ô �4�ZðD&ô �d•
ð	D&ô
 ˆ>œ5Ð Õ!ñD&r.   c                ó’  a€ V P                  4        Ve   V P                  V,          MV P                  pVR,          pVP                  RR4      p\        V RV P                  V P
                  ,          4      p\        Wv,          4      pVR,          p	VP                  R4      p
VP                  R4      pVP                  R4      pVR	,          pV	f   V P                  V,          p	RR
 lpV
f8   V'       d(   V'       d    \        V! W›4      V! Wœ4      ,          4      p
MV! V	4      p
VP                  R4      ;'       g    ^ pVP                  R4      ;'       g    ^pR oV3R lpR pV\        P                  ! ^ V^4      P                  V\        P                  R7      V,          ,          pRV,          pRV	V,          ,          pV P                  P                  RR4      pV! VVW…VV4      w  pp^V! VVV^,          4      P                  V\        P                  R7      ,
          pV^V,
          ,          VV,          ,           pVV
3# )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.
rO   rP   rQ   rR   rN   r_   ÚmscaleÚmscale_all_dimr   c                 ój   € V ^8:  d   R# RV,          \         P                  ! V 4      ,          R,           # )é   rQ   gš™™™™™¹?)ÚmathÚlog)Úscalerw   s   &&r+   Ú
get_mscaleÚ,_compute_yarn_parameters.<locals>.get_mscale•  s(   € Ø�AŒ:ÙØ�V�|œdŸhšh u›oÕ-°Õ3Ð3r.   Ú	beta_fastÚ	beta_slowc                óÄ   € V\         P                  ! W0^,          \         P                  ,          ,          4      ,          ^\         P                  ! V4      ,          ,          # )zPInverse dimension formula to find the dimension based on the number of rotations)r{   r|   Úpi)Únum_rotationsr^   r]   ro   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                óÌ   <€ S! WW44      pS! WW44      pV'       d-   \         P                  ! V4      p\         P                  ! V4      p\        V^ 4      \	        Wr^,
          4      3# )z.Find dimension range bounds based on rotations)r{   ÚfloorÚceilr   Úmin)	Úlow_rotÚhigh_rotr^   r]   ro   ÚtruncateÚlowÚhighr…   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                 óÈ   € W8X  d
   VR ,          p\         P                  ! V\         P                  R7      V ,
          W,
          ,          p\         P                  ! V^ ^4      pV# )gü©ñÒMbP?rS   )r   rZ   rg   Úclamp)rŠ   r   r^   Ú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.   rU   r�   T)rz   )rV   r   rW   r    rX   rY   rG   ro   rJ   r   rZ   r%   )r   r(   r   r   r\   r]   rP   rR   r^   rN   r_   rw   rx   r   r~   r€   r�   r�   r–   Ú	pos_freqsÚinv_freq_extrapolationÚinv_freq_interpolationr�   rŽ   r�   Úinv_freq_extrapolation_factorr   r…   s   &&&&                       @r+   Ú_compute_yarn_parametersrœ   G  s5  ø€ ð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                ó�   € V ^8„  d   QhRRR\         R,          R\        R,          R\        R,          R\        R	\        3,          /# rA   rF   )rK   s   "r+   rL   rL   Î  sX   € ÷ U&ñ U&ØðU&ä�^Õ$ðU&ô �4�ZðU&ô �d•
ð	U&ô
 ˆ>œ5Ð Õ!ñU&r.   c                óÖ  € V P                  4        Ve   V P                  V,          MV P                  pVR,          pVP                  RR4      p\        V RV P                  V P
                  ,          4      p\        Wv,          4      pVR,          p	VR,          p
VP                  R4      pVP                  R4      pVR	,          pVf   V P                  V,          pVfW   VR8:  d   RpML\        P                  ! ^\        P                  ! V4      \        P                  ! V4      ,          ,           4      pV'       d/   W-8”  d)   \        P                  ! V	\        P                  VR
7      pM'\        P                  ! V
\        P                  VR
7      p\        P                  ! ^ V^\        P                  VR
7      P!                  4       V,          pRWåV,          ,          ,          pVV3# )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.
rO   rP   rQ   rR   Úlong_factorÚshort_factorrN   r_   r   rd   )rV   r   rW   r    rX   rY   rG   ro   r{   Úsqrtr|   r   rs   rg   rZ   r[   rJ   )r   r(   r   r   r\   r]   rP   rR   r^   rŸ   r    rN   r_   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                ó�   € V ^8„  d   QhRRR\         R,          R\        R,          R\        R,          R\        R	\        3,          /# rA   rF   )rK   s   "r+   rL   rL   &  sX   € ÷ L,ñ L,ØðL,ä�^Õ$ðL,ô �4�ZðL,ô �d•
ð	L,ô
 ˆ>œ5Ð Õ!ñL,r.   c           	     ó¤  € V P                  4        Ve   V P                  V,          MV P                  pVR,          pVP                  RR4      p\        V RR4      ;'       g    V P                  V P
                  ,          p\        Wv,          4      pRp	RV\        P                  ! ^ V^\        P                  R7      P                  V\        P                  R7      V,          ,          ,          p
VR,          pVR	,          pVR
,          pVR,          pWì,          pWí,          p^\        P                  ,          V
,          p\        P                  ! VV8„  W«,          V
4      pVV,          V,
          WÜ,
          ,          p^V,
          V,          V,          VV,          ,           pVV8  ( VV8„  ( ,          p\        P                  ! VVV4      pVV	3# )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.
NrO   rP   rQ   rR   rS   rU   rN   Úlow_freq_factorÚhigh_freq_factorr   )rV   r   rW   r    rX   rY   rG   r   rZ   r[   r%   rJ   r{   rƒ   Úwhere)r   r(   r   r   r\   r]   rP   rR   r^   r_   r   rN   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Ð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.   Úlinearr7   Úyarnr8   Úllama3Úproportionalc                   ó0   a € ] tR tRt o RtV 3R ltRtV tR# )Ú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
c                ór  <€ V ^8„  d   Qh/ S[ R,          ;R&   S[R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   S[R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   S[ R,          ;R	&   S[S[ ,          R,          ;R
&   S[S[ ,          R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   # )rB   NrO   r   rP   rN   r   r_   r€   r�   r    rŸ   r§   r¨   )rJ   rH   rG   Úlist)rK   Ú__classdict__s   "€r+   rL   ÚRopeParameters.__annotate__‚  só   ø‡ ‚ ñT ˜•ÑñU ñV �T�zÑñW ñX ! 4�<Ñ'ñY ñZ �D�LÑñ[ ñ\ '*¨D¥jÑ0ñ] ñ^ ˜d•lÑ"ñ_ ñ` �t�|Ñña ñb �t�|Ññc ñd ‘u•+ Õ$Ñ$ñe ñf ‘e•˜tÕ#Ñ#ñg ñh ˜T•\Ñ!ñi ñj ˜d•lÑ"òk r.   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r»   s   @r+   r¸   r¸   ‚  s   ø‡ € ñ'÷ ƒ r.   r¸   c                   ó  a € ] tR tRt o RtRt]! 4       tR tR t	V 3R lR lt
RV 3R	 lR
 lltRV 3R lR lltRV 3R lR lltRV 3R lR lltRV 3R lR lltRV 3R lR lltRV 3R lR llt]RV 3R lR ll4       tRtV tR# )ÚRotaryEmbeddingConfigMixiniº  zS
A Mixin containing the functionality to standardize and validate RoPE parameters.
g     ˆÃ@c                ó  € VP                  R R4      pT;'       g    V P                  V n        V P                  e   V P                  M/ V n        VP                  R\        V RV P                  4      4      pV P                  P	                  RV4       VP                  R\        V RR4      4      pVeI   V P                  P	                  RV4       \        V P                  ;'       g    . 4      R0,          V n        V P                  4        V# )Úrope_scalingNrO   rP   )	Úpopr   r    Údefault_thetaÚ
setdefaultrW   ÚsetÚignore_keys_at_rope_validationrV   )r&   r:   rÊ   rO   rP   s   &,   r+   Úconvert_rope_params_to_dictÚ6RotaryEmbeddingConfigMixin.convert_rope_params_to_dictÂ  só   € Ø—z‘z .°$Ó7ˆØ+×CÐ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Ô[Ü25°d×6YÑ6Y×6_Ð6_Ð]_Ó2`Ø'ðdõ 3ˆDÔ/ð 	×$Ñ$Ô&Øˆr.   c                óÜ  € \        V RR4      p\        V RR4      p\        V RR4      ;'       g    / p\        V RR4      pV'       g    V'       g   \        P                  R4       R# Ve6   V/ 8X  g/   \        VP	                  4       4      P                  V4      '       gž   VP                  RVP                  RR	4      4       VP                  RV4       Ve   W#R&   VR,          R9   dS   \        V R
4      '       d   V P                  V P                  R
&   MÑV P                  P                  R
V P                  4       Mª\        V4       F›  pW5,          P                  RW5,          P                  RR	4      4       W5,          P                  RV4       Ve   W#V,          R&   W5,          R,          R9   g   Kn  V P                  V,          P                  R
V P                  4       K�  	  W0n
        R# )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)
rO   NrP   r   Úlayer_typeszG`standardize_rope_params` was called but no RoPE parameters were found.r   ÚtypeÚdefaultr   )rµ   r´   r8   )r    ÚloggerÚwarningrÎ   ÚkeysÚissubsetrÍ   rW   r!   r   r   ro   )r&   rO   rP   r   rÓ   r   s   &     r+   rV   Ú2RotaryEmbeddingConfigMixin.standardize_rope_paramsÙ  s¹  € ô ˜T <°Ó6ˆ
Ü '¨Ð.EÀtÓ LÐÜ! $Ð(9¸4Ó@×FÐ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                ó   <€ V ^8„  d   QhRR/# )rB   r&   r   r½   )rK   r»   s   "€r+   rL   Ú'RotaryEmbeddingConfigMixin.__annotate__	  s   ø€ ÷ ñ Ð.ñ r.   c                óÌ  € \        V RR4      pV'       g   R# \        V RR4      e:   \        VP                  4       4      P                  V P                  4      '       d   MRV/pVP                  4        Fl  pVP                  RVP                  RR4      4      p\        V RV R	2R4      pW2R&   Ve   V! W P                  R
7       KS  \        P                  RV R24       Kn  	  R# )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Ó   ÚvaluesrW   rÏ   rÖ   r×   )r&   r\   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.   Nc                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ©rB   r   râ   N©ÚdictrÎ   )rK   r»   s   "€r+   rL   rÜ   &  s"   ø€ ÷ 
ñ 
Áð 
ÑTWÐZ^ÕT^ñ 
r.   c                ó~   € R 0pR0p\        VP                  4       4      pVR ,          pV P                  WeW4VR7       R# )r   rO   ©Úoptional_keysrâ   N)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                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ré   rê   )rK   r»   s   "€r+   rL   rÜ   /  s&   ø€ ÷ jñ jÁð jÑSVÐY]ÕS]ñ jr.   c                ó  € R R0pR0p\        VP                  4       4      pVR ,          pV P                  WeW4VR7       VR,          pVe$   \        V\        \
        34      '       d   VR8  d   \        P                  RV 24       R# R# ©r   rN   rO   rí   NrQ   úB`rope_parameters`'s factor field must be a float or int >= 1, got ©rÎ   rØ   rï   rp   rJ   rG   rÖ   r×   ©r&   r   râ   rð   rî   rñ   r   rN   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                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ré   rê   )rK   r»   s   "€r+   rL   rÜ   <  s&   ø€ ÷ jñ jÁð jÑTWÐZ^ÕT^ñ jr.   c                ó  € R R0pR0p\        VP                  4       4      pVR ,          pV P                  WeW4VR7       VR,          pVe$   \        V\        \
        34      '       d   VR8  d   \        P                  RV 24       R# R# rö   rø   rù   s   &&&     r+   Ú!_validate_dynamic_rope_parametersÚ<RotaryEmbeddingConfigMixin._validate_dynamic_rope_parameters<  rü   r.   c                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ré   rê   )rK   r»   s   "€r+   rL   rÜ   I  s"   ø€ ÷ 2ñ 2¹dð 2ÑQTÐW[ÕQ[ñ 2r.   c           	     óÐ  € 0 Rmp0 Rmp\        VP                  4       4      pVR ,          pV P                  WeW4VR7       VR,          pVe$   \        V\        \
        34      '       d   VR8  d   \        P                  R	V 24       VP                  R4      pVe6   \        V\        4      '       d   V^ 8  d   \        P                  R
V 24       VP                  R4      p	V	e5   \        V	\        \
        34      '       g   \        P                  RV	 24       VP                  R4      p
V
e5   \        V
\        \
        34      '       g   \        P                  RV
 24       T	;'       g    ^ T
;'       g    ^8  d   \        P                  RV	 RV
 R24       VR,          pV P                  V,          pWÇ8w  d+   V^8w  d"   \        P                  RV RV RV R24       R# R# R# )r   rN   r   r_   r€   r�   rá   NrQ   r÷   zO`rope_parameters`'s attention_factor field must be a float greater than 0, got z@`rope_parameters`'s beta_fast field must be a float or int, got z@`rope_parameters`'s beta_slow field must be a float or int, got 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)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.>   rN   r   r   >   rw   r�   r€   r�   rO   rx   r_   )rÎ   rØ   rï   rp   rJ   rG   rÖ   r×   rW   ro   Úwarning_once)r&   r   râ   rð   rî   rñ   r   rN   r_   r€   r�   r   Úimplicit_factors   &&&          r+   Ú_validate_yarn_rope_parametersÚ9RotaryEmbeddingConfigMixin._validate_yarn_rope_parametersI  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ˆO˜ 	§ ¨QÔ/Ü�N‰NØdÐenÐdoð p:Ø:C¸ÐD\ð^ôð ,;Ð;]Õ+^Ð(Ø×6Ñ6Ð9YÕYˆØÔ$¨¸AÔ)=Ü×ÑØ]Ð^dÐ]eð fqð #Ð#Ð#AÀ&Àð J~ð	~öñ *>Ñ$r.   c                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ré   rê   )rK   r»   s   "€r+   rL   rÜ   }  s"   ø€ ÷ 0ñ 0Á$ð 0ÑUXÐ[_ÕU_ñ 0r.   c                óÎ  € 0 Rmp0 Rmp\        VP                  4       4      pVR ,          pV P                  WeW4VR7       VP                  RR4      p\	        V R	V P
                  V P                  ,          4      p\        W‡,          4      p	VP                  R4      p
\        V
\        4      '       d;   \        ;QJ d    R
 V
 4       F  '       d   K   RM	  RM! R
 V
 4       4      '       g   \        P                  RV
 24       \        V
4      V	^,          8w  d,   \        P                  RV	^,           R\        V
4       24       VP                  R4      p\        V\        4      '       d;   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        P                  RV 24       \        V4      V	^,          8w  d,   \        P                  RV	^,           R\        V4       24       VP                  R4      pVR,          pVf   Ve   \        P                  R4       MYVf   Vf   \        P                  R4       M;\        V\        \        34      '       d   VR8  d   \        P                  RV 24       VP                  R4      pVe@   \        V\        \        34      '       d   VR8  d   \        P                  RV 24       R# R# R# )r   r    rŸ   r   r_   rN   rá   rP   rQ   rR   c              3   óN   "  € T F  p\        V\        \        34      x € K  	  R # 5ir>   ©rp   rG   rJ   ©Ú.0r9   s   & r+   Ú	<genexpr>ÚPRotaryEmbeddingConfigMixin._validate_longrope_rope_parameters.<locals>.<genexpr>‰  s!   é € Ð6iÑ\hÐWX´zÀ!ÄcÌ5À\×7RÐ7RÓ\hùó   ‚#%FTzF`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   óN   "  € T F  p\        V\        \        34      x € K  	  R # 5i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 Nav  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÷   g        zV`rope_parameters`'s attention_factor field must be a float or int greater than 0, got >   r   rŸ   r    r   >   rN   rO   r_   )rÎ   rØ   rï   rW   r    rX   rY   rG   rp   rº   ÚallrÖ   r×   Úlenr  rJ   )r&   r   râ   rð   rî   rñ   r   rP   rR   r^   r    rŸ   rN   r   r_   s   &&&            r+   Ú"_validate_longrope_rope_parametersÚ=RotaryEmbeddingConfigMixin._validate_longrope_rope_parameters}  s|  € Ú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³3Ñ6iÑ\hÓ6i·3·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·#·#²#Ñ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                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ré   rê   )rK   r»   s   "€r+   rL   rÜ   ¯  s"   ø€ ÷ )ñ )Áð )ÑSVÐY]ÕS]ñ )r.   c                ó2  € 0 RmpVR ,          p\        VP                  4       4      pV P                  WEW2R7       VR,          pVe$   \        V\        \
        34      '       d   VR8  d   \        P                  RV 24       VR,          pVR,          pVe   \        V\        \
        34      '       g   \        P                  R	V 24       Ve   \        V\        \
        34      '       g   \        P                  R
V 24       W‡8:  d   \        P                  RV RV 24       VR,          p	V	e   \        V	\
        4      '       g   \        P                  RV	 24       W�P                  8¼  d(   \        P                  RV	 RV P                   24       R# R# )r   rN   r   r§   r¨   rá   NrQ   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=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=>   rN   r   rO   r§   r¨   r   )	rÎ   rØ   rï   rp   rJ   rG   rÖ   r×   ro   )
r&   r   râ   rð   r   rñ   rN   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                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ré   rê   )rK   r»   s   "€r+   rL   rÜ   Ú  s"   ø€ ÷ ñ Ádð ÑY\Ð_cÕYcñ r.   c                óÐ   € R R0pVR ,          p\        VP                  4       4      pV P                  WEW2R7       VP                  R4      pVf   \        P                  R4       R# R# )r   rO   rá   rP   Nzó`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ï   rW   rÖ   r×   )r&   r   râ   rð   r   rñ   rP   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.   c                óT   <€ V ^8„  d   QhRS[ RS[RS[RS[R,          RS[R,          /# )rB   r   rñ   rð   rî   Nrâ   )rH   rÎ   )rK   r»   s   "€r+   rL   rÜ   é  sJ   ø€ ÷ sñ sÙðsáðsñ ðsñ ˜T•zð	sñ
 ˜4•Zñsr.   c                óx  € RV9   d   VR0,          pVP                  R4       T;'       g    \        4       pRV9  d   VP                  R4       Ve   V\        V4      ,          pW!,
          pV'       d   \        RV  RV 24      hW,
          V,
          pV'       d   \        P	                  RV  RV 24       R# R# )z\Compare the received keys in `config.rope_parameters` against the expected and optional keysrÔ   r   rP   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>   )NN)r¾   r¿   rÀ   rÁ   rÂ   rÌ   rÎ   rÏ   rÐ   rV   ræ   rò   rú   rÿ   r  r  r  r  Ústaticmethodrï   rÄ   rÅ   rÆ   s   @r+   rÈ   rÈ   º  s—   ø‡ € ñð €MÙ%(£UÐ"òò../÷`ð ÷:
ò 
÷jò j÷jò j÷2ò 2÷h0ò 0÷d)ò )÷Vò ð ÷sñ só ösr.   rÈ   c                ó>   € V ^8„  d   QhR\         R\        R,          /# )rB   r   râ   N)rÈ   rÎ   )rK   s   "r+   rL   rL     s    € ÷ ñ Ô#=ð ÌCÐRVÍJñ r.   c                ó|   € \         P                  ! R\        4       V P                  4        V P	                  4        R# )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ÚFutureWarningrV   ræ   )r   râ   s   &&r+   Úrope_config_validationr*    s5   € ô
 ‡M‚Mð	Gô
 	ôð ×"Ñ"Ô$Ø
×ÑÖr.   c                ó–   € V ^8„  d   Qh/ ^ \         9   d5   \        \        \        R\        R\
        3,          3,          3,          ;R&   # )rB   .rE   r"   )Ú__conditional_annotations__rë   rH   r   rI   rJ   )rK   s   "r+   rL   rL      s<   € ‡�÷Rò ”Tœ#œx¨¬U°>Ä5Ð3HÕ-IÐ(IÕJÐJÕKñ òS r.   )NNNN)NNNNrR   )NNNr>   ) r,  r{   r'  Úcollections.abcr   Ú	functoolsr   Útypingr   r   r   Úutilsr	   r
   Ú
get_loggerr¾   rÖ   r   Úconfiguration_utilsr   r?   r`   rl   rt   rœ   r¤   r²   r"   r¸   rÈ   r*  rL   )r,  s   @r+   Ú<module>r3     sÏ   øð÷ €Û Ý $Ý ß 5Ñ 5ç .ð 
×	Ò	˜HÓ	%€ñ ×ÒÛçÝ5ò`÷F3&÷lC&÷LC&÷LD&÷NU&÷pL,ðf Ð5ØÐ.Ø
Ð$ØÐ,ØÐ(ØÐ9ðOÐ ó ô5#�Yô 5#÷pJsñ Js÷Z
ñ r.   