+
    œ°³j*  ã                   óR  € 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 ^RIHt ^R	IHt ^R
IHtHtHtHtHtHtHt ^RIHt ]P8                  ! ]4      t ! R R]4      t ! R R]4      t  ! R R]4      t! ! R R]4      t" ! R R]4      t# ! R R]4      t$. ROt%R# )zPyTorch BitNet model.)ÚCallableN)ÚCache)ÚFlashAttentionKwargs©ÚCausalLMOutputWithPast)ÚALL_ATTENTION_FUNCTIONS)ÚUnpack)Úlogging)ÚGemmaMLP)ÚLlamaAttentionÚLlamaDecoderLayerÚLlamaForCausalLMÚ
LlamaModelÚLlamaRMSNormÚapply_rotary_pos_embÚeager_attention_forward©ÚBitNetConfigc                   ó   € ] tR t^)tRtR# )ÚBitNetRMSNorm© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    Új/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/bitnet/modular_bitnet.pyr   r   )   ó   † Ûr   r   c                   óD   a a€ ] tR t^-t oV3R lV 3R lltR tRtVtV ;t# )Ú	BitNetMLPc                ó    <€ V ^8„  d   QhRS[ /# )é   Úconfigr   )ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚBitNetMLP.__annotate__.   s   ø€ ÷ ]ñ ]™|ñ ]r   c                ór   <€ \         SV `  V4       \        VP                  VP                  R 7      V n        R# ©)ÚepsN)ÚsuperÚ__init__r   Úintermediate_sizeÚrms_norm_epsÚffn_sub_norm)Úselfr$   Ú	__class__s   &&€r   r-   ÚBitNetMLP.__init__.   s+   ø€ Ü‰Ñ˜Ô Ü)¨&×*BÑ*BÈ×H[ÑH[Ô\ˆÖr   c           	     ó®   € V P                  V P                  V P                  V P                  V4      4      V P	                  V4      ,          4      4      pV# ©N)Ú	down_projr0   Úact_fnÚ	gate_projÚup_proj)r1   Úxr6   s   && r   ÚforwardÚBitNetMLP.forward2   sF   € Ø—N‘N 4×#4Ñ#4°T·[±[ÀÇÁÐPQÓARÓ5SÐVZ×VbÑVbÐcdÓVeÕ5eÓ#fÓgˆ	ØÐr   )r0   ©	r   r   r   r   r-   r;   r   Ú__classdictcell__Ú__classcell__©r2   r&   s   @@r   r!   r!   -   s   ù‡ € ÷]ó ]÷ò r   r!   c                   óT   a a€ ] tR t^7t 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# )ÚBitNetAttentionc                ó&   <€ V ^8„  d   QhRS[ RS[/# )r#   r$   Ú	layer_idx)r   Úint)r%   r&   s   "€r   r'   ÚBitNetAttention.__annotate__8   s   ø€ ÷ Xñ X™|ð X¹ñ Xr   c                ór   <€ \         SV `  W4       \        VP                  VP                  R 7      V n        R# r*   )r,   r-   r   Úhidden_sizer/   Úattn_sub_norm)r1   r$   rD   r2   s   &&&€r   r-   ÚBitNetAttention.__init__8   s+   ø€ Ü‰Ñ˜Ô+Ü*¨6×+=Ñ+=À6×CVÑCVÔWˆÖ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,          /# )r#   Úhidden_statesÚposition_embeddingsÚattention_maskNÚpast_key_valuesÚkwargsÚreturn)ÚtorchÚTensorÚtupler   r   r   )r%   r&   s   "€r   r'   rF   <   s‡   ø€ ÷ ')ñ ')á—|‘|ð')ñ #¡5§<¡<±·±Ð#=Õ>ð')ñ Ÿ™ tÕ+ð	')ñ
  �ð')ñ Ñ-Õ.ð')ñ 
