+
    œ°³jš6  ã                   óÊ  € R t ^ RIHt ^ RIt^ RIHt ^RIHt ^RIHt ^RI	H
t
 ^RIHtHt ^RIHt ^R	IHt ^R
IHt ^RIHtHtHtHt ^RIHtHt ^RIHtHtHtH t H!t!H"t" ^RI#H$t$ ]PJ                  ! ]&4      t' ! R R]PP                  4      t) ! R R]!4      t*R t+RR lt, ! R R]4      t-] ! R R]4      4       t. ! R R]
4      t/ ! R R] 4      t0 ! R R]4      t1. R Ot2R# )!zPyTorch Cohere model.)ÚCallableN)Únn)ÚCache)ÚFlashAttentionKwargs)ÚGradientCheckpointingLayer)ÚBaseModelOutputWithPastÚCausalLMOutputWithPast)Údynamic_rope_update)ÚALL_ATTENTION_FUNCTIONS)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚlogging)Úmaybe_autocastÚno_inherit_decorator)ÚLlamaAttentionÚLlamaForCausalLMÚLlamaMLPÚ
LlamaModelÚLlamaRotaryEmbeddingÚeager_attention_forward©ÚCohereConfigc                   ó<   a a€ ] tR t^4t oRV 3R lltR tRtVtV ;t# )ÚCohereLayerNormc                óŽ   <€ \         SV `  4        \        P                  ! \        P
                  ! V4      4      V n        W n        R# )zcThe hidden size can be a tuple or an int. The tuple is used for QKNorm to normalize across head_dimN)ÚsuperÚ__init__r   Ú	ParameterÚtorchÚonesÚweightÚvariance_epsilon)ÚselfÚhidden_sizeÚepsÚbiasÚ	__class__s   &&&&€Új/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/cohere/modular_cohere.pyr   ÚCohereLayerNorm.__init__5   s-   ø€ ä‰ÑÔÜ—l’l¤5§:¢:¨kÓ#:Ó;ˆŒØ #Öó    c                ó¶  € VP                   pVP                  \        P                  4      pVP	                  RRR7      pW,
          P                  ^4      P	                  RRR7      pW,
          \        P                  ! W@P                  ,           4      ,          pV P                  P                  \        P                  4      V,          pVP                  V4      # )é   T)Úkeepdiméÿÿÿÿ)	ÚdtypeÚtor    Úfloat32ÚmeanÚpowÚrsqrtr#   r"   )r$   Úhidden_statesÚinput_dtyper3   Úvariances   &&   r)   ÚforwardÚCohereLayerNorm.forward;   s¤   € Ø#×)Ñ)ˆØ%×(Ñ(¬¯©Ó7ˆØ×!Ñ! "¨dÐ!Ó3ˆØ!Õ(×-Ñ-¨aÓ0×5Ñ5°bÀ$Ð5ÓGˆØ&Õ-´·²¸X×H]ÑH]Õ=]Ó1^Õ^ˆØŸ™Ÿ™¤u§}¡}Ó5¸ÕEˆØ×Ñ Ó,Ð,r+   )r#   r"   )Ngñhãˆµøä>F©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r9   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r(   Ú__classdict__s   @@r)   r   r   4   s   ù‡ € ÷$÷-ò -r+   r   c                   óX   a € ] tR t^Et o ]P
                  ! 4       ]R 4       4       tRtV t	R# )ÚCohereRotaryEmbeddingc                ób  € V P                   R,          P                  4       P                  VP                  ^ ,          R^4      pVR	,          P                  4       p\	        VP
                  P                  \        4      '       d2   VP
                  P                  R8w  d   VP
                  P                  MRp\        VRR7      ;_uu_ 4        VP                  4       VP                  4       ,          P                  ^^4      p\        P                  ! V^RR7      pVP                  4       V P                  ,          pVP                  4       V P                  ,          p	R R R 4       XP                  VP                   R7      X	P                  VP                   R7      3#   + '       g   i     LH; i)
