+
    œ°³j8  ã                   ó4  € ^ RI t ^ RIHt ^RIHt ^RIHt ^RIHtH	t	H
t
HtHt ^RIHt ^RIHt ]P"                  ! ]4      tRt ! R R	]4      t ! R
 R]4      tR tRR lt] ! R R]4      4       t ! R R]	4      t ! R R]
4      t ! R R]4      t. ROtR# )é    N)Úlogging)Úno_inherit_decorator)ÚLlamaAttentionÚLlamaForCausalLMÚLlamaForSequenceClassificationÚLlamaForTokenClassificationÚLlamaRotaryEmbedding)ÚPhi3MLP)Ú	GlmConfigzTHUDM/glm-4-9bc                   ó   € ] tR t^%tRtR# )ÚGlmMLP© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    Úd/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/glm/modular_glm.pyr   r   %   ó   † Ûr   r   c                   ó6   a € ] tR t^)t o RV 3R lR lltRtV tR# )ÚGlmRotaryEmbeddingNc                óP   <€ V ^8„  d   QhRS[ RS[S[P                  S[3,          /# )é   ÚconfigÚreturn)r   ÚtupleÚtorchÚTensorÚfloat)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚGlmRotaryEmbedding.__annotate__*   s.   ø€ ÷ 5ñ 5±	ð 5ÑUZÑ[`×[gÑ[gÑinÐ[nÕUoñ 5r   c           	     óŠ  € V P                   R,          pV P                   P                  RR4      p\        V RR4      ;'       g    V P                  V P                  ,          p\        WT,          4      pRpRV\        P                  ! ^ V^\        P                  R7      V,          ,          ,          pVP                  V4      V3# )a~  
Computes the inverse frequencies according to the original RoPE implementation
Args:
    config ([`~transformers.PreTrainedConfig`]):
        The model configuration.
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).
Ú
rope_thetaÚpartial_rotary_factorg      ð?Úhead_dimN)Údtype)
Úrope_parametersÚgetÚgetattrÚhidden_sizeÚnum_attention_headsÚintr   Úaranger!   Úto)	r   ÚdeviceÚkwargsÚbaser(   r)   ÚdimÚattention_factorÚinv_freqs	   &&,      r   Úcompute_default_rope_parametersÚ2GlmRotaryEmbedding.compute_default_rope_parameters*   s¦   € ð ×%Ñ% lÕ3ˆØ &× 6Ñ 6× :Ñ :Ð;RÐTWÓ XÐÜ˜6 :¨tÓ4×hÐh¸×8JÑ8JÈf×NhÑNhÕ8hˆÜ�(Õ2Ó3ˆàÐà˜$¤5§<¢<°°3¸ÄÇÁÔ#MÐPSÕ#SÕTÕUˆØ�{‰{˜6Ó"Ð$4Ð4Ð4r   r   ©N)r   r   r   r   r9   r   Ú__classdictcell__)r#   s   @r   r   r   )   s   ø‡ € ÷5÷ 5ð 5r   r   c                óz   € V R,          pV R,          p\         P                  ! V) V3RR7      P                  R4      # )z*Rotates half the hidden dims of the input.©r6   ).:r   Nr   ).:é   Nr   éÿÿÿÿéþÿÿÿ)r   ÚstackÚflatten)ÚxÚx1Úx2s   &  r   Úrotate_halfrG   ?   s6   € à	
ˆ9�€BØ	
ˆ9�€BÜ�;Š;˜˜˜R�y bÔ)×1Ñ1°"Ó5Ð5r   c                óŽ  € VP                  V4      pVP                  V4      pVRRVP                  R,          ^,          13,          P                  ^RR7      pVRRVP                  R,          ^,          13,          P                  ^RR7      pVP                  R,          pV RRV13,          V RVR13,          rvVRRV13,          VRVR13,          r˜Wb,          \        V4      V,          ,           p
W‚,          \        V4      V,          ,           p\        P
                  ! W§.RR7      p
\        P
                  ! W¹.RR7      pW«3# )aI  Applies Rotary Position Embedding to the query and key tensors.