‰u�|‰|™UŸ\™\¨DÕ0Ð0Õ	1ñ')r   c                ó2  € VP                   R R p. VORNV P                  N5pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      p	V P                  V4      P                  V4      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V P+                  V4      pWï3# )NÚdropoutg        Úscalingéÿÿÿÿ)ÚshapeÚhead_dimÚq_projÚviewÚ	transposeÚk_projÚv_projr   ÚupdaterD   r   Úget_interfacer$   Ú_attn_implementationr   ÚtrainingÚattention_dropoutrW   ÚreshapeÚ
contiguousrI   Úo_proj)r1   rL   rM   rN   rO   rP   Úinput_shapeÚhidden_shapeÚquery_statesÚ
key_statesÚvalue_statesÚcosÚsinÚattention_interfaceÚattn_outputÚattn_weightss   &&&&&,          r   r;   ÚBitNetAttention.forward<   s—  € ð $×)Ñ)¨#¨2Ð.ˆØ8˜Ð8 bÐ8¨$¯-©-Ñ8ˆà—{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆØ—[‘[ Ó/×4Ñ4°\ÓB×LÑLÈQÐPQÓRˆ
Ø—{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆà&‰ˆÜ#7¸ÐRUÓ#[Ñ ˆàÒ&Ø'6×'=Ñ'=¸jÐX\×XfÑXfÓ'gÑ$ˆJä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØñ	%
ð  $Ÿ}Ÿ}˜}‘C°$×2HÑ2Hð	%
ð —L‘Lð	%
ð ñ	%
Ñ!ˆð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØ×(Ñ(¨Ó5ˆØ—k‘k +Ó.ˆØÐ(Ð(r   )rI   r5   r=   r@   s   @@r   rB   rB   7   s    ù‡ € ÷Xó X÷')÷ ')ò ')r   rB   c                   ó   € ] tR t^ftRtR# )ÚBitNetDecoderLayerr   Nr   r   r   r   rt   rt   f   r   r   rt   c                   ó   € ] tR t^jtRtR# )ÚBitNetModelr   Nr   r   r   r   rv   rv   j   r   r   rv   c                   óN   a a€ ] tR t^nt oRR/tRtRtV3R lV 3R lltRtVt	V ;t
# )ÚBitNetForCausalLMzlm_head.weightzmodel.embed_tokens.weightNc                ó    <€ V ^8„  d   QhRS[ /# )r#   rQ   r   )r%   r&   s   "€r   r'   ÚBitNetForCausalLM.__annotate__s   s   ø€ ÷ /ñ /ñ 
 ñ/r   c                ó$   <€ \         SV `  ! R/ VB # )a¤  
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the masked language modeling loss. Indices should either be in `[0, transformers.,
    config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
    (masked), the loss is only computed for the tokens with labels in `[0, transformers., config.vocab_size]`.

Example:

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

>>> model = BitNetForCausalLM.from_pretrained("microsoft/bitnet-b1.58-2B-4T")
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/bitnet-b1.58-2B-4T")

>>> prompt = f'<|begin_of_text|>User: Hey, are you conscious? Can you talk to me?<|eot_id|>Assistant: '
>>> inputs = tokenizer(prompt, return_tensors="pt")

>>> # Generate
>>> generate_ids = model.generate(inputs.input_ids, max_length=100)
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
"User: Hey, are you conscious? Can you talk to me?Assistant: No, I'm not conscious. I'm an artificial intelligence designed to assist with information and tasks. How can I help you today?"
```r   )r,   r;   )r1   Úsuper_kwargsr2   s   &,€r   r;   ÚBitNetForCausalLM.forwards   s   ø€ ô4 ‰wŠÑ. Ñ.Ð.r   r   )r   r   r   r   Ú_tied_weights_keysÚ_tp_planÚ_pp_planr;   r   r>   r?   r@   s   @@r   rx   rx   n   s*   ù‡ € Ø*Ð,GÐHÐØ€HØ€H÷/÷ /ó /r   rx   )rx   rv   ÚBitNetPreTrainedModel)&Ú__doc__Úcollections.abcr   rR   Úcache_utilsr   Úmodeling_flash_attention_utilsr   Úmodeling_outputsr   Úmodeling_utilsr   Úprocessing_utilsr   Úutilsr	   Úgemma.modeling_gemmar
   Úllama.modeling_llamar   r   r   r   r   r   r   Úconfiguration_bitnetr   Ú
get_loggerr   Úloggerr   r!   rB   rt   rv   rx   Ú__all__r   r   r   Ú<module>r�      sž   ðñ å $ã å  Ý BÝ 6Ý 5Ý &Ý Ý +÷÷ ñ õ /ð 
×	Ò	˜HÓ	%€ô	�Lô 	ô�ô ô,)�nô ,)ô^	Ð*ô 	ô	�*ô 	ô/Ð(ô /òD‚r   