Ë
    Gêñi®â  ã                   ó¼  — U d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 ddl
mZmZ  ej                  e«      Z e«       rd dlZerddlmZ d„ Z	 	 	 	 d!d	ed
   ded   dedz  dedz  dedef   f
d„Z	 	 	 	 	 d"d	ed
   ded   dedz  dedz  dededef   fd„Z	 	 	 	 d!d	ed
   ded   dedz  dedz  dedef   f
d„Z	 	 	 d#d	d
ded   dedz  dedz  dedef   f
d„Z	 	 	 d#d	d
ded   dedz  dedz  dedef   f
d„Z	 	 	 d#d	d
ded   dedz  dedz  dedef   f
d„ZeeeeeedœZeeededef   f   f   e d<    G d„ de	«      Z! G d„ d«      Z"d$d	e"de#dz  fd „Z$y)%é    N)ÚCallable©Úwraps)ÚTYPE_CHECKINGÚOptionalÚ	TypedDicté   )Úis_torch_availableÚlogging)ÚPreTrainedConfigc                 óH   ‡ ‡‡— dd„Šdd„Št        ‰ «      dˆˆˆ fd„	«       }|S )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  — t        j                  |«      dz   }|€4| j                  }| j                  }d}| j                  j
                  d   }n?| j                  |   }t        | |› d�«      }|› d�}| j                  j
                  |   d   }||kD  r\t        | |› d�«      s%t        |   }	 |	| j                  ||dz   |¬«      \  }
}| j                  |› d	�
d
¬«       t        | |› d�|
«       y|j                  |«      }| j                  |› d	�|d
¬«       t        | |› d�|«       y)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               úb/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/transformers/modeling_rope_utils.pyÚlongrope_frequency_updatez6dynamic_rope_update.<locals>.longrope_frequency_update/   sY  € ä—)‘)˜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Ò5Ü˜4 J <¨~Ð!>Ô?Ü2°9Ñ=�Ù#/Ø—K‘KØØ<¸qÑ@Ø)ô	$Ñ �˜qð × Ñ  F 8¨8Ð!4°mÐPUÐ ÔVÜ�D˜V˜H MÐ2°MÕBð !2× 4Ñ 4°VÓ <ÐØ× Ñ  F 8¨8Ð!4Ð6GÐTYÐ ÔZÜ�D˜V˜HÐ$5Ð6Ð8IÕJó    c                 óŠ  — t        j                  |«      dz   }|€'| j                  }| j                  }| j                  }d}n=| j                  |   }t        | |› d�| j                  «      }t        | |› d�«      }|› d�}||kD  rNt        |   }	 |	| j                  |||¬«      \  }
| _        | j                  |› d�|
d	¬
«       t        | |› d�|«       || j                  k  rc|| j                  kD  rS|j                  |«      }| j                  |› d�|d	¬
«       t        | |› d�|«       t        | |› d�| j                  «       yyy)a  
        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   r1   r   r*   r+   r   s              r,   Údynamic_frequency_updatez5dynamic_rope_update.<locals>.dynamic_frequency_updateR   s|  € ô —)‘)˜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�dÔ,ð × Ñ  F 8¨8Ð!4°hÈ5Ð ÔQÜ�D˜Z˜LÐ(;Ð<¸gÔFà�T×.Ñ.Ò.Ð3EÈ×HaÑHaÒ3að !2× 4Ñ 4°VÓ <ÐØ× Ñ  F 8¨8Ð!4Ð6GÐTYÐ ÔZÜ�D˜V˜HÐ$5Ð6Ð8IÔJÜ�D˜Z˜LÐ(;Ð<¸d×>WÑ>WÕXð 4bÐ.r.   c                 óÐ   •— |€| j                   n| j                   |   }|�d|ini }d|v r ‰| |fd|j                  i|¤Ž n|dk(  r ‰| |fd|j                  i|¤Ž  ‰| ||fi |¤ŽS )Nr   Údynamicr)   Úlongrope)r   r)   )	r'   Úxr(   r   r   Úkwargsr4   r-   Úrope_forwards	         €€€r,   Úwrapperz$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¨LÑTÀÇÁÐTÈVÒTÙ˜D ! \Ñ<°VÑ<Ð<r.   ©Nr   )r:   r;   r4   r-   s   ` @@r,   Údynamic_rope_updater=   "   s1   ú€ ó!KóF$YôL ˆ<Óö=ó ð=ð €Nr.   r   r   r)   ztorch.devicer   r   Úreturnztorch.Tensorc                 ó´  — | j                  «        |�| j                  |   n| j                  }|d   }|d   }|j                  dd«      }t        | dd«      xs | j                  | j
                  z  }t        ||z  «      }	d}