Args:
    q (`torch.Tensor`): The query tensor.
    k (`torch.Tensor`): The key tensor.
    cos (`torch.Tensor`): The cosine part of the rotary embedding.
    sin (`torch.Tensor`): The sine part of the rotary embedding.
    unsqueeze_dim (`int`, *optional*, defaults to 1):
        The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
        sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
        that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
        k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
        cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
        the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
Returns:
    `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
.Nr>   r@   )Ú	unsqueezeÚshapeÚrepeat_interleaverG   r   Úcat)ÚqÚkÚcosÚsinÚunsqueeze_dimÚ
rotary_dimÚq_rotÚq_passÚk_rotÚk_passÚq_embedÚk_embeds   &&&&&       r   Úapply_rotary_pos_embrY   F   s6  € ð$ �-‰-˜Ó
&€CØ
�-‰-˜Ó
&€Cð ˆcÐ'�S—Y‘Y˜r•] aÕ'Ð'Ð'Õ
(×
:Ñ
:¸1À"Ð
:Ó
E€CØ
ˆcÐ'�S—Y‘Y˜r•] aÕ'Ð'Ð'Õ
(×
:Ñ
:¸1À"Ð
:Ó
E€Cð —‘˜2•€JØ�c˜;˜J˜;Ð&Õ'¨¨3°
±Ð+;Õ)<ˆ6Ø�c˜;˜J˜;Ð&Õ'¨¨3°
±Ð+;Õ)<ˆ6ð �{œ{¨5Ó1°CÕ7Õ8€GØ�{œ{¨5Ó1°CÕ7Õ8€Gô �iŠi˜Ð)¨rÔ2€GÜ�iŠi˜Ð)¨rÔ2€GØÐÐr   c                   óB   a a€ ] tR t^nt oRV3R lV 3R llltRtVtV ;t# )ÚGlmAttentionc                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# )r   r   Ú	layer_idxN)r   r0   )r"   r#   s   "€r   r$   ÚGlmAttention.__annotate__p   s#   ø€ ÷ lñ l™yð l±S¸4µZñ lr   c                ó¬   <€ \         SV `  W4       \        P                  ! VP                  V P
                  ,          VP                  R R7      V n        R# )F)ÚbiasN)ÚsuperÚ__init__ÚnnÚLinearr/   r)   r.   Úo_proj)Úselfr   r]   Ú	__class__s   &&&€r   rb   ÚGlmAttention.__init__p   s:   ø€ Ü‰Ñ˜Ô+Ü—i’i × :Ñ :¸T¿]¹]Õ JÈF×L^ÑL^ÐejÔkˆŽr   )re   r;   )r   r   r   r   rb   r   r<   Ú__classcell__)rg   r#   s   @@r   r[   r[   n   s   ù‡ € ÷l÷ lõ lr   r[   c                   ó   € ] tR t^utRtR# )ÚGlmForCausalLMr   Nr   r   r   r   rk   rk   u   r   r   rk   c                   ó   € ] tR t^ytRtR# )ÚGlmForSequenceClassificationr   Nr   r   r   r   rm   rm   y   r   r   rm   c                   ó   € ] tR t^}tRtR# )ÚGlmForTokenClassificationr   Nr   r   r   r   ro   ro   }   r   r   ro   )r?   )ÚGlmPreTrainedModelÚGlmModelrk   rm   ro   )r   Útorch.nnrc   Úutilsr   Úutils.genericr   Úllama.modeling_llamar   r   r   r   r	   Úphi3.modeling_phi3r
   Úconfiguration_glmr   Ú
get_loggerr   ÚloggerÚ_CHECKPOINT_FOR_DOCr   r   rG   rY   r[   rk   rm   ro   Ú__all__r   r   r   Ú<module>r|      s­   ðó  Ý å Ý 1÷õ õ )Ý (ð 
×	Ò	˜HÓ	%€à&Ð ô	ˆWô 	ô5Ð-ô 5ò,6ô%ðP ôl�>ó ló ðlô	Ð%ô 	ô	Ð#Aô 	ô	Ð ;ô 	ò‚r   