NÚmpsÚcpuF)Údevice_typeÚenabled©Údim©r0   )NºNNNNr/   )rO   NrO   )Úinv_freqÚfloatÚexpandÚshapeÚ
isinstanceÚdeviceÚtypeÚstrr   Ú	transposer    Úrepeat_interleaveÚcosÚattention_scalingÚsinr1   r0   )
r$   ÚxÚposition_idsÚinv_freq_expandedÚposition_ids_expandedrJ   ÚfreqsÚembrZ   r\   s
   &&&       r)   r9   ÚCohereRotaryEmbedding.forwardF   s5  € ð !ŸM™M¨-Õ8×>Ñ>Ó@×GÑGÈ×HZÑHZÐ[\ÕH]Ð_aÐcdÓeÐØ ,¨ZÕ 8× >Ñ >Ó @Ðä'1°!·(±(·-±-Ä×'EÒ'EÈ!Ï(É(Ï-É-Ð[`ÔJ`�a—h‘h—m’mÐfkˆÜ¨¸U×CÖCØ&×,Ñ,Ó.Ð1F×1LÑ1LÓ1NÕN×YÑYÐZ[Ð]^Ó_ˆEÜ×)Ò)¨%°¸Ô;ˆCØ—'‘'“)˜d×4Ñ4Õ4ˆCØ—'‘'“)˜d×4Ñ4Õ4ˆC÷	 Dð �v‰v˜AŸG™GˆvÓ$ c§f¡f°1·7±7 fÓ&;Ð;Ð;÷ D×Cús   ÃBFÆF.	© N)
r<   r=   r>   r?   r    Úno_gradr	   r9   r@   rA   )rD   s   @r)   rF   rF   E   s%   ø‡ € Ø
‡]‚]ƒ_Øñ<ó ó ö<r+   rF   c                 ó~   € V R,          pV R,          p\         P                  ! V) V.RR7      P                  R4      pV# ).rL   ).:NNé   ).:r-   Nrg   r/   éþÿÿÿ)r    ÚstackÚflatten)r]   Úx1Úx2Úrot_xs   &   r)   Úrotate_halfrn   V   s:   € à	
ˆ8�€BØ	
ˆ9�€BÜ�KŠK˜"˜˜b˜	 rÔ*×2Ñ2°2Ó6€EØ€Lr+   c                ób  € V P                   pV P                  4       p VP                  4       pVP                  V4      pVP                  V4      pW,          \        V 4      V,          ,           pW,          \        V4      V,          ,           pVP	                  VR7      VP	                  VR7      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.
rN   )r0   rQ   Ú	unsqueezern   r1   )ÚqÚkrZ   r\   Úunsqueeze_dimr0   Úq_embedÚk_embeds   &&&&&   r)   Úapply_rotary_pos_embrv   ^   sŠ   € ð$ �G‰G€EØ	�‰‹	€AØ	�‰‹	€AØ
�-‰-˜Ó
&€CØ
�-‰-˜Ó
&€CØ�wœ; q›>¨CÕ/Õ0€GØ�wœ; q›>¨CÕ/Õ0€GØ�:‰:˜Eˆ:Ó" G§J¡J°U JÓ$;Ð;Ð;r+   c                   ó2   a a€ ] tR t^zt oV 3R ltRtVtV ;t# )Ú	CohereMLPc                óR  <€ \         SV `  V4       \        P                  ! V P                  V P
                  R R7      V n        \        P                  ! V P                  V P
                  R R7      V n        \        P                  ! V P
                  V P                  R R7      V n        R# )F)r'   N)	r   r   r   ÚLinearr%   Úintermediate_sizeÚ	gate_projÚup_projÚ	down_proj©r$   Úconfigr(   s   &&€r)   r   ÚCohereMLP.__init__{   ss   ø€ Ü‰Ñ˜Ô ÜŸš 4×#3Ñ#3°T×5KÑ5KÐRWÔXˆŒÜ—y’y ×!1Ñ!1°4×3IÑ3IÐPUÔVˆŒÜŸš 4×#9Ñ#9¸4×;KÑ;KÐRWÔXˆŽr+   )r~   r|   r}   ©r<   r=   r>   r?   r   r@   rA   rB   rC   s   @@r)   rx   rx   z   s   ù‡ € ÷Yõ Yr+   rx   c                   ó\   a a€ ] tR t^‚t oRtRV3R lV 3R llltRV3R lR lltRtVtV ;t	# )ÚCohereAttentionz=Multi-headed attention from 'Attention Is All You Need' paperc                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# )rg   r€   Ú	layer_idxN©r   Úint)ÚformatrD   s   "€r)   Ú__annotate__ÚCohereAttention.__annotate__†   s   ø€ ÷ 