d|t        j                  d|	dt        j                  ¬	«      j                  |t        j                  ¬
«      |	z  z  z  }||z  }||
fS )aX  
    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)   rG   )Ústandardize_rope_paramsr    Úgetr!   Úhidden_sizeÚnum_attention_headsÚintr   ÚarangeÚint64r&   Úfloat)r   r)   r   r   Úrope_parameters_dictr@   ÚbaserB   rD   ÚdimÚattention_factorr   s               r,   Ú'_compute_linear_scaling_rope_parametersrU   …   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                 ót  — | j                  «        |�| j                  |   n| j                  }t        | |d«      xs | j                  | j                  z  }|d   }|j                  dd«      }|j                  dd«      }	d}
t        |	|z  dz  «      }d|t        j                  dd|z  dt        j                  ¬«      j                  |t        j                  ¬	«      |z  z  z  }|dz  |z
  }|dkD  r>t        j                  |t        j                  |t        j                  |¬
«      fd¬«      }n|}||z  }||
fS )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).
    NrA   r@   rC   rB   rE   r   rF   rH   ©rG   r)   )rS   )rI   r    r!   rK   rL   rJ   rM   r   rN   rO   r&   rP   ÚcatÚzerosÚfloat32)r   r)   r   r   rV   rQ   rD   rR   r@   Úrope_proportionrT   Úrope_anglesÚinv_freq_rotatedÚnope_anglesr   s                  r,   Ú%_compute_proportional_rope_parametersr`   »   sK  € ð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                 óþ  — | j                  «        |�| j                  |   n| j                  }|d   }|j                  dd«      }t        | d| j                  | j
                  z  «      }t        ||z  «      }|d   }	d}
|€| j                  }n{t        |t        j                  «      rKt        j                  |t        j                  | j                  |j                  |j                  ¬«      «      }nt        || j                  «      }||	|z  | j                  z  |	dz
  z
  ||dz
  z  z  z  }d|t        j                   d	|dt        j"                  ¬
«      j%                  |t        j&                  ¬«      |z  z  z  }||
fS )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).
    rA   rB   rC   rD   r@   rX   r	   rE   r   rF   rH   )rI   r    rJ   r!   rK   rL   rM   Úmax_position_embeddingsÚ
isinstancer   ÚTensorÚmaximumÚtensorrG   r)   r   rN   rO   r&   rP   )r   r)   r   r   rQ   rR   rB   rD   rS   r@   rT   r   s               r,   Ú_compute_dynamic_ntk_parametersrg     sw  € ð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˜v×=Ñ=Ó>ˆð �F˜WÑ$ v×'EÑ'EÑEÈ&ÐSTÉ*ÑUÐ[^ÐbeÐ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                 óÀ  ‡— | j                  «        |�| j                  |   n| j                  }|d   }|j                  dd«      }t        | d| j                  | j
                  z  «      }t        ||z  «      }|d   }	|j                  d«      }
|j                  d«      }|j                  d«      }|d	   }|	€| j                  |z  }	dd„}|
€)|r|rt         ||	|«       ||	|«      z  «      }
n ||	«      }
|j                  d«      xs d}|j                  d«      xs d
}d„ Šˆfd„}d„ }|t        j                  d|d«      j                  |t        j                  ¬«      |z  z  }d|z  }d|	|z  z  }| j                  j                  dd«      } |||||||«      \  }}d
 ||||dz  «      j                  |t        j                  ¬«      z
  }|d
|z
  z  ||z  z   }||
fS )aD  
    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.
    rA   rB   rC   rD   r@   rT   ÚmscaleÚmscale_all_dimr   r	   c                 óJ   — | dk  ryd|z  t        j                  | «      z  dz   S )Nr	   rC   gš™™™™™¹?)ÚmathÚlog)Úscaleri   s     r,   Ú
get_mscalez,_compute_yarn_parameters.<locals>.get_mscale•  s(   € Ø�AŠ:ØØ�V‰|œdŸh™h u›oÑ-°Ñ3Ð3r.   Ú	beta_fasté    Ú	beta_slowc                 ó’   — |t        j                  || dz  t         j                  z  z  «      z  dt        j                  |«      z  z  S )zPInverse dimension formula to find the dimension based on the number of rotationsrE   )rl   rm   Úpi)Únum_rotationsrS   rR   rb   s       r,   Úfind_correction_dimz5_compute_yarn_parameters.<locals>.find_correction_dim§  sB   € à”d—h‘hÐ6¸-È!Ñ:KÌdÏgÉgÑ:UÑVÓWÑWÐ\]Ô`d×`hÑ`hÐimÓ`nÑ\nÑoÐor.   c                 ó¾   •—  ‰| |||«      } ‰||||«      }|r*t        j                  |«      }t        j                  |«      }t        |d«      t	        ||dz
  «      fS )z.Find dimension range bounds based on rotationsr   r	   )rl   ÚfloorÚceilr   Úmin)	Úlow_rotÚhigh_rotrS   rR   rb   ÚtruncateÚlowÚhighrv   s	           €r,   Úfind_correction_rangez7_compute_yarn_parameters.<locals>.find_correction_range«  s^   ø€ á! '¨3°Ð6MÓNˆÙ" 8¨S°$Ð8OÓPˆÙÜ—*‘*˜S“/ˆCÜ—9‘9˜T“?ˆDÜ�3˜‹{œC  c¨A¡gÓ.Ð.Ð.r.   c                 ó¤   — | |k(  r|dz  }t        j                  |t         j                  ¬«      | z
  || z
  z  }t        j                  |dd«      }|S )Ngü©ñÒMbP?rF   r   r	   )r   rN   r[   Úclamp)rz   r   rS   Úlinear_funcÚ	ramp_funcs        r,   Úlinear_ramp_factorz4_compute_yarn_parameters.<locals>.linear_ramp_factor´  sL   € Ø�#Š:Ø�5‰LˆCä—|‘| C¬u¯}©}Ô=ÀÑCÈÈcÉ	ÑRˆÜ—K‘K ¨Q°Ó2ˆ	ØÐr.   r   rE   rH   r}   T)r	   )rI   r    rJ   r!   rK   rL   rM   rb   rP   r   rN   r&   )r   r)   r   r   rQ   rR   rB   rD   rS   r@   rT   ri   rj   r   ro   rp   rr   r€   r…   Ú	pos_freqsÚinv_freq_extrapolationÚinv_freq_interpolationr}   r~   r   Úinv_freq_extrapolation_factorr   rv   s                              @r,   Ú_compute_yarn_parametersrŠ   G  s9  ø€ ð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ÐUcÓ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                 ó@  — | j                  «        |�| j                  |   n| j                  }|d   }|j                  dd«      }t        | d| j                  | j
                  z  «      }t        ||z  «      }|d   }	|d   }
|j                  d«      }|j                  d«      }|d	   }|€| j                  |z  }|€I|dk  rd}nAt        j                  d
t        j                  |«      t        j                  |«      z  z   «      }|r,||kD  r't        j                  |	t        j                  |¬«      }n&t        j                  |
t        j                  |¬«      }t        j                  d|dt        j                  |¬«      j!                  «       |z  }d|||z  z  z  }||fS )a  
    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.
    rA   rB   rC   rD   Úlong_factorÚshort_factorr@   rT   r   r	   rX   r   rE   )rI   r    rJ   r!   rK   rL   rM   rb   rl   Úsqrtrm   r   rf   r[   rN   rO   rP   )r   r)   r   r   rQ   rR   rB   rD   rS   rŒ   r�   r@   rT   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 D¨.Ñ$8Ñ8Ñ9€HàÐ%Ð%Ð%r.   c                 óÈ  — | j                  «        |�| j                  |   n| j                  }|d   }|j                  dd«      }t        | dd«      xs | j                  | j
                  z  }t        ||z  «      }d}	d|t        j                  d|dt        j                  ¬«      j                  |t        j                  ¬	«      |z  z  z  }
|d
   }|d   }|d   }|d   }||z  }||z  }dt        j                  z  |
z  }t        j                  ||kD  |
|z  |
«      }||z  |z
  ||z
  z  }d|z
  |z  |z  ||z  z   }||k   ||kD   z  }t        j                  |||«      }||	fS )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.
    NrA   rB   rC   rD   r   rE   rF   rH   r@   Úlow_freq_factorÚhigh_freq_factorr   r	   )rI   r    rJ   r!   rK   rL   rM   r   rN   rO   r&   rP   rl   rt   Úwhere)r   r)   r   r   rQ   rR   rB   rD   rS   rT   r   r@   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ÐXgÑEgÑh€MØ˜]Ñ*¨nÑ<¸vÑEÈÐXfÑHfÑfÐØÐ!2Ñ2Ð3¸ÐBRÑ8RÐ6SÑS€NÜ—[‘[ Ð1BÀNÓS€NàÐ+Ð+Ð+r.   )Úlinearr6   Úyarnr7   Úllama3Úproportional.r#   c                   óÞ   — e Zd ZU dZedz  ed<   edz  ed<   edz  ed<   edz  ed<   edz  ed<   edz  ed<   edz  ed	<   edz  ed
<   ee   dz  ed<   ee   dz  ed<   edz  ed<   edz  ed<   y)ÚRopeParametersu  
    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
    NrA   r   rB   r@   r   rT   rp   rr   r�   rŒ   r“   r”   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rP   Ú__annotations__ÚstrrM   Úlist© 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                   ó  — e Zd ZdZdZ e«       Zd„ Zd„ Zdd„Z	dde
dedz  fd	„Zdde
dedz  fd
„Zdde
dedz  fd„Zdde
dedz  fd„Zdde
dedz  fd„Zdde
dedz  fd„Zdde
dedz  fd„Ze	 	 ddededededz  dedz  f
d„«       Zy)ÚRotaryEmbeddingConfigMixinz[
    A Mixin containing the functionality to standardize and validate RoPE parameters.
    g     ˆÃ@c                 óØ  — |j                  dd «      }|xs | j                  | _        | j                  �| j                  ni | _        |j                  dt        | d| j                  «      «      }| j                  j	                  d|«       |j                  dt        | dd «      «      }|�1| j                  j	                  d|«       | j                  dhz  | _        | j                  «        |S )NÚrope_scalingrA   rB   )Úpopr    r!   Údefault_thetaÚ
setdefaultrJ   Úignore_keys_at_rope_validationrI   )r'   r9   r°   rA   rB   s        r,   Úconvert_rope_params_to_dictz6RotaryEmbeddingConfigMixin.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                 ód  — t        | dd«      }t        | dd«      }t        | dd«      xs i }t        | dd«      }|s|st        j                  d«       y|�-|i k(  s(t        |j	                  «       «      j                  |«      s�|j                  d|j                  dd	«      «       |j                  d|«       |�||d<   |d   d
v ræt        | d«      r!| j                  | j                  d<   || _
        y| j                  j                  d| j                  «       || _
        yt        |«      D ]}  }||   j                  d||   j                  dd	«      «       ||   j                  d|«       |�|||   d<   ||   d   d
v sŒU| j                  |   j                  d| j                  «       Œ || _
        y)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)
        rA   NrB   r    Úlayer_typeszG`standardize_rope_params` was called but no RoPE parameters were found.r   ÚtypeÚdefault)r¡   r    r7   r   )r!   ÚloggerÚwarningÚsetÚkeysÚissubsetr³   rJ   r"   r   r    rb   )r'   rA   rB   r    r·   r   s         r,   rI   z2RotaryEmbeddingConfigMixin.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Ø×&Ñ& {°O×4GÑ4GÈÐPYÓ4ZÔ[Ø×&Ñ& |°ZÔ@Ø$Ð0Ø;P�Ð 7Ñ8ð ˜{Ñ+Ð/MÑMÜ˜4Ð!CÔDð PT×OtÑOt�D×(Ñ(Ð)KÑLð"  /ˆÕð ×(Ñ(×3Ñ3Ð4VÐX\×XtÑXtÔuð  /ˆÕô " +Ó.ò 	�
Ø 
Ñ+×6Ñ6°{ÀOÐT^ÑD_×DcÑDcÐdjÐluÓDvÔwØ 
Ñ+×6Ñ6°|ÀZÔPØ(Ð4ØK`�O JÑ/Ð0GÑHà" :Ñ.¨{Ñ;Ð?]Ò]Ø×(Ñ(¨Ñ4×?Ñ?Ø:¸D×<XÑ<Xõð	ð  /ˆÕr.   c                 ó¦  — t        | dd«      }|syt        | dd«      �3t        |j                  «       «      j                  | j                  «      rnd|i}|j                  «       D ]j  }|j                  d|j                  dd«      «      }t        | d|› d	�d«      }||d<   |� ||| j                  ¬
«       ŒRt        j                  d|› d�«       Œl y)zY
        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·   ÚvaluesrJ   r´   rº   r»   )r'   rQ   r    r   Úvalidation_fns        r,   Úvalidate_ropez(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ˆO˜KÑ(àÐ(Ù˜o¸4×;^Ñ;^Ö_ä—‘ØcÐdmÐcnÐnoÐpõñ
	r.   Nr    rÄ   c                 óx   — dh}dh}t        |j                  «       «      }|d   }| j                  |||||¬«       y )Nr   rA   ©Úoptional_keysrÄ   )r¼   r½   Ú_check_received_keys)r'   r    rÄ   Úrequired_keysrË   Úreceived_keysr   s          r,   Ú!_validate_default_rope_parametersz<RotaryEmbeddingConfigMixin._validate_default_rope_parameters$  sL   € Ø$˜ˆØ%˜ˆÜ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ!Ø�} mÀ=Ð^ið 	"õ 	
