Ë
    S^(h¸€  ã                   ó²  — d dl Z d dlmZ d dlmZ ddlmZ ddlmZm	Z	  e	j                  e«      Z e«       rd dlZd„ Z	 	 	 d"dee   d	ed
   dee   dedef   fd„Z	 	 	 d"dee   d	ed
   dee   dedef   fd„Z	 	 	 d"dee   d	ed
   dee   dedef   fd„Z	 d#ded	d
dee   dedef   fd„Z	 d#ded	d
dee   dedef   fd„Z	 d#ded	d
dee   dedef   fd„ZeeeeeedœZ	 	 d$dedededee   dee   f
d„Zd#dedee   fd„Zd#dedee   fd„Zd#dedee   fd„Zd#dedee   fd„Zd#dedee   fd„Z d#dedee   fd „Z!eeeee e!dœZ"d#dedee   fd!„Z#y)%é    N©Úwraps)ÚOptionalé   )ÚPretrainedConfig)Úis_torch_availableÚloggingc                 óB   ‡ ‡‡— d„ Šd„ Št        ‰ «      ˆˆˆ 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                 óè  — t        j                  |«      dz   }t        | j                  d«      r| j                  j                  }n| j                  j
                  }||kD  rTt        | d«      s)| j                  | j                  ||dz   ¬«      \  | _        }| j                  d| j                  d¬«       y| j                  j                  |«      | _	        | j                  d| j                  d¬«       y)	zbLongrope uses long factor if sequence is larger than original pretraining length, short otherwise.r   Ú original_max_position_embeddingsÚlong_inv_freq©Úseq_lenÚinv_freqF©Ú
persistentN)ÚtorchÚmaxÚhasattrÚconfigr   Úmax_position_embeddingsÚrope_init_fnr   Úregister_bufferÚoriginal_inv_freqÚto)ÚselfÚposition_idsÚdevicer   r   Ú_s         ú^/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/modeling_rope_utils.pyÚlongrope_frequency_updatez6dynamic_rope_update.<locals>.longrope_frequency_update+   sÚ   € ä—)‘)˜LÓ)¨AÑ-ˆÜ�4—;‘;Ð BÔCØ/3¯{©{×/[Ñ/[Ñ,à/3¯{©{×/RÑ/RÐ,ØÐ5Ò5Ü˜4 Ô1Ø(,×(9Ñ(9Ø—K‘K Ð1QÐTUÑ1Uð ):ó )Ñ%�Ô" Að × Ñ  ¨T×-?Ñ-?ÈEÐ ÕRð &*×%;Ñ%;×%>Ñ%>¸vÓ%FˆDÔ"Ø× Ñ  ¨T×-CÑ-CÐPUÐ ÕVó    c                 óÆ  — t        j                  |«      dz   }|| j                  kD  rA| j                  | j                  ||¬«      \  }| _        | j                  d|d¬«       || _        || j                  k  rj| j                  | j                  kD  rP| j                  j                  |«      | _        | j                  d| j                  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   r   r   Fr   N)
r   r   Úmax_seq_len_cachedr   r   Úattention_scalingr   Úoriginal_max_seq_lenr   r   )r   r   r   r   r   s        r    Údynamic_frequency_updatez5dynamic_rope_update.<locals>.dynamic_frequency_update>   sÕ   € ô —)‘)˜LÓ)¨AÑ-ˆØ�T×,Ñ,Ò,Ø/3×/@Ñ/@ÀÇÁÈfÐ^eÐ/@Ó/fÑ,ˆH�dÔ,Ø× Ñ  ¨XÀ%Ð ÔHØ&-ˆDÔ#à�T×.Ñ.Ò.°4×3JÑ3JÈT×MfÑMfÒ3fð &*×%;Ñ%;×%>Ñ%>¸vÓ%FˆDÔ"Ø× Ñ  ¨T×-CÑ-CÐPUÐ ÔVØ&*×&?Ñ&?ˆDÕ#ð 4gÐ.r"   c                 ó¨   •— d| j                   v r ‰| ||j                  ¬«       n$| j                   dk(  r ‰| ||j                  ¬«        ‰| ||«      S )NÚdynamic)r   Úlongrope)Ú	rope_typer   )r   Úxr   r'   r!   Úrope_forwards      €€€r    Úwrapperz$dynamic_rope_update.<locals>.wrapperQ   sJ   ø€ à˜Ÿ™Ñ&Ù$ T¨<ÀÇÁÖIØ�^‰^˜zÒ)Ù% d¨LÀÇÁÕJÙ˜D ! \Ó2Ð2r"   r   )r-   r.   r'   r!   s   ` @@r    Údynamic_rope_updater/      s/   ú€ òWò&@ô& ˆ<Óõ3ó ð3ð €Nr"   r   r   ztorch.devicer   Úreturnztorch.Tensorc                 óÔ  — | �t        |«      dkD  rt        d|› d| › �«      ‚t        |«      dkD  r|d   }|d   }nZ| �X| j                  }t        | d«      r| j                  nd}t        | d| j                  | j                  z  «      }t        ||z  «      }d}dt        j                  dd	t        j                  ¬
«      j                  |t        j                  ¬«      |z  z  z  }	|	|fS )a  
    Computes the inverse frequencies according to the original RoPE implementation
    Args:
        config ([`~transformers.PretrainedConfig`]):
            The model configuration.
        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.
        rope_kwargs (`Dict`, *optional*):
            BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
    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).
    r   zƒUnexpected arguments: `**rope_kwargs` and `config` are mutually exclusive in `_compute_default_rope_parameters`, got `rope_kwargs`=ú and `config`=ÚbaseÚdimÚpartial_rotary_factorç      ð?Úhead_dimé   ©Údtype©r   r:   )ÚlenÚ