ñ 
™|ð 
¹¸d½
ñ 
r+   c                ó8  <€ \         SV `  W4       VP                  V n        V P                  '       dg   \        VP                  V P
                  3VP                  R 7      V n        \        VP                  V P
                  3VP                  R 7      V n	        R# R# ©©r%   r&   N)
r   r   Úuse_qk_normr   Únum_attention_headsÚhead_dimÚlayer_norm_epsÚq_normÚnum_key_value_headsÚk_norm©r$   r€   r†   r(   s   &&&€r)   r   ÚCohereAttention.__init__†   s}   ø€ Ü‰Ñ˜Ô+Ø!×-Ñ-ˆÔØ××Ðä)Ø#×7Ñ7¸¿¹ÐGÈV×MbÑMbôˆDŒKô *Ø#×7Ñ7¸¿¹ÐGÈV×MbÑMbôˆDŽKñ r+   c                ó  <€ V ^8„  d   QhRS[ P                  RS[S[ P                  S[ P                  3,          RS[ P                  R,          RS[R,          RS[S[,          RS[S[ P                  S[ P                  R,          3,          /# )rg   r6   Úposition_embeddingsÚattention_maskNÚpast_key_valuesÚkwargsÚreturn)r    ÚTensorÚtupler   r   r   )r‰   rD   s   "€r)   rŠ   r‹   ’   s‡   ø€ ÷ .)ñ .)á—|‘|ð.)ñ #¡5§<¡<±·±Ð#=Õ>ð.)ñ Ÿ™ tÕ+ð	.)ñ
  �ð.)ñ Ñ-Õ.ð.)ñ 
‰u�|‰|™UŸ\™\¨DÕ0Ð0Õ	1ñ.)r+   c                ó„  € VP                   R R p. VORNV P                  N5pV P                  V4      P                  V4      pV P	                  V4      P                  V4      p	V P                  V4      P                  V4      p
V P                  '       d#   V P                  V4      pV P                  V	4      p	VP                  ^^4      pV	P                  ^^4      p	V
P                  ^^4      p
Vw  r¼\        W‰W¼4      w  r‰Ve   VP                  WšV P                  4      w  rš\        P                  ! V P                  P                   \"        4      pT! V VV	V
V3RV P$                  '       g   RMV P&                  RV P(                  /VB w  rïVP*                  ! . VORN5!  P-                  4       pV P/                  V4      pWï3# )NÚdropoutg        Úscalingr/   )rS   r‘   Úq_projÚviewÚk_projÚv_projr�   r“   r•   rX   rv   Úupdater†   r
   Úget_interfacer€   Ú_attn_implementationr   ÚtrainingÚattention_dropoutr¢   ÚreshapeÚ
contiguousÚo_proj)r$   r6   r™   rš   r›   rœ   Úinput_shapeÚhidden_shapeÚquery_statesÚ
key_statesÚvalue_statesrZ   r\   Úattention_interfaceÚattn_outputÚattn_weightss   &&&&&,          r)   r9   ÚCohereAttention.forward’   s»  € ð $×)Ñ)¨#¨2Ð.ˆØ8˜Ð8 bÐ8¨$¯-©-Ñ8ˆà—{‘{ =Ó1×6Ñ6°|ÓDˆØ—[‘[ Ó/×4Ñ4°\ÓBˆ
Ø—{‘{ =Ó1×6Ñ6°|ÓDˆà××ÐØŸ;™; |Ó4ˆLØŸ™ ZÓ0ˆJà#×-Ñ-¨a°Ó3ˆØ×)Ñ)¨!¨QÓ/ˆ
Ø#×-Ñ-¨a°Ó3ˆà&‰ˆÜ#7¸ÐRUÓ#[Ñ ˆàÒ&Ø'6×'=Ñ'=¸jÐX\×XfÑXfÓ'gÑ$ˆJä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØñ	%
ð  $Ÿ}Ÿ}˜}‘C°$×2HÑ2Hð	%
ð —L‘Lð	%
ð ñ	%
Ñ!ˆð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØ—k‘k +Ó.ˆØÐ(Ð(r+   )r•   r“   r�   ©N)
r<   r=   r>   r?   Ú__doc__r   r9   r@   rA   rB   rC   s   @@r)   r„   r„   ‚   s!   ù‡ € áG÷
õ 
÷.)÷ .)ò .)r+   r„   c                   óT   a a€ ] tR t^Ãt oV3R lV 3R lltRV3R lR lltRtVtV ;t# )ÚCohereDecoderLayerc                ó&   <€ V ^8„  d   QhRS[ RS[/# )rg   r€   r†   r‡   )r‰   rD   s   "€r)   rŠ   ÚCohereDecoderLayer.__annotate__Ä   s   ø€ ÷ lñ l™|ð l¹ñ lr+   c                óÔ   <€ \         SV `  4        VP                  V n        \        WR 7      V n        \        V4      V n        \        VP                  VP                  R7      V n	        R# ))r€   r†   rŽ   N)
r   r   r%   r„   Ú	self_attnrx   Úmlpr   r’   Úinput_layernormr–   s   &&&€r)   r   ÚCohereDecoderLayer.__init__Ä   sP   ø€ Ü‰ÑÔØ!×-Ñ-ˆÔÜ(°ÔLˆŒÜ˜VÓ$ˆŒÜ.¸F×<NÑ<NÐU[×UjÑUjÔkˆÖr+   c                ó.  <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[S[ P                  S[ P                  3,          R,          RS[S[,          R	S[ P                  /# )
rg   r6   rš   Nr^   r›   Ú	use_cacher™   rœ   r�   )r    rž   Ú
LongTensorr   ÚboolrŸ   r   r   )r‰   rD   s   "€r)   rŠ   r½   Ë   sœ   ø€ ÷ *ñ *á—|‘|ð*ñ Ÿ™ tÕ+ð*ñ ×&Ñ&¨Õ-ð	*ñ
  �ð*ñ ˜$•;ð*ñ #¡5§<¡<±·±Ð#=Õ>ÀÕEð*ñ Ñ-Õ.ð*ñ 
�‰ñ*r+   c                ó¬   € TpV P                  V4      pV P                  ! RRVRVRVRVRVRV/VB w  ršV P                  V4      pW‰,           V,           pV# )a<  
Args:
    hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
    attention_mask (`torch.FloatTensor`, *optional*):
        attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
        query_sequence_length, key_sequence_length)` if default attention is used.
    past_key_values (`Cache`, *optional*): cached past key and value projection states
    output_attentions (`bool`, *optional*):
        Whether or not to return the attentions tensors of all attention layers. See `attentions` under
        returned tensors for more detail.
    use_cache (`bool`, *optional*):
        If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
        (see `past_key_values`).
    position_embeddings (`tuple[torch.FloatTensor, torch.FloatTensor]`, *optional*):
        Tuple containing the cosine and sine positional embeddings of shape `(batch_size, seq_len, head_dim)`,
        with `head_dim` being the embedding dimension of each attention head.
r6   rš   r^   r›   rÄ   r™   rd   )rÁ   r¿   rÀ   )r$   r6   rš   r^   r›   rÄ   r™   rœ   ÚresidualÚhidden_states_attentionÚ_Úhidden_states_mlps   &&&&&&&,    r)   r9   ÚCohereDecoderLayer.forwardË   s’   € ð6 !ˆØ×,Ñ,¨]Ó;ˆà%)§^¢^ñ &
Ø'ð&
à)ð&
ð &ð&
ð ,ð	&
ð
  ð&
ð !4ð&
ð ñ&
Ñ"Ðð !ŸH™H ]Ó3ÐØ Õ:Ð=NÕNˆØÐr+   )r%   rÁ   rÀ   r¿   )NNNFNr;   rC   s   @@r)   r»   r»   Ã   s    ù‡ € ÷ló l÷*÷ *ò *r+   r»   c                   ó>   a a€ ] tR t^øt oV3R lV 3R lltRtVtV ;t# )ÚCohereModelc                ó    <€ V ^8„  d   QhRS[ /# )rg   r€   r   )r‰   rD   s   "€r)   rŠ   ÚCohereModel.__annotate__ù   s   ø€ ÷ añ a™|ñ ar+   c           	     ó
  <€ \         SV `  V4       \        P                  ! \	        VP
                  4       Uu. uF  p\        W4      NK  	  up4      V n        \        VP                  VP                  R 7      V n        R# u upi r�   )r   r   r   Ú
ModuleListÚrangeÚnum_hidden_layersr»   Úlayersr   r%   r’   Únormr–   s   && €r)   r   ÚCohereModel.__init__ù   sg   ø€ Ü‰Ñ˜Ô Ü—m’mÜDIÈ&×JbÑJbÔDcÓdÑDc°yÔ Ö2ÑDcÑdó
ˆŒô $°×1CÑ1CÈ&×J_ÑJ_Ô`ˆŽ	ùò es   ¸B )rÕ   rÖ   r‚   rC   s   @@r)   rÎ   rÎ   ø   s   ù‡ € ÷a÷ aó ar+   rÎ   c                   ó\   a a€ ] tR tRt oV 3R lt]]RV3R lR ll4       4       tRtVt	V ;t
# )ÚCohereForCausalLMi  c                óŠ   <€ \         SV `  V4       \        V4      V n        VP                  V n        VP
                  V n        R # r¸   )r   r   rÎ   ÚmodelÚlogit_scaleÚtie_word_embeddingsr   s   &&€r)   r   ÚCohereForCausalLM.__init__  s8   ø€ Ü‰Ñ˜Ô Ü  Ó(ˆŒ
Ø!×-Ñ-ˆÔØ#)×#=Ñ#=ˆÖ r+   c                óP  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[ P                  R,          RS[ P                  R,          RS[R,          R	S[S[ P                  ,          R
S[S[,          RS[	/
# )rg   Ú	input_idsNrš   r^   r›   Úinputs_embedsÚlabelsrÄ   Úlogits_to_keeprœ   r�   )
r    rÅ   rž   r   ÚFloatTensorrÆ   rˆ   r   r   r   )r‰   rD   s   "€r)   rŠ   ÚCohereForCausalLM.__annotate__
  s»   ø€ ÷ 6
ñ 6
á×#Ñ# dÕ*ð6
ñ Ÿ™ tÕ+ð6
ñ ×&Ñ&¨Õ-ð	6
ñ
  �ð6
ñ ×(Ñ(¨4Õ/ð6
ñ × Ñ  4Õ'ð6
ñ ˜$•;ð6
ñ ™eŸl™lÕ*ð6
ñ Ñ+Õ,ð6
ñ 
 ñ6
r+   c	                óº  € V P                   ! RRVRVRVRVRVRV/V	B p
V
P                  p\        V\        4      '       d   \	        V) R4      MTpV P                  VRVR3,          4      pWÐP                  ,          pRpVe-   V P                  ! RR	VR
VRV P                  P                  /V	B p\        VVV
P                  V
P                  V
P                  R7      # )au  
Example:

```python
>> from transformers import AutoTokenizer, CohereForCausalLM

>> model = CohereForCausalLM.from_pretrained("CohereForAI/c4ai-command-r-v01")
>> tokenizer = AutoTokenizer.from_pretrained("CohereForAI/c4ai-command-r-v01")

>> prompt = "Hey, are you conscious? Can you talk to me?"
>> inputs = tokenizer(prompt, return_tensors="pt")

>> # Generate
>> generate_ids = model.generate(inputs.input_ids, max_length=30)
>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
```rà   rš   r^   r›   rá   rÄ   NrO   Úlogitsrâ   Ú
vocab_size)Úlossrç   r›   r6   Ú
attentionsrd   )rÛ   Úlast_hidden_staterT   rˆ   ÚsliceÚlm_headrÜ   Úloss_functionr€   rè   r   r›   r6   rê   )r$   rà   rš   r^   r›   rá   râ   rÄ   rã   rœ   Úoutputsr6   Úslice_indicesrç   ré   s   &&&&&&&&&,     r)   r9   ÚCohereForCausalLM.forward  s  € ð> ,0¯:ª:ñ ,
Øð,
à)ð,
ð &ð,
ð ,ð	,
ð
 (ð,
ð  ð,
ð ñ,
ˆð  ×1Ñ1ˆÜ8BÀ>ÔSV×8WÒ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜m¨A¨}¸aÐ,?Õ@ÓAˆØ×*Ñ*Õ*ˆàˆØÒØ×%Ò%Ñp¨VÐp¸FÐpÈtÏ{É{×OeÑOeÐpÐioÑpˆDä%ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r+   )rÜ   rÛ   rÝ   )NNNNNNNé    )r<   r=   r>   r?   r   r   r   r9   r@   rA   rB   rC   s   @@r)   rÙ   rÙ     s0   ù‡ € õ>ð Ø÷6
ñ 6
ó ó ÷6
ð 6
r+   rÙ   )r-   )rÙ   rÎ   ÚCoherePreTrainedModel)3r¹   Úcollections.abcr   r    r   Úcache_utilsr   Úmodeling_flash_attention_utilsr   Úmodeling_layersr   Úmodeling_outputsr   r   Úmodeling_rope_utilsr	   Úmodeling_utilsr
   Úprocessing_utilsr   Úutilsr   r   r   r   Úutils.genericr   r   Úllama.modeling_llamar   r   r   r   r   r   Úconfiguration_coherer   Ú
get_loggerr<   ÚloggerÚModuler   rF   rn   rv   rx   r„   r»   rÎ   rÙ   Ú__all__rd   r+   r)   Ú<module>r     sÔ   ðñ, å $ã Ý å  Ý BÝ 9ß OÝ 6Ý 5Ý &ß RÓ Rß A÷÷ õ /ð 
×	Ò	˜HÓ	%€ô-�b—i‘iô -ô"<Ð0ô <ò"ô<ô8Y�ô Yð ô=)�nó =)ó ð=)ô@2Ð3ô 2ôja�*ô aô?
Ð(ô ?
òD‚r+   