r.   c                 óð   — ddh}dh}t        |j                  «       «      }|d   }| j                  |||||¬«       |d   }|�t        |t        t
        f«      r|dk  rt        j                  d|› �«       y y ©Nr   r@   rA   rÊ   rC   úB`rope_parameters`'s factor field must be a float or int >= 1, got ©r¼   r½   rÌ   rc   rP   rM   rº   r»   ©r'   r    rÄ   rÍ   rË   rÎ   r   r@   s           r,   Ú _validate_linear_rope_parametersz;RotaryEmbeddingConfigMixin._validate_linear_rope_parameters-  ó�   € Ø$ hÐ/ˆØ%˜ˆÜ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ!Ø�} mÀ=Ð^ið 	"ô 	
ð ! Ñ*ˆØˆ>¤¨F´U¼C°LÔ!AÀVÈcÂ\Ü�N‰NÐ_Ð`fÐ_gÐhÕið FRr.   c                 óð   — ddh}dh}t        |j                  «       «      }|d   }| j                  |||||¬«       |d   }|�t        |t        t
        f«      r|dk  rt        j                  d|› �«       y y rÑ   rÓ   rÔ   s           r,   Ú!_validate_dynamic_rope_parametersz<RotaryEmbeddingConfigMixin._validate_dynamic_rope_parameters:  rÖ   r.   c           	      óX  — h d£}h d£}t        |j                  «       «      }|d   }| j                  |||||¬«       |d   }|�t        |t        t
        f«      r|dk  rt        j                  d|› �«       |j                  d«      }|�-t        |t        «      r|d	k  rt        j                  d
|› �«       |j                  d«      }	|	�.t        |	t        t
        f«      st        j                  d|	› �«       |j                  d«      }
|
�.t        |
t        t
        f«      st        j                  d|
› �«       |	xs d|
xs dk  rt        j                  d|	› d|
› d�«       | j                  d   }| j                  |z  }||k7  r&|dk7  r t        j                  d|› d|› d|› d�«       y y y )N>   r@   r   r   >   ri   r}   rp   rr   rA   rj   rT   r   rÃ   r@   rC   rÒ   rT   r   zO`rope_parameters`'s attention_factor field must be a float greater than 0, got rp   z@`rope_parameters`'s beta_fast field must be a float or int, got rr   z@`rope_parameters`'s beta_slow field must be a float or int, got rq   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Ì   rc   rP   rM   rº   r»   rJ   r    rb   Úwarning_once)r'   r    rÄ   rÍ   rË   rÎ   r   r@   rT   rp   rr   r   Úimplicit_factors                r,   Ú_validate_yarn_rope_parametersz9RotaryEmbeddingConfigMixin._validate_yarn_rope_parametersG  så  € ÚSˆò
ˆô ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ! )¨]¸MÈ=ÐfqÐ!Ôrà  Ñ*ˆØˆ>¤¨F´U¼C°LÔ!AÀVÈcÂ\Ü�N‰NÐ_Ð`fÐ_gÐhÔià*×.Ñ.Ð/AÓBÐØÐ'´Ð<LÌeÔ1TÐXhÐklÒXlÜ�N‰NØaÐbrÐasÐtôð $×'Ñ'¨Ó4ˆ	ØÐ ¬°IÄÄs¸|Ô)LÜ�N‰NÐ]Ð^gÐ]hÐiÔjØ#×'Ñ'¨Ó4ˆ	ØÐ ¬°IÄÄs¸|Ô)LÜ�N‰NÐ]Ð^gÐ]hÐiÔjàŠO˜ 	¢¨QÒ/Ü�N‰NØdÐenÐdoð p:Ø:C¸ÐD\ð^ôð ,0×+?Ñ+?Ð@bÑ+cÐ(Ø×6Ñ6Ð9YÑYˆØ˜fÒ$¨¸AÒ)=Ü×ÑØ]Ð^dÐ]eð fqð #Ð#Ð#AÀ&Àð J~ð	~õð *>Ð$r.   c                 óš  — h d£}h d£}t        |j                  «       «      }|d   }| j                  |||||¬«       |j                  dd«      }t	        | d| j
                  | j                  z  «      }t        ||z  «      }	|j                  d«      }