ValueErrorÚ
rope_thetar   r5   ÚgetattrÚhidden_sizeÚnum_attention_headsÚintr   ÚarangeÚint64r   Úfloat)
r   r   r   Úrope_kwargsr3   r4   r5   r7   Úattention_factorr   s
             r    Ú _compute_default_rope_parametersrH   \   s  € ð* Ðœc +Ó.°Ò2ÜðEØEPÀMÐQ_Ð`fÐ_gðió
ð 	
ô ˆ;Ó˜!ÒØ˜6Ñ"ˆØ˜%Ñ ‰Ø	Ð	Ø× Ñ ˆÜ@GÈÐPgÔ@h × <Ò <ÐnqÐÜ˜6 :¨v×/AÑ/AÀV×E_ÑE_Ñ/_Ó`ˆÜ�(Ð2Ñ2Ó3ˆàÐð �dœuŸ|™|¨A¨s°A¼U¿[¹[ÔI×LÑLÐTZÔbg×bmÑbmÐLÓnÐqtÑtÑuÑv€HØÐ%Ð%Ð%r"   c                 óÂ   — | �t        |«      dkD  rt        d|› d| › �«      ‚t        |«      dkD  r|d   }n| �| j                  d   }t        | ||fi |¤Ž\  }}|z  }||fS )a  
    Computes the inverse frequencies with linear scaling. Credits to the Reddit user /u/kaiokendev
    Args:
        config ([`~transformers.PretrainedConfig`]):
            The model configuration.
        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.
        rope_kwargs (`Dict`, *optional*):
            BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
    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).
    r   zŠUnexpected arguments: `**rope_kwargs` and `config` are mutually exclusive in `_compute_linear_scaling_rope_parameters`, got `rope_kwargs`=r2   Úfactor)r<   r=   Úrope_scalingrH   )r   r   r   rF   rJ   r   rG   s          r    Ú'_compute_linear_scaling_rope_parametersrL   †   s¢   € ð* Ðœc +Ó.°Ò2ÜðLØLWÈ=ÐXfÐgmÐfnðpó
ð 	
ô ˆ;Ó˜!ÒØ˜XÑ&‰Ø	Ð	Ø×$Ñ$ XÑ.ˆô "BÀ&È&ÐRYÑ!iÐ]hÑ!iÑ€HÐð
 �Ñ€HØÐ%Ð%Ð%r"   c                 óh  — | �t        |«      dkD  rt        d|› d| › �«      ‚t        |«      dkD  r|d   }|d   }|d   }|d   }nu| �s| j                  }t        | d«      r| j                  nd	}t        | d
| j                  | j                  z  «      }	t        |	|z  «      }| j                  }| j                  d   }d	}
|�|kD  r|n}|z  |z  |dz
  z
  |dz
  z  z  z  }d	|t        j                  d|dt        j                  ¬«      j                  |t        j                  ¬«      |z  z  z  }||
fS )a4  
    Computes the inverse frequencies with NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla
    Args:
        config ([`~transformers.PretrainedConfig`]):
            The model configuration.
        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.
        rope_kwargs (`Dict`, *optional*):
            BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
    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).
    r   z‚Unexpected arguments: `**rope_kwargs` and `config` are mutually exclusive in `_compute_dynamic_ntk_parameters`, got `rope_kwargs`=r2   r3   r4   r   rJ   r5   r6   r7   r   r8   r9   r;   )r<   r=   r>   r   r5   r?   r@   rA   rB   r   rK   r   rC   rD   r   rE   )r   r   r   rF   r3   r4   r   rJ   r5   r7   rG   r   s               r    Ú_compute_dynamic_ntk_parametersrN   ¯   s†  € ð, Ðœc +Ó.°Ò2ÜðDØDOÀ=ÐP^Ð_eÐ^fðhó
ð 	
ô ˆ;Ó˜!ÒØ˜6Ñ"ˆØ˜%Ñ ˆØ"-Ð.GÑ"HÐØ˜XÑ&‰Ø	Ð	Ø× Ñ ˆÜ@GÈÐPgÔ@h × <Ò <ÐnqÐÜ˜6 :¨v×/AÑ/AÀV×E_ÑE_Ñ/_Ó`ˆÜ�(Ð2Ñ2Ó3ˆØ"(×"@Ñ"@ÐØ×$Ñ$ XÑ.ˆàÐð !Ð,°Ð;RÒ1R‰gÐXo€Gð �F˜WÑ$Ð'>Ñ>À6ÈAÁ:ÑNÐTWÐ[^ÐabÑ[bÑTcÑdÑd€DØ�dœuŸ|™|¨A¨s°A¼U¿[¹[ÔI×LÑLÐTZÔbg×bmÑbmÐLÓnÐqtÑtÑuÑv€HØÐ%Ð%Ð%r"   c                 ó@  ‡— t        |«      dkD  rt        d|› �«      ‚| j                  }t        | d«      r| j                  nd}t        | d| j                  | j                  z  «      }t        ||z  «      }| j                  d   }| j                  j                  d«      }	| j                  j                  d«      }
| j                  j                  d	«      }d
| j                  v r| j                  d
   }| j                  |z  }n| j                  }dd„}|	€)|
r|rt         |||
«       |||«      z  «      }	n ||«      }	| j                  j                  d«      xs d}| j                  j                  d«      xs d}d„ Šˆfd„}d„ }|t        j                  d|d«      j                  |t        j                  ¬«      |z  z  }d|z  }d||z  z  } ||||||«      \  }}d ||||dz  «      j                  |t        j                  ¬«      z
  }|d|z
  z  ||z  z   }||	fS )a  
    Computes the inverse frequencies with NTK scaling. Please refer to the
    [original paper](https://arxiv.org/abs/2309.00071)
    Args:
        config ([`~transformers.PretrainedConfig`]):
            The model configuration.
        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.
        rope_kwargs (`Dict`, *optional*):
            BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
    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.
    r   zYUnexpected arguments: `**rope_kwargs` should be unset in `_compute_yarn_parameters`, got r5   r6   r7   rJ   rG   ÚmscaleÚmscale_all_dimr   r   c                 óJ   — | dk  ryd|z  t        j                  | «      z  dz   S )Nr   r6   gš™™™™™¹?)ÚmathÚlog)ÚscalerP   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 rotationsr8   )rS   rT   Úpi)Únum_rotationsr4   r3   r   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                 ó²   •— t        j                   ‰| |||«      «      }t        j                   ‰||||«      «      }t        |d«      t	        ||dz
  «      fS )z.Find dimension range bounds based on rotationsr   r   )rS   ÚfloorÚceilr   Úmin)Úlow_rotÚhigh_rotr4   r3   r   ÚlowÚhighr]   s          €r    Úfind_correction_rangez7_compute_yarn_parameters.<locals>.find_correction_range#  sU   ø€ ä�j‰jÑ,¨W°c¸4ÐAXÓYÓZˆÜ�y‰yÑ,¨X°s¸DÐBYÓZÓ[ˆÜ�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?r9   r   r   )r   rC   Úfloat32Úclamp)ra   r   r4   Ú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"   r8   r;   )r   )r<   r=   r>   r   r5   r?   r@   rA   rB   rK   Úgetr   rE   r   rC   r   )r   r   r   rF   r3   r5   r7   r4   rJ   rG   rP   rQ   r   rV   rW   rY   rf   rl   Ú	pos_freqsÚinv_freq_extrapolationÚinv_freq_interpolationrd   re   Úinv_freq_extrapolation_factorr   r]   s                            @r    Ú_compute_yarn_parametersrr   â   s_  ø€ ô( ˆ;Ó˜!ÒÜØgÐhsÐgtÐuó
ð 	
ð ×Ñ€DÜ<CÀFÐLcÔ<d˜F×8Ò8ÐjmÐÜ�v˜z¨6×+=Ñ+=À×A[ÑA[Ñ+[Ó\€HÜ
ˆhÐ.Ñ.Ó
/€CØ× Ñ  Ñ*€FØ×*Ñ*×.Ñ.Ð/AÓBÐØ× Ñ ×$Ñ$ XÓ.€FØ×(Ñ(×,Ñ,Ð-=Ó>€Nð
 *¨V×-@Ñ-@Ñ@Ø+1×+>Ñ+>Ð?aÑ+bÐ(Ø×/Ñ/Ð2RÑR‰à+1×+IÑ+IÐ(ó4ð ÐÙ‘nÜ$¡Z°¸Ó%?Á*ÈVÐUcÓBdÑ%dÓeÑá)¨&Ó1Ðð ×#Ñ#×'Ñ'¨Ó4Ò:¸€IØ×#Ñ#×'Ñ'¨Ó4Ò9¸€Iòpô/òð œŸ™ a¨¨aÓ0×3Ñ3¸6ÌÏÉÐ3ÓUÐX[Ñ[Ñ\€IØ  9™_ÐØ  F¨YÑ$6Ñ7Ðá% i°¸CÀÐGgÓh�I€Cˆð %&Ñ(:¸3ÀÀcÈQÁhÓ(O×(RÑ(RÐZ`Ôhm×hsÑhsÐ(RÓ(tÑ$tÐ!à !Ð&CÑ"CÑDØ
 Ð#@Ñ
@ñ	Að ð Ð%Ð%Ð%r"   c                 óÜ  — t        |«      dkD  rt        d|› �«      ‚| j                  }t        | d«      r| j                  nd}t        | d| j                  | j                  z  «      }t        ||z  «      }| j                  d   }| j                  d   }	| j                  j                  d«      }
| j                  j                  d	«      }t        | d
«      r&| j                  }| j                  | j                  z  }
n| j                  }|€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.
        device (`torch.device`):
            The device to use for initialization of the inverse frequencies.
        seq_len (`int`, *optional*):
            The current sequence length.
        rope_kwargs (`Dict`, *optional*):
            BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
    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.
    r   z]Unexpected arguments: `**rope_kwargs` should be unset in `_compute_longrope_parameters`, got r5   r6   r7   Úlong_factorÚshort_factorrJ   rG   r   r   )r:   r   r8   )r<   r=   r>   r   r5   r?   r@   rA   rB   rK   rm   r   r   rS   ÚsqrtrT   r   Útensorrh   rC   rD   rE   )r   r   r   rF   r3   r5   r7   r4   rt   ru   rJ   rG   r   Úext_factorsÚinv_freq_shaper   s                   r    Ú_compute_longrope_parametersrz   B  sÌ  € ô* ˆ;Ó˜!ÒÜØkØˆmðó
ð 	
ð
 ×Ñ€DÜ<CÀFÐLcÔ<d˜F×8Ò8ÐjmÐÜ�v˜z¨6×+=Ñ+=À×A[ÑA[Ñ+[Ó\€HÜ
ˆhÐ.Ñ.Ó
/€CØ×%Ñ% mÑ4€KØ×&Ñ& ~Ñ6€LØ× Ñ ×$Ñ$ XÓ.€FØ×*Ñ*×.Ñ.Ð/AÓBÐô
 ˆvÐ9Ô:Ø+1×+RÑ+RÐ(Ø×/Ñ/°&×2YÑ2YÑY‰à+1×+IÑ+IÐ(ð ÐØ�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                 ó¤  — t        | ||fi |¤Ž\  }}| j                  d   }| j                  d   }| j                  d   }| j                  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.
        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.
        rope_kwargs (`Dict`, *optional*):
            BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
    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.
    rJ   Úlow_freq_factorÚhigh_freq_factorr   r8   r   )rH   rK   rS   r[   r   Úwhere)r   r   r   rF   r   rG   rJ   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#  € ô( "BÀ&È&ÐRYÑ!iÐ]hÑ!iÑ€HÐà× Ñ  Ñ*€FØ×)Ñ)Ð*;Ñ<€OØ×*Ñ*Ð+=Ñ>ÐØ×)Ñ)Ð*LÑM€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"   )ÚdefaultÚlinearr)   Úyarnr*   Úllama3r+   Úreceived_keysÚrequired_keysÚoptional_keysÚignore_keysc                 óÔ   — d|v r|dhz  }|j                  d«       |�||z  }||z
  }|rt        d| › d|› �«      ‚|�	||z
  |z
  }n||z
  }|rt        j                  d| › d|› �«       yy)zYCompare the received keys in `config.rope_scaling` against the expected and optional keysÚtyper+   Nz9Missing required keys in `rope_scaling` for 'rope_type'='z': z5Unrecognized keys in `rope_scaling` for 'rope_type'=')ÚaddÚKeyErrorÚloggerÚwarning)r+   rŒ   r�   rŽ   r�   Úmissing_keysÚunused_keyss          r    Ú_check_received_keysr˜   ¹  s§   € ð �ÑØ˜&˜Ñ!ˆØ×Ñ˜+Ô&ð ÐØ˜Ñ$ˆà  =Ñ0€LÙÜÐRÐS\ÐR]Ð]`ÐamÐ`nÐoÓpÐpàÐ Ø# mÑ3°mÑC‰à# mÑ3ˆÙÜ�‰ÐNÈyÈkÐY\Ð]hÐ\iÐjÕkð r"   c                 ó¶   — | j                   }|j                  d|j                  dd «      «      }dh}t        |j                  «       «      }t	        ||||¬«       y )Nr+   r‘   ©r�   )rK   rm   ÚsetÚkeysr˜   )r   r�   rK   r+   r�   rŒ   s         r    Ú!_validate_default_rope_parametersr�   Ö  sT   € Ø×&Ñ&€LØ× Ñ  ¨l×.>Ñ.>¸vÀtÓ.LÓM€IØ �M€MÜ˜×)Ñ)Ó+Ó,€MÜ˜ M°=ÈkÖZr"   c                 ó"  — | j                   }|j                  d|j                  dd «      «      }ddh}t        |j                  «       «      }t	        ||||¬«       |d   }|�t        |t        «      r|dk  rt        j                  d|› �«       y y )Nr+   r‘   rJ   rš   r6   ú8`rope_scaling`'s factor field must be a float >= 1, got ©	rK   rm   r›   rœ   r˜   Ú
isinstancerE   r”   r•   )r   r�   rK   r+   r�   rŒ   rJ   s          r    Ú(_validate_linear_scaling_rope_parametersr¢   Þ  s‘   € Ø×&Ñ&€LØ× Ñ  ¨l×.>Ñ.>¸vÀtÓ.LÓM€IØ  (Ð+€MÜ˜×)Ñ)Ó+Ó,€MÜ˜ M°=ÈkÕZà˜(Ñ#€FØ€~œZ¨´Ô6¸&À3º,Ü�‰ÐQÐRXÐQYÐZÕ[ð ;Gr"   c                 ó*  — | j                   }|j                  d|j                  dd «      «      }ddh}dh}t        |j                  «       «      }t	        |||||¬«       |d   }|�t        |t        «      r|dk  rt        j                  d|› �«       y y )Nr+   r‘   rJ   r   rš   r6   rŸ   r    )r   r�   rK   r+   r�   rŽ   rŒ   rJ   s           r    Ú)_validate_dynamic_scaling_rope_parametersr¤   ê  sœ   € Ø×&Ñ&€LØ× Ñ  ¨l×.>Ñ.>¸vÀtÓ.LÓM€IØ  (Ð+€Mà7Ð8€MÜ˜×)Ñ)Ó+Ó,€MÜ˜ M°=À-Ð]hÕià˜(Ñ#€FØ€~œZ¨´Ô6¸&À3º,Ü�‰ÐQÐRXÐQYÐZÕ[ð ;Gr"   c                 óê  — | j                   }|j                  d|j                  dd «      «      }ddh}h d£}t        |j                  «       «      }t	        |||||¬«       |d   }|�t        |t        «      r|dk  rt        j                  d|› �«       |j                  d«      }|�-t        |t        «      r|d	k  rt        j                  d
|› �«       |j                  d«      }	|	�(t        |	t        «      st        j                  d|	› �«       |j                  d«      }
|
�(t        |
t        «      st        j                  d|
› �«       |	xs d|
xs dk  rt        j                  d|	› d|
› d�«       y y )Nr+   r‘   rJ   >   rP   rW   rY   rQ   rG   r   rš   r6   rŸ   rG   r   úL`rope_scaling`'s attention_factor field must be a float greater than 0, got rW   z6`rope_scaling`'s beta_fast field must be a float, got rY   z6`rope_scaling`'s beta_slow field must be a float, got rX   r   zO`rope_scaling`'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    )r   r�   rK   r+   r�   rŽ   rŒ   rJ   rG   rW   rY   s              r    Ú_validate_yarn_parametersr§   ø  s‚  € Ø×&Ñ&€LØ× Ñ  ¨l×.>Ñ.>¸vÀtÓ.LÓM€IØ  (Ð+€Mò€Mô ˜×)Ñ)Ó+Ó,€MÜ˜ M°=À-Ð]hÕià˜(Ñ#€FØ€~œZ¨´Ô6¸&À3º,Ü�‰ÐQÐRXÐQYÐZÔ[à#×'Ñ'Ð(:Ó;ÐØÐ#¬ZÐ8HÌ%Ô-PÐTdÐghÒThÜ�‰ØZÐ[kÐZlÐmô	
ð × Ñ  Ó-€IØÐ¤Z°	¼5Ô%AÜ�‰ÐOÐPYÈ{Ð[Ô\Ø× Ñ  Ó-€IØÐ¤Z°	¼5Ô%AÜ�‰ÐOÐPYÈ{Ð[Ô\àŠ�R˜IšN¨Ò+Ü�‰Ø]Ð^gÐ]hð i6Ø6?°[Ð@XðZõ	
ð ,r"   c                 óÚ  — | j                   }|j                  d|j                  dd «      «      }h d£}h d£}t        |j                  «       «      }t	        |||||¬«       t        | d«      r| j                  nd}t        | d| j                  | j                  z  «      }t        ||z  «      }	|j                  d	«      }
t        |
t        «      s*t        d
„ |
D «       «      rt        j                  d|
› �«       t!        |
«      |	dz  k(  s't        j                  d|	dz  › dt!        |
«      › �«       |j                  d«      }t        |t        «      s*t        d„ |D «       «      rt        j                  d|› �«       t!        |«      |	dz  k(  s't        j                  d|	dz  › dt!        |«      › �«       t        | d«      rt        j#                  d«       y |j                  d«      }|€t        j                  d«       n-t        |t$        «      r|dk  rt        j                  d|› �«       |j                  d«      }|�/t        |t$        «      r|dk  rt        j                  d|› �«       y y y )Nr+   r‘   >   r+   rt   ru   >   rJ   rG   r   rš   r5   r6   r7   ru   c              3   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­w©N©r¡   rB   rE   ©Ú.0r,   s     r    ú	<genexpr>z0_validate_longrope_parameters.<locals>.<genexpr>,  s   è ø€ Ò1dÐRS´*¸QÄÄeÀ×2MÑ1dùó   ‚ "zC`rope_scaling`'s short_factor field must be a list of numbers, got r8   z5`rope_scaling`'s short_factor field must have length z, got rt   c              3   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­wrª   r«   r¬   s     r    r®   z0_validate_longrope_parameters.<locals>.<genexpr>2  s   è ø€ Ò0bÐQR´¸AÄÄU¸|×1LÑ0bùr¯   zB`rope_scaling`'s long_factor field must be a list of numbers, got z4`rope_scaling`'s long_factor field must have length r   aY  This model has set a `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_scaling`with this ratio instead -- we recommend the use of this field over `original_max_position_embeddings`, as it is compatible with most model architectures.rJ   z1Missing required keys in `rope_scaling`: 'factor'rŸ   rG   g        r¦   )rK   rm   r›   rœ   r˜   r   r5   r?   r@   rA   rB   r¡   ÚlistÚallr”   r•   r<   Úwarning_oncerE   )r   r�   rK   r+   r�   rŽ   rŒ   r5   r7   r4   ru   rt   rJ   rG   s                 r    Ú_validate_longrope_parametersr´     sI  € Ø×&Ñ&€LØ× Ñ  ¨l×.>Ñ.>¸vÀtÓ.LÓM€IÚ@€MâV€MÜ˜×)Ñ)Ó+Ó,€MÜ˜ M°=À-Ð]hÕiä<CÀFÐLcÔ<d˜F×8Ò8ÐjmÐÜ�v˜z¨6×+=Ñ+=À×A[ÑA[Ñ+[Ó\€HÜ
ˆhÐ.Ñ.Ó
/€Cà×#Ñ# NÓ3€LÜ�l¤DÔ)¬cÑ1dÐWcÔ1dÔ.dÜ�‰Ð\Ð]iÐ\jÐkÔlÜˆ|Ó  q¡Ò(Ü�‰ÐNÈsÐVWÉxÈjÐX^Ô_bÐcoÓ_pÐ^qÐrÔsà×"Ñ" =Ó1€KÜ�k¤4Ô(¬SÑ0bÐVaÔ0bÔ-bÜ�‰Ð[Ð\gÐ[hÐiÔjÜˆ{Ó˜s a™xÒ'Ü�‰ÐMÈcÐUVÉhÈZÐW]Ô^aÐbmÓ^nÐ]oÐpÔqô
 ˆvÐ9Ô:Ü×ÑðAõ	
ð ×!Ñ! (Ó+ˆØˆ>Ü�N‰NÐNÕOÜ˜F¤EÔ*¨f°sªlÜ�N‰NÐUÐV\ÐU]Ð^Ô_à'×+Ñ+Ð,>Ó?ÐØÐ'ÜÐ.´Ô6Ð:JÈSÒ:PÜ—‘ØbÐcsÐbtÐuõð ;Qð (r"   c                 óä  — | j                   }|j                  d|j                  dd «      «      }h d£}t        |j                  «       «      }t	        ||||¬«       |d   }|�t        |t        «      r|dk  rt        j                  d|› �«       |d   }|d	   }|�t        |t        «      st        j                  d
|› �«       |�t        |t        «      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 )Nr+   r‘   >   rJ   r+   r|   r}   r   rš   rJ   r6   rŸ   r|   r}   z<`rope_scaling`'s low_freq_factor field must be a float, got z=`rope_scaling`'s high_freq_factor field must be a float, got zc`rope_scaling`'s high_freq_factor field must be greater than low_freq_factor, got high_freq_factor=z and low_freq_factor=r   zP`rope_scaling`'s original_max_position_embeddings field must be an integer, got zg`rope_scaling`'s original_max_position_embeddings field must be less than max_position_embeddings, got z and max_position_embeddings=)rK   rm   r›   rœ   r˜   r¡   rE   r”   r•   rB   r   )
r   r�   rK   r+   r�   rŒ   rJ   r|   r}   r   s
             r    Ú_validate_llama3_parametersr¶   P  s‹  € Ø×&Ñ&€LØ× Ñ  ¨l×.>Ñ.>¸vÀtÓ.LÓM€IÚv€MÜ˜×)Ñ)Ó+Ó,€MÜ˜ M°=ÈkÕZà˜(Ñ#€FØ€~œZ¨´Ô6¸&À3º,Ü�‰ÐQÐRXÐQYÐZÔ[à"Ð#4Ñ5€OØ#Ð$6Ñ7ÐØÐ¤j°Ä%Ô&HÜ�‰ÐUÐVeÐUfÐgÔhØÐ¤zÐ2BÄEÔ'JÜ�‰ÐVÐWgÐVhÐiÔjØ˜?Ò*Ü�‰ØqØÐ Ð 5°oÐ5FðHô	
ð
 (4Ð4VÑ'WÐ$Ø'Ð/´zÐBbÔdgÔ7hÜ�‰Ø^Ø/Ð0ð2ô	
ð (¨6×+IÑ+IÒIÜ�‰ØuØ/Ð0Ð0MÈf×NlÑNlÐMmðoõ	
ð Jr"   c                 óÞ   — t        | dd«      }|€y|j                  d|j                  dd«      «      }t        j                  |«      }|� || |¬«       yt        j	                  d|› d�«       y)	zO
    Validate the RoPE config arguments, given a `PretrainedConfig` object
    rK   Nr+   r‘   rˆ   rš   zTMissing validation function mapping in `ROPE_VALIDATION_FUNCTIONS` for 'rope_type'='ú')r?   rm   ÚROPE_VALIDATION_FUNCTIONSr”   r•   )r   r�   rK   r+   Úvalidation_fns        r    Úrope_config_validationr»     sw   € ô ˜6 >°4Ó8€LØÐØð × Ñ  ¨l×.>Ñ.>¸vÀyÓ.QÓR€IÜ-×1Ñ1°)Ó<€MØÐ Ù�f¨+Ö6ä�‰ØbÐclÐbmÐmnÐoõ	
r"   )NNNrª   )NN)$rS   Ú	functoolsr   Útypingr   Úconfiguration_utilsr   Úutilsr   r	   Ú
get_loggerÚ__name__r”   r   r/   rB   ÚtuplerE   rH   rL   rN   rr   rz   r‡   ÚROPE_INIT_FUNCTIONSÚstrr›   r˜   r�   r¢   r¤   r§   r´   r¶   r¹   r»   © r"   r    ú<module>rÆ      s  ðó Ý Ý å 1ß .ð 
ˆ×	Ñ	˜HÓ	%€ñ ÔÛò;ð~ *.Ø'+Ø!ñ'&ØÐ%Ñ&ð'&à�^Ñ$ð'&ð �c‰]ð'&ð
 ˆ>˜5Ð Ñ!ó'&ðV *.Ø'+Ø!ñ&&ØÐ%Ñ&ð&&à�^Ñ$ð&&ð �c‰]ð&&ð
 ˆ>˜5Ð Ñ!ó&&ðT *.Ø'+Ø!ñ0&ØÐ%Ñ&ð0&à�^Ñ$ð0&ð �c‰]ð0&ð
 ˆ>˜5Ð Ñ!ó0&ðh PTñ]&Øð]&Ø&4ð]&Ø?GÈ¹}ð]&à
ˆ>˜5Ð Ñ!ó]&ðB PTñ<&Øð<&Ø&4ð<&Ø?GÈ¹}ð<&à
ˆ>˜5Ð Ñ!ó<&ð@ PTñ(,Øð(,Ø&4ð(,Ø?GÈ¹}ð(,à
ˆ>˜5Ð Ñ!ó(,ð^ 0Ø5Ø.Ø$Ø,Ø(ñÐ ð $(Ø!%ñlØðlàðlð ðlð ˜C‘=ð	lð
 ˜#‘ólñ:[Ð.>ð [ÈXÐVYÉ]ó [ñ	\Ð5Eð 	\ÐT\Ð]`ÑTaó 	\ñ\Ð6Fð \ÐU]Ð^aÑUbó \ñ#
Ð&6ð #
ÀXÈcÁ]ó #
ñL/Ð*:ð /ÈÐRUÉó /ñd!
Ð(8ð !
ÀxÐPSÁ}ó !
ðL 1Ø6Ø8Ø%Ø-Ø)ñÐ ñ
Ð#3ð 
À(È3Á-ô 
r"   