t        |
t        «      rt        d	„ |
D «       «      st        j                  d
|
› �«       t        |
«      |	dz  k7  r't        j                  d|	dz  › dt        |
«      › �«       |j                  d«      }t        |t        «      rt        d„ |D «       «      st        j                  d|› �«       t        |«      |	dz  k7  r't        j                  d|	dz  › dt        |«      › �«       |j                  d«      }|d   }|€|�t        j                  d«       nM|€|€t        j                  d«       n3t        |t        t        f«      r|dk  rt        j                  d|› �«       |j                  d«      }|�5t        |t        t        f«      r|dk  rt        j                  d|› �«       y y y )N>   r   rŒ   r�   r   >   r@   rA   rT   r   rÃ   rB   rC   rD   r�   c              3   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­wr<   ©rc   rM   rP   ©Ú.0r8   s     r,   ú	<genexpr>zPRotaryEmbeddingConfigMixin._validate_longrope_rope_parameters.<locals>.<genexpr>‡  s   è ø€ Ò6iÐWX´zÀ!ÄcÌ5À\×7RÑ6iùó   ‚ "zF`rope_parameters`'s short_factor field must be a list of numbers, got rE   z8`rope_parameters`'s short_factor field must have length z, got rŒ   c              3   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­wr<   rß   rà   s     r,   râ   zPRotaryEmbeddingConfigMixin._validate_longrope_rope_parameters.<locals>.<genexpr>�  s   è ø€ Ò5gÐVW´jÀÄSÌ%ÀL×6QÑ5gù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 r@   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Ò   rT   g        zV`rope_parameters`'s attention_factor field must be a float or int greater than 0, got )r¼   r½   rÌ   rJ   r!   rK   rL   rM   rc   r«   Úallrº   r»   ÚlenrÚ   rP   )r'   r    rÄ   rÍ   rË   rÎ   r   rB   rD   rS   r�   rŒ   r@   r   rT   s                  r,   Ú"_validate_longrope_rope_parametersz=RotaryEmbeddingConfigMixin._validate_longrope_rope_parameters{  sO  € ÚhˆÚDˆÜ˜O×0Ñ0Ó2Ó3ˆØ# KÑ0ˆ	Ø×!Ñ! )¨]¸MÈ=ÐfqÐ!Ôrà /× 3Ñ 3Ð4KÈSÓ QÐÜ˜4 ¨T×-=Ñ-=À×AYÑAYÑ-YÓZˆÜ�(Ð2Ñ2Ó3ˆà&×*Ñ*¨>Ó:ˆÜ˜<¬Ô.´3Ñ6iÐ\hÔ6iÔ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Ü�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°V¸c²\Ü�N‰NÐ_Ð`fÐ_gÐhÔià*×.Ñ.Ð/AÓBÐØÐ'´Ð<LÌuÔVYÈlÔ1[Ð_oÐruÒ_uÜ�N‰NØhÐiyÐhzÐ{õð `vÐ'r.   c                 óÂ  — h d£}|d   }t        |j                  «       «      }| j                  ||||¬«       |d   }|�t        |t        t
        f«      r|dk  rt        j                  d|› �«       |d   }|d   }|�t        |t        t
        f«      st        j                  d	|› �«       |�t        |t        t
        f«      st        j                  d
|› �«       ||k  rt        j                  d|› d|› �«       |d   }	|	�t        |	t
        «      st        j                  d|	› �«       |	| j                  k\  r&t        j                  d|	› d| j                  › �«       y y )N>   r@   r   rA   r“   r”   r   r   rÃ   r@   rC   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Ì   rc   rP   rM   rº   r»   rb   )
r'   r    rÄ   rÍ   r   rÎ   r@   r“   r”   r   s
             r,   Ú _validate_llama3_rope_parametersz;RotaryEmbeddingConfigMixin._validate_llama3_rope_parameters­  s‹  € ò
ˆð $ KÑ0ˆ	Ü˜O×0Ñ0Ó2Ó3ˆØ×!Ñ! )¨]¸MÐWbÐ!Ôcà  Ñ*ˆØˆ>¤¨F´U¼C°LÔ!AÀVÈcÂ\Ü�N‰NÐ_Ð`fÐ_gÐhÔià)Ð*;Ñ<ˆØ*Ð+=Ñ>ÐØÐ"¬*°_ÄuÌcÀlÔ*SÜ�N‰NÐcÐdsÐctÐuÔvØÐ#¬:Ð6FÌÔPSÈÔ+UÜ�N‰NØYÐZjÐYkÐlôð ˜Ò.Ü�N‰NØxØ#Ð$Ð$9¸/Ð9JðLôð
 ,;Ð;]Ñ+^Ð(Ø+Ð3¼:ÐFfÔhkÔ;lÜ�N‰NØeØ3Ð4ð6ôð ,¨t×/KÑ/KÒKÜ�N‰NØ|Ø3Ð4Ð4QÐRV×RnÑRnÐQoðqõð Lr.   c                 óÄ   — ddh}|d   }t        |j                  «       «      }| j                  ||||¬«       |j                  d«      }|€t        j                  d«       y y )Nr   rA   rÃ   rB   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Ì   rJ   rº   r»   )r'   r    rÄ   rÍ   r   rÎ   rB   s          r,   Ú&_validate_proportional_rope_parameterszARotaryEmbeddingConfigMixin._validate_proportional_rope_parametersØ  sp   € Ø$ lÐ3ˆØ# KÑ0ˆ	Ü˜O×0Ñ0Ó2Ó3ˆØ×!Ñ! )¨]¸MÐWbÐ!Ôcà /× 3Ñ 3Ð4KÓ LÐØ Ð(Ü�N‰NðCõð )r.   r   rÎ   rÍ   rË   c                 ó  — d|v r|dhz  }|j                  d«       |xs
 t        «       }d|vr|j                  d«       |�|t        |«      z  }||z
  }|rt        d| › d|› �«      ‚||z
  |z
  }|rt        j	                  d| › d|› �«       yy)z\Compare the received keys in `config.rope_parameters` against the expected and optional keysr¸   r   rB   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Ì   z/RotaryEmbeddingConfigMixin._check_received_keysæ  sÁ   € ð �]Ñ"Ø˜f˜XÑ%ˆMØ×Ñ˜kÔ*à%Ò.¬«ˆØ"¨-Ñ7Ø×ÑÐ5Ô6ð Ð"ØœS Ó-Ñ-ˆMà$ }Ñ4ˆÙÜÐYÐZcÐYdÐdgÐhtÐguÐvÓwÐwà# mÑ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µ   rI   rÈ   ÚdictrÏ   rÕ   rØ   rÜ   rç   ré   rë   Ústaticmethodrª   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                 óx   — t        j                  dt        «       | j                  «        | j	                  «        y)zq
    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ÚFutureWarningrI   rÈ   )r   rÄ   s     r,   Úrope_config_validationr÷     s5   € ô
 ‡M�Mð	Gô
 	ôð ×"Ñ"Ô$Ø
×ÑÕr.   )NNNN)NNNNrD   )NNNr<   )%rl   rô   Úcollections.abcr   Ú	functoolsr   Útypingr   r   r   Úutilsr
   r   Ú
get_loggerr¥   rº   r   Úconfiguration_utilsr   r=   rM   rª   ÚtuplerP   rU   r`   rg   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.   