+
    ÆÜ³jæ¬  ã                   ó  € ^ RI t ^ RIt^ RIHtHtHtHtHt ^ RIt^ RIH	t	H
t
HtHt ^ RIHu Ht ^ RIt^ RIHtHtHtHt ^ RIHt ^ RIHtHt ]P8                  ! ]4      t]! RRR	7      t ! R
 R]P                  P@                  4      t! ! R R]P                  P@                  4      t  ! R R]P                  PD                  4      t#R R lt$ ! R R]PJ                  4      t& ! R R]&4      t' ! R R]&4      t( ! R R]P                  PD                  4      t)R t* ! R R]P@                  4      t+ ! R R]P@                  4      t, ! R R ],4      t- ! R! R"],4      t. ! R# R$]PJ                  4      t/ ! R% R&]PJ                  4      t0R# )'é    N)ÚAnyÚOptionalÚTypeVarÚUnionÚoverload)ÚTensorÚdeviceÚdtypeÚnn)Ú
QuantStateÚ_convert_weight_packed_for_cpuÚ&_convert_weight_packed_for_cpu_inverseÚhas_avx512bf16)ÚGlobalOptimManager)Ú*INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPINGÚOutlierTracerÚTztorch.nn.Module)Úboundc                   ó~   a a€ ] tR t^t oRtRV3R lV 3R llltV3R lR lt V3R lR ltV3R lR	 ltR
t	Vt
V ;t# )ÚStableEmbeddinga¾  
Custom embedding layer designed to improve stability during training for NLP tasks by using 32-bit optimizer states. It is designed to reduce gradient variations that can result from quantization. This embedding layer is initialized with Xavier uniform initialization followed by layer normalization.

Example:

```
# Initialize StableEmbedding layer with vocabulary size 1000, embedding dimension 300
embedding_layer = StableEmbedding(num_embeddings=1000, embedding_dim=300)

# Reset embedding parameters
embedding_layer.reset_parameters()

# Perform a forward pass with input tensor
input_tensor = torch.tensor([1, 2, 3])
output_embedding = embedding_layer(input_tensor)
```

Attributes:
    norm (`torch.nn.LayerNorm`): Layer normalization applied after the embedding.

Methods:
    reset_parameters(): Reset embedding parameters using Xavier uniform initialization.
    forward(input: Tensor) -> Tensor: Forward pass through the stable embedding layer.
c                ó~   <€ V ^8„  d   QhRS[ RS[ RS[S[ ,          RS[S[,          RS[RS[RS[RS[S[,          R	R
/	# )é   Únum_embeddingsÚembedding_dimÚpadding_idxÚmax_normÚ	norm_typeÚscale_grad_by_freqÚsparseÚ_weightÚreturnN)Úintr   ÚfloatÚboolr   )ÚformatÚ__classdict__s   "€ÚX/home/luca/screen-checking/.venv/lib/python3.14/site-packages/bitsandbytes/nn/modules.pyÚ__annotate__ÚStableEmbedding.__annotate__6   s}   ø€ ÷ -gñ -gáð-gñ ð-gñ ™c•]ð	-gñ
 ™5•/ð-gñ ð-gñ !ð-gñ ð-gñ ™&Õ!ð-gð 
ñ-gó    c                óÒ   <€ \         SV `  VVVVVVVVV	V
4
       \        P                  P	                  W)R7      V n        \        P                  ! 4       P                  V RR^ /4       R# ©aô  
Args:
    num_embeddings (`int`):
        The number of unique embeddings (vocabulary size).
    embedding_dim (`int`):
        The dimensionality of the embedding.
    padding_idx (`Optional[int]`):
        Pads the output with zeros at the given index.
    max_norm (`Optional[float]`):
        Renormalizes embeddings to have a maximum L2 norm.
    norm_type (`float`, defaults to `2.0`):
        The p-norm to compute for the `max_norm` option.
    scale_grad_by_freq (`bool`, defaults to `False`):
        Scale gradient by frequency during backpropagation.
    sparse (`bool`, defaults to `False`):
        Computes dense gradients. Set to `True` to compute sparse gradients instead.
    _weight (`Optional[Tensor]`):
        Pretrained embeddings.
©r	   ÚweightÚ
optim_bitsN)	ÚsuperÚ__init__Útorchr   Ú	LayerNormÚnormr   Úget_instanceÚregister_module_override)Úselfr   r   r   r   r   r   r   r    r	   r
   Ú	__class__s   &&&&&&&&&&&€r'   r1   ÚStableEmbedding.__init__6   sn   ø€ ô@ 	‰ÑØØØØØØØØØØô	
ô —H‘H×&Ñ& }Ð&ÓDˆŒ	Ü×'Ò'Ó)×BÑBÀ4ÈÐT`ÐbdÐSeÖfr*   c                ó   <€ V ^8„  d   QhRR/# ©r   r!   N© )r%   r&   s   "€r'   r(   r)   e   ó   ø€ ÷ +ñ + $ñ +r*   c                óŒ   € \         P                  P                  P                  V P                  4       V P                  4        R # ©N©r2   r   ÚinitÚxavier_uniform_r.   Ú_fill_padding_idx_with_zero©r7   s   &r'   Úreset_parametersÚ StableEmbedding.reset_parameterse   ó(   € Ü�‰�‰×%Ñ% d§k¡kÔ2Ø×(Ñ(Ö*r*   c                ó   <€ V ^8„  d   QhRR/# r;   r<   )r%   r&   s   "€r'   r(   r)   p   ó   ø€ ÷ 7ñ 7¨Tñ 7r*   c                óò   € V P                   eU   \        P                  ! 4       ;_uu_ 4        V P                  V P                   ,          P	                  ^ 4       R R R 4       R # R #   + '       g   i     R # ; ir?   ©r   r2   Úno_gradr.   Úfill_rD   s   &r'   rC   Ú+StableEmbedding._fill_padding_idx_with_zerop   óJ   € Ø×ÑÒ'Ü—’—•Ø—‘˜D×,Ñ,Õ-×3Ñ3°AÔ6÷ !‘ñ (ß —�úó   ¬-A%Á%A6	c                ó&   <€ V ^8„  d   QhRS[ RS[ /# ©r   Úinputr!   ©r   )r%   r&   s   "€r'   r(   r)   u   s   ø€ ÷ 4ñ 4™Vð 4©ñ 4r*   c           	     ób  € \         P                  ! VV P                  V P                  V P                  V P
                  V P                  V P                  4      pVP                  \        P                  ! 4       4      pV P                  V4      P                  V P                  P                  4      # r?   )ÚFÚ	embeddingr.   r   r   r   r   r   Útor2   Úget_default_dtyper4   r
   ©r7   rS   Úembs   && r'   ÚforwardÚStableEmbedding.forwardu   s}   € Ü�kŠkØØ�K‰KØ×ÑØ�M‰MØ�N‰NØ×#Ñ#Ø�K‰Kó
ˆð �f‰f”U×,Ò,Ó.Ó/ˆà�y‰y˜‹~× Ñ  §¡×!2Ñ!2Ó3Ð3r*   )r4   )NNç       @FFNNN©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r1   rE   rC   r\   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r8   r&   s   @@r'   r   r      s?   ù‡ € ñ÷2-gõ -g÷^+ð +ð÷7ð 7÷
4÷ 4ð 4r*   r   c                   ó~   a a€ ] tR t^†t oRtRV3R lV 3R llltV3R lR lt V3R lR ltV3R lR	 ltR
t	Vt
V ;t# )Ú	EmbeddingzK
Embedding class to store and retrieve word embeddings from their indices.
c                ó”   <€ V ^8„  d   QhRS[ RS[ RS[S[ ,          RS[S[,          RS[RS[RS[RS[S[,          R	S[S[,          R
R/
# )r   r   r   r   r   r   r   r   r    r	   r!   N)r"   r   r#   r$   r   r	   )r%   r&   s   "€r'   r(   ÚEmbedding.__annotate__‹   s�   ø€ ÷ *gñ *gáð*gñ ð*gñ ™c•]ð	*gñ
 ™5•/ð*gñ ð*gñ !ð*gñ ð*gñ ™&Õ!ð*gñ ™Õ ð*gð 
ñ*gr*   c
                óˆ   <€ \         S
V `  VVVVVVVVV	R7	       \        P                  ! 4       P	                  V RR^ /4       R# r,   )r0   r1   r   r5   r6   )r7   r   r   r   r   r   r   r   r    r	   r8   s   &&&&&&&&&&€r'   r1   ÚEmbedding.__init__‹   sV   ø€ ô> 	‰ÑØØØØØØØØØð 	ô 
	
ô 	×'Ò'Ó)×BÑBÀ4ÈÐT`ÐbdÐSeÖfr*   c                ó   <€ V ^8„  d   QhRR/# r;   r<   )r%   r&   s   "€r'   r(   rl   ·   r=   r*   c                óŒ   € \         P                  P                  P                  V P                  4       V P                  4        R # r?   r@   rD   s   &r'   rE   ÚEmbedding.reset_parameters·   rG   r*   c                ó   <€ V ^8„  d   QhRR/# r;   r<   )r%   r&   s   "€r'   r(   rl   Â   rI   r*   c                óò   € V P                   eU   \        P                  ! 4       ;_uu_ 4        V P                  V P                   ,          P	                  ^ 4       R R R 4       R # R #   + '       g   i     R # ; ir?   rK   rD   s   &r'   rC   Ú%Embedding._fill_padding_idx_with_zeroÂ   rO   rP   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# rR   rT   )r%   r&   s   "€r'   r(   rl   Ç   s   ø€ ÷ ñ ™Vð ©ñ r*   c           	     ó¶   € \         P                  ! VV P                  V P                  V P                  V P
                  V P                  V P                  4      pV# r?   )rV   rW   r.   r   r   r   r   r   rZ   s   && r'   r\   ÚEmbedding.forwardÇ   sH   € Ü�kŠkØØ�K‰KØ×ÑØ�M‰MØ�N‰NØ×#Ñ#Ø�K‰Kó
ˆð ˆ
r*   r<   )NNr^   FFNNr_   rh   s   @@r'   rj   rj   †   s?   ù‡ € ñ÷*gõ *g÷X+ð +ð÷7ð 7÷
÷ ð r*   rj   c            	       óø  a a€ ] tR t^Õt oRRRRRR]P
                  RR3	V3R lR lltR tR t]	R	 4       t
]	R
 4       t]	R 4       t]	R 4       t]	R 4       t]	R 4       t]	R 4       t]	R 4       t]	R 4       t]	R 4       tR tR t]R&V3R lR ll4       tR tR tR'V3R lR lltR'V3R lR llt]R(V3R lR ll4       t]R)V3R lR  ll4       t]R)V3R! lR" ll4       tV 3R# lt]R*V 3R$ ll4       tR%tVt V ;t!# )+Ú
Params4bitNFTÚfp4c                ó´   <€ V ^8„  d   QhRS[ S[P                  ,          RS[ S[,          RS[ S[,          RS[RS[RS[P                  RS[ R,          R	S[R
R/	# )r   ÚdataÚquant_stateÚ	blocksizeÚcompress_statisticsÚ
quant_typeÚquant_storageÚmoduleÚ
Linear4bitÚbnb_quantizedr!   ry   )r   r2   r   r   r"   r$   Ústrr
   )r%   r&   s   "€r'   r(   ÚParams4bit.__annotate__Ö   s€   ø€ ÷ ñ á‘u—|‘|Õ$ðñ ™jÕ)ð	ñ
 ™C•=ðñ "ðñ ðñ —{‘{ðñ ˜Õ&ðñ ðð 
ñr*   c
                óæ   € Vf   \         P                  ! ^ 4      pVf   ^@p\         P                  P                  WV4      pWKn        W[n        Wkn        W;n        W{n        W›n	        Wn
        W‹n        V# r?   )r2   Úemptyr   Ú_make_subclassr~   r   r€   r}   r�   r„   r|   r‚   )Úclsr|   Úrequires_gradr}   r~   r   r€   r�   r‚   r„   Úkwargsr7   s   &&&&&&&&&&, r'   Ú__new__ÚParams4bit.__new__Ö   sh   € ð Š<Ü—;’;˜q“>ˆDàÒØˆIä�|‰|×*Ñ*¨3°mÓDˆØ"ŒØ#6Ô Ø$ŒØ&ÔØ*ÔØ*ÔØŒ	ØŒØˆr*   c                óv   € V P                   P                  4       pV P                  VR &   V P                  VR&   V# )r|   r‹   )Ú__dict__Úcopyr|   r‹   ©r7   Ústates   & r'   Ú__getstate__ÚParams4bit.__getstate__ô   s6   € Ø—‘×"Ñ"Ó$ˆØŸ	™	ˆˆf‰Ø!%×!3Ñ!3ˆˆoÑØˆr*   c                ó  € VR ,          V n         VR,          V n        VR,          V n        VR,          V n        VR,          V n        VR,          V n        VR,          V n        VR,          V n        VR,          V n        R	# )
r‹   r~   r   r€   r}   r|   r�   r„   r‚   N)	r‹   r~   r   r€   r}   r|   r�   r„   r‚   r’   s   &&r'   Ú__setstate__ÚParams4bit.__setstate__ú   sr   € Ø" ?Õ3ˆÔØ˜{Õ+ˆŒØ#(Ð)>Õ#?ˆÔ Ø Õ-ˆŒØ  Õ/ˆÔØ˜&•MˆŒ	Ø" ?Õ3ˆÔØ" ?Õ3ˆÔØ˜H•oˆŽr*   c                óœ   € V P                   P                  R 4      pVe   VP                  # \        R\	        V 4      P
                   R24      h)r}   Ú'z"' object has no attribute 'absmax')r�   ÚgetÚabsmaxÚAttributeErrorÚtyper`   ©r7   Úqss   & r'   rœ   ÚParams4bit.absmax  óE   € à�]‰]×Ñ˜}Ó-ˆØŠ>Ø—9‘9ÐÜ˜q¤ d£×!4Ñ!4Ð 5Ð5WÐXÓYÐYr*   c                óœ   € V P                   P                  R 4      pVe   VP                  # \        R\	        V 4      P
                   R24      h)r}   rš   z ' object has no attribute 'code'©r�   r›   Úcoder�   rž   r`   rŸ   s   & r'   r¥   ÚParams4bit.code  sD   € à�]‰]×Ñ˜}Ó-ˆØŠ>Ø—7‘7ˆNÜ˜q¤ d£×!4Ñ!4Ð 5Ð5UÐVÓWÐWr*   c                óœ   € V P                   P                  R 4      pVe   VP                  # \        R\	        V 4      P
                   R24      h)r}   rš   z%' object has no attribute 'quant_map'r¤   rŸ   s   & r'   Ú	quant_mapÚParams4bit.quant_map  sD   € à�]‰]×Ñ˜}Ó-ˆØŠ>Ø—7‘7ˆNÜ˜q¤ d£×!4Ñ!4Ð 5Ð5ZÐ[Ó\Ð\r*   c                óœ   € V P                   P                  R 4      pVe   VP                  # \        R\	        V 4      P
                   R24      h)r}   rš   z"' object has no attribute 'offset'©r�   r›   Úoffsetr�   rž   r`   rŸ   s   & r'   r¬   ÚParams4bit.offset$  r¢   r*   c                óœ   € V P                   P                  R 4      pVe   VP                  # \        R\	        V 4      P
                   R24      h)r}   rš   z"' object has no attribute 'state2')r�   r›   Ústate2r�   rž   r`   rŸ   s   & r'   r¯   ÚParams4bit.state2+  r¢   r*   c                óÌ   € V P                   P                  R 4      pVe%   VP                  e   VP                  P                  # \	        R\        V 4      P                   R24      h)r}   rš   z)' object has no attribute 'nested_absmax')r�   r›   r¯   rœ   r�   rž   r`   rŸ   s   & r'   Únested_absmaxÚParams4bit.nested_absmax2  sT   € à�]‰]×Ñ˜}Ó-ˆØŠ>˜bŸi™iÒ3Ø—9‘9×#Ñ#Ð#Ü˜q¤ d£×!4Ñ!4Ð 5Ð5^Ð_Ó`Ð`r*   c                óÌ   € V P                   P                  R 4      pVe%   VP                  e   VP                  P                  # \	        R\        V 4      P                   R24      h)r}   rš   z,' object has no attribute 'nested_blocksize')r�   r›   r¯   r~   r�   rž   r`   rŸ   s   & r'   Únested_blocksizeÚParams4bit.nested_blocksize9  sT   € à�]‰]×Ñ˜}Ó-ˆØŠ>˜bŸi™iÒ3Ø—9‘9×&Ñ&Ð&Ü˜q¤ d£×!4Ñ!4Ð 5Ð5aÐbÓcÐcr*   c                óÌ   € V P                   P                  R 4      pVe%   VP                  e   VP                  P                  # \	        R\        V 4      P                   R24      h)r}   rš   z,' object has no attribute 'nested_quant_map')r�   r›   r¯   r¥   r�   rž   r`   rŸ   s   & r'   Únested_quant_mapÚParams4bit.nested_quant_map@  sR   € à�]‰]×Ñ˜}Ó-ˆØŠ>˜bŸi™iÒ3Ø—9‘9—>‘>Ð!Ü˜q¤ d£×!4Ñ!4Ð 5Ð5aÐbÓcÐcr*   c                óÌ   € V P                   P                  R 4      pVe%   VP                  e   VP                  P                  # \	        R\        V 4      P                   R24      h)r}   rš   z(' object has no attribute 'nested_dtype')r�   r›   r¯   r
   r�   rž   r`   rŸ   s   & r'   Únested_dtypeÚParams4bit.nested_dtypeG  sR   € à�]‰]×Ñ˜}Ó-ˆØŠ>˜bŸi™iÒ3Ø—9‘9—?‘?Ð"Ü˜q¤ d£×!4Ñ!4Ð 5Ð5]Ð^Ó_Ð_r*   c                óœ   € V P                   P                  R 4      pVe   VP                  # \        R\	        V 4      P
                   R24      h)r}   rš   z)' object has no attribute 'nested_offset'r«   rŸ   s   & r'   Únested_offsetÚParams4bit.nested_offsetN  sE   € à�]‰]×Ñ˜}Ó-ˆØŠ>Ø—9‘9ÐÜ˜q¤ d£×!4Ñ!4Ð 5Ð5^Ð_Ó`Ð`r*   c                ó  € \        V 4      P                  \        V 4      4      pV P                  4       pVP                  V4       \        P
                  ! VR ,          4      Vn        \        P
                  ! VR,          4      Vn        V# )r}   r|   )rž   r�   r”   r—   r‘   Údeepcopyr}   r|   )r7   ÚmemoÚnew_instancer“   s   &&  r'   Ú__deepcopy__ÚParams4bit.__deepcopy__U  sg   € Ü˜D“z×)Ñ)¬$¨t«*Ó5ˆØ×!Ñ!Ó#ˆØ×!Ñ! %Ô(Ü#'§=¢=°°}Õ1EÓ#FˆÔ Ü ŸMšM¨%°­-Ó8ˆÔØÐr*   c                óŽ   € \        V 4      P                  \        V 4      4      pV P                  4       pVP                  V4       V# r?   )rž   r�   r”   r—   )r7   rÃ   r“   s   &  r'   Ú__copy__ÚParams4bit.__copy__]  s<   € Ü˜D“z×)Ñ)¬$¨t«*Ó5ˆØ×!Ñ!Ó#ˆØ×!Ñ! %Ô(ØÐr*   c          
      ón   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          RS[RS[R,          RR/# )r   r|   Úquantized_statsr‹   r‚   rƒ   r!   ry   )r2   r   Údictr…   r   r$   r   )r%   r&   s   "€r'   r(   r†   d  sN   ø€ ÷ ñ á�l‰lðñ ™c¡3˜h�ðñ ð	ñ ˜Õ&ðð 
ñr*   c                óÖ  € \         P                  P                  WP                  V4      4      pW7n        \
        P                  ! W$R 7      Vn        VP                  P                  Vn        VP                  P                  Vn
        VP                  P                  Vn        RVn        VP                  Vn        WWn        VP                  e   VP                  VP                  n        V# ))Úqs_dictr	   T)r2   r   r‰   rX   r‹   r   Ú	from_dictr}   r~   Únestedr   r€   r„   r
   r�   r‚   )rŠ   r|   rÊ   r‹   r	   r‚   rŒ   r7   s   &&&&&&, r'   Úfrom_prequantizedÚParams4bit.from_prequantizedc  s­   € ô �|‰|×*Ñ*¨3·±¸³Ó@ˆØ*ÔÜ%×/Ò/¸ÔWˆÔØ×)Ñ)×3Ñ3ˆŒØ#'×#3Ñ#3×#:Ñ#:ˆÔ Ø×*Ñ*×5Ñ5ˆŒØ!ˆÔà!ŸZ™ZˆÔØŒà�;‰;Ò"Ø&*×&6Ñ&6ˆD�K‰KÔ#àˆr*   c                óV  € V P                   P                  4       P                  V4      p\        P                  P                  VV P                  V P                  V P                  V P                  R 7      w  r4W0n         W@n
        V P                  e   W@P                  n
        RV n        V # ))r~   r   r€   r�   T)r|   Ú
contiguousrX   ÚbnbÚ
functionalÚquantize_4bitr~   r   r€   r�   r}   r‚   r„   )r7   r	   ÚwÚw_4bitr}   s   &&   r'   Ú	_quantizeÚParams4bit._quantize}  sŒ   € Ø�I‰I× Ñ Ó"×%Ñ% fÓ-ˆÜ!Ÿn™n×:Ñ:ØØ—n‘nØ $× 8Ñ 8Ø—‘Ø×,Ñ,ð ;ó 
Ñˆð Œ	Ø&ÔØ�;‰;Ò"Ø&1�K‰KÔ#Ø!ˆÔØˆr*   c                ó&   € V P                  R R7      # ©Úcpur-   ©rX   rD   s   &r'   rÝ   ÚParams4bit.cpu�  ó   € Ø�w‰w˜eˆwÓ$Ð$r*   c                óV   <€ V ^8„  d   QhRS[ S[S[,          S[,          ,          RS[/# ©r   r	   Únon_blocking©r   r"   r	   r…   r$   )r%   r&   s   "€r'   r(   r†   �  s-   ø€ ÷ _ñ _™8¡C©&¥L±3Õ$6Õ7ð _Édñ _r*   c                óÔ   € \        V P                  R R4      '       d.   \        V P                  V P                  4      w  V n        V n        T P	                  Vf	   RVR7      # TVR7      # )Úpacking_format_for_cpuFÚcuda©r	   rã   ©Úgetattrr}   r   r|   rX   ©r7   r	   rã   s   &&&r'   rç   ÚParams4bit.cuda�  sa   € Ü�4×#Ñ#Ð%=¸u×EÒEÜ*PÐQU×QZÑQZÐ\`×\lÑ\lÓ*mÑ'ˆDŒI�tÔ'Ø�w‰w¨ª˜fÐQ]ˆwÓ^Ð^¸FÐQ]ˆwÓ^Ð^r*   c                óV   <€ V ^8„  d   QhRS[ S[S[,          S[,          ,          RS[/# râ   rä   )r%   r&   s   "€r'   r(   r†   •  s-   ø€ ÷ ^ñ ^™(¡3©¥<±#Õ#5Õ6ð ^ÉTñ ^r*   c                óÔ   € \        V P                  R R4      '       d.   \        V P                  V P                  4      w  V n        V n        T P	                  Vf	   RVR7      # TVR7      # )ræ   FÚxpurè   ré   rë   s   &&&r'   rï   ÚParams4bit.xpu•  sa   € Ü�4×#Ñ#Ð%=¸u×EÒEÜ*PÐQU×QZÑQZÐ\`×\lÑ\lÓ*mÑ'ˆDŒI�tÔ'Ø�w‰w v¢~˜eÐP\ˆwÓ]Ð]¸6ÐP\ˆwÓ]Ð]r*   c          
      óx   <€ V ^8„  d   QhRS[ RS[S[S[,          ,          RS[S[S[,          ,          RS[RS[ /# ©r   r7   r	   r
   rã   r!   ©r   r   r"   r	   r
   r…   r$   )r%   r&   s   "€r'   r(   r†   ›  óM   ø€ ÷ ñ Ùðá™™v�Õ&ðñ ™¡�Õ$ðñ ð	ñ
 
ñr*   c                ó   € R # r?   r<   ©r7   r	   r
   rã   s   &&&&r'   rX   ÚParams4bit.toš  ó   € ñ r*   c                óB   <€ V ^8„  d   QhRS[ RS[S[,          RS[RS[ /# ©r   r7   r
   rã   r!   ©r   r
   r…   r$   )r%   r&   s   "€r'   r(   r†   £  ó!   ø€ ×KÑK‘ÐK™5¡3�;ÐK±dÐKÁQÑKr*   c                ó   € R # r?   r<   ©r7   r
   rã   s   &&&r'   rX   r÷   ¢  ó   € ÙHKr*   c                ó2   <€ V ^8„  d   QhRS[ RS[RS[RS[ /# ©r   r7   Útensorrã   r!   ©r   r   r$   )r%   r&   s   "€r'   r(   r†   ¦  ó   ø€ ×GÑG‘ÐG™FÐG±$ÐGÁÑGr*   c                ó   € R # r?   r<   ©r7   r  rã   s   &&&r'   rX   r÷   ¥  ó   € ÙDGr*   c                óô  <€ \         P                  P                  P                  ! V/ VB w  r4rVVe5   VP                  R8w  d$   V P
                  '       g   V P                  V4      # V P                  e   V P                  P                  V4       \        \        SV `!  W4VR7      V P                  V P                  V P                  V P                  V P                  V P                  V P
                  R7      pV# )NÚmeta©r	   r
   rã   )r‹   r}   r~   r   r€   r�   r„   )r2   Ú_CÚ_nnÚ	_parse_torž   r„   rÙ   r}   rX   ry   r0   r‹   r~   r   r€   r�   )	r7   ÚargsrŒ   r	   r
   rã   Ú_Ú	new_paramr8   s	   &*,     €r'   rX   r÷   ¨  sÍ   ø€ Ü).¯©¯©×)?Ò)?ÀÐ)PÈÑ)PÑ&ˆ�|àÒ &§+¡+°Ô"7À×@R×@RÐ@RØ—>‘> &Ó)Ð)à×ÑÒ+Ø× Ñ ×#Ñ# FÔ+ä"Ü‘‘
 &ÀL�
ÓQØ"×0Ñ0Ø ×,Ñ,ØŸ.™.Ø$(×$<Ñ$<ØŸ?™?Ø"×0Ñ0Ø"×0Ñ0ô	ˆIð Ðr*   c                ó  <a a€ Vf   / pV\         P                  \         P                  39   dÅ   V^ ,          o\        SS `  WW44      p\        V\        4      '       d5   \        ;QJ d    . V V3R lV 4       F  NK  	  5# ! V V3R lV 4       4      # S ! VSP                  SP                  SP                  SP                  SP                  SP                  SP                  SP                  R7	      # \        SS `  WW44      # )Nc              3   óæ   <"  € T Ff  pS! VSP                   SP                  SP                  SP                  SP                  SP
                  SP                  SP                  R 7	      x € Kh  	  R# 5i)©	r|   r‹   r}   r~   r   r€   r�   r‚   r„   N)r‹   r}   r~   r   r€   r�   r‚   r„   )Ú.0ÚchunkrŠ   r  s   & €€r'   Ú	<genexpr>Ú0Params4bit.__torch_function__.<locals>.<genexpr>É  so   øé € ð ñ "(˜ñ Ø"Ø&,×&:Ñ&:Ø$*×$6Ñ$6Ø"(×"2Ñ"2Ø,2×,FÑ,FØ#)×#4Ñ#4Ø&,×&:Ñ&:Ø%Ÿ}™}Ø&,×&:Ñ&:÷
ñ 
ó "(ùs   ƒA.A1r  )r2   r  Úsplitr0   Ú__torch_function__Ú
isinstanceÚtupler‹   r}   r~   r   r€   r�   r‚   r„   )rŠ   ÚfuncÚtypesr  rŒ   Úresultr  r8   s   f&&&& @€r'   r  ÚParams4bit.__torch_function__¾  së   ú€ àŠ>ØˆFà”E—K‘K¤§¡Ð-Ô-Ø˜!•WˆFä‘WÑ/°¸TÓJˆFä˜&¤%×(Ò(ß”uõ ñ "(ó—uð �uõ ñ "(óó ð ñ ØØ"(×"6Ñ"6Ø &× 2Ñ 2Ø$×.Ñ.Ø(.×(BÑ(BØ%×0Ñ0Ø"(×"6Ñ"6Ø!Ÿ=™=Ø"(×"6Ñ"6ô
ð 
ô ‰wÑ)¨$°tÓDÐDr*   )	r~   r„   r   r|   r‚   r}   r�   r€   r‹   )Frç   N©NF©...©.)r<   N)"r`   ra   rb   rc   r2   Úuint8r�   r”   r—   Úpropertyrœ   r¥   r¨   r¬   r¯   r²   rµ   r¸   r»   r¾   rÄ   rÇ   ÚclassmethodrÐ   rÙ   rÝ   rç   rï   r   rX   r  re   rf   rg   rh   s   @@r'   ry   ry   Õ   s¹  ù‡ € ð (,ØØ,0Ø#'Ø$(ØØ%*§[¡[Ø)-Ø#÷ò ò<ò	&ð* ñZó ðZð ñXó ðXð ñ]ó ð]ð ñZó ðZð ñZó ðZð ñaó ðað ñdó ðdð ñdó ðdð ñ`ó ð`ð ñaó ðaòòð ÷ñ ó ðò2ò %÷_ò _÷
^ò ^ð
 ÷ñ ó ðð ßKÑKó ØKàßGÑGó ØGõð, ö%Eó ÷%Eð %Er*   ry   c                ó2   € V ^8„  d   QhR\         R,          /# )r   r‚   )ÚEmbedding4bitrƒ   )r   )r%   s   "r'   r(   r(   ç  s   € ÷ 3ñ 3´EÐ:WÕ4Xñ 3r*   c                 ó�  € \        V P                  R R4      e   R# \        V R R4      f   \        P                  R4       V P                  P                  ^,          ^8X  g   Q h\        V P                  \        4      '       g(   \        V P                  V P                  RR7      V n        V P                  V P                  n        R# )r}   NzhFP4 quantization state not initialized. Please call .cuda() or .to(device) on the LinearFP4 layer first.T)r�   r„   )	rê   r.   ÚloggerÚwarningÚshaper  ry   r�   r}   )r‚   s   &r'   Ú'fix_4bit_weight_quant_state_from_moduler,  ç  s“   € Üˆv�}‰}˜m¨TÓ2Ò>Ùäˆv�} dÓ+Ò3Ü�‰Øvô	
ð �=‰=×Ñ˜qÕ! QÔ&Ð&Ð&Ü�f—m‘m¤Z×0Ò0Ü" 6§=¡=À×@TÑ@TÐdhÔiˆŒØ &× 2Ñ 2€F‡M�MÖr*   c                   ó~   a a€ ] tR tRt oRtRRRR]P                  R3V 3R lltR tV 3R lt	V3R	 lR
 lt
RtVtV ;t# )rƒ   iø  az  
This class is the base module for the 4-bit quantization algorithm presented in [QLoRA](https://arxiv.org/abs/2305.14314).
QLoRA 4-bit linear layers uses blockwise k-bit quantization under the hood, with the possibility of selecting various
compute datatypes such as FP4 and NF4.

In order to quantize a linear layer one should first load the original fp16 / bf16 weights into
the Linear4bit module, then call `quantized_module.to("cuda")` to quantize the fp16 / bf16 weights.

Example:

```python
import torch
import torch.nn as nn

import bitsandbytes as bnb
from bitsandbytes.nn import Linear4bit

fp16_model = nn.Sequential(
    nn.Linear(64, 64),
    nn.Linear(64, 64)
)

quantized_model = nn.Sequential(
    Linear4bit(64, 64),
    Linear4bit(64, 64)
)

quantized_model.load_state_dict(fp16_model.state_dict())
quantized_model = quantized_model.to(0) # Quantization happens here
```
TNrz   c	           	     óÒ   <€ \         S	V `  WW84       \        V P                  P                  RVVVV R7      V n        W@n        VRJV n        RV n        Wpn        \        4       V n
        R# )a/  
Initialize Linear4bit class.

Args:
    input_features (`str`):
        Number of input features of the linear layer.
    output_features (`str`):
        Number of output features of the linear layer.
    bias (`bool`, defaults to `True`):
        Whether the linear class uses the bias term as well.
F©r‹   r   r€   r�   r‚   N)r0   r1   ry   r.   r|   Úcompute_dtypeÚcompute_type_is_setr}   r�   r   Úsupport_avx512bf16_for_cpu)
r7   Úinput_featuresÚoutput_featuresÚbiasr0  r   r€   r�   r	   r8   s
   &&&&&&&&&€r'   r1   ÚLinear4bit.__init__  sj   ø€ ô, 	‰Ñ˜¸$ÔGÜ Ø�K‰K×ÑØØ 3Ø!Ø'Øô
ˆŒð +ÔØ#0¸Ð#<ˆÔ ØˆÔØ*ÔÜ*8Ó*:ˆÖ'r*   c                óD  € VP                   \        P                  \        P                  39   d   VP                   V n        R # VP                   \        P
                  8X  d¿   V P                  R \        P                  39   d<   VP                  4       VP                  R,          8X  d   \        P                  R4       V P                  R \        P                  39   d@   VP                  4       VP                  R,          8w  d   \        P                  R4       R # R # R # R # )Nz‚Input type into Linear4bit is torch.float16, but bnb_4bit_compute_dtype=torch.float32 (default). This will lead to slow inference.z”Input type into Linear4bit is torch.float16, but bnb_4bit_compute_dtype=torch.float32 (default). This will lead to slow inference or training speed.éÿÿÿÿ)
r
   r2   Úfloat32Úbfloat16r0  Úfloat16Únumelr+  r)  r*  )r7   Úxs   &&r'   Úset_compute_typeÚLinear4bit.set_compute_type?  sÊ   € Ø�7‰7”u—}‘}¤e§n¡nÐ5Ô5ð "#§¡ˆDÖØ�W‰WœŸ™Ô%à×!Ñ! d¬E¯M©MÐ%:Ô:ÀÇÁÃ	ÈQÏWÉWÐUWÍ[Ô@Xô —‘ð Yôð ×!Ñ! d¬E¯M©MÐ%:Ô:ÀÇÁÃ	ÈQÏWÉWÐUWÍ[Ô@XÜ—‘ð köñ AYÑ:ñ &r*   c                óV  <€ \        V P                  RR4      e}   \        V P                  P                  RR4      '       dV   \        V P                  P                  V P                  P                  4      w  V P                  n        V P                  n        \
        SV `  WV4       \        V P                  RR4      ej   V P                  P                  P                  RR7      P                  4        F/  w  rEV'       d   TMVP                  4       WR,           V,           &   K1  	  R# R# )zK
save weight and bias,
then fill state_dict with components of quant_state
r}   Nræ   FT)Úpackedzweight.)
rê   r.   r}   r   r|   r0   Ú_save_to_state_dictÚas_dictÚitemsÚdetach)r7   ÚdestinationÚprefixÚ	keep_varsÚkÚvr8   s   &&&&  €r'   rB  ÚLinear4bit._save_to_state_dictQ  så   ø€ ô
 �4—;‘; ¨tÓ4Ò@ÄWØ�K‰K×#Ñ#Ð%=¸u÷F
ò F
ô 9_Ø—‘× Ñ  $§+¡+×"9Ñ"9ó9Ñ5ˆD�K‰KÔ˜dŸk™kÔ5ô 	‰Ñ# K¸ÔCÜ�4—;‘; ¨tÓ4Ò@ØŸ™×/Ñ/×7Ñ7¸tÐ7ÓD×JÑJÖL‘�ß;D±aÈ!Ï(É(Ë*� YÕ.°Õ2Ó3ó Mñ Ar*   c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©r   r=  ©r2   r   )r%   r&   s   "€r'   r(   ÚLinear4bit.__annotate__a  s   ø€ ÷ añ a™Ÿ™ñ ar*   c                ón  € \        V 4       V P                  P                  pVP                  P                  R 8X  d{   V P
                  '       di   V P                  '       gW   VP                  R8X  dF   \        VRR4      '       g3   \        V P                  P                  V4      w  V P                  n
        pV P                  '       g   V P                  V4       RV n        VP                  pV P                  e   VP                  V P                  4      pV P                   pVea   VP                  VP                  8w  d+   VP                  P                  VP                  4      Vn
        VP                  V P                  4      p\"        P$                  ! WP                  WBR7      P                  V4      # )rÝ   Fræ   T)r5  r}   )r,  r.   r}   r	   rž   r2  Útrainingr‹   rê   r   r|   r1  r>  r
   r0  rX   r5  rÔ   Úmatmul_4bit)r7   r=  r}   Ú	inp_dtyper5  s   &&   r'   r\   ÚLinear4bit.forwarda  s6  € Ü/°Ô5Ø—k‘k×-Ñ-ˆð �H‰H�M‰M˜UÔ"Ø×/×/Ð/Ø—M—M�MØ—‘ 5Ô(Ü˜KÐ)AÀ5×IÒIä,JÈ4Ï;É;×K[ÑK[Ð]hÓ,iÑ)ˆD�K‰KÔ˜kà×'×'Ð'Ø×!Ñ! !Ô$Ø'+ˆDÔ$à—G‘Gˆ	Ø×ÑÒ)Ø—‘�T×'Ñ'Ó(ˆAà�y‰yˆØÒØ�z‰z˜QŸW™WÔ$à ŸI™IŸL™L¨¯©Ó1�”	Ø—7‘7˜4×-Ñ-Ó.ˆDä�Š˜q§+¡+°DÔR×UÑUÐV_Ó`Ð`r*   )r0  r1  r}   r�   r2  r.   )r`   ra   rb   rc   rd   r2   r#  r1   r>  rB  r\   re   rf   rg   rh   s   @@r'   rƒ   rƒ   ø  sF   ù‡ € ñðH ØØ ØØ—k‘kØ÷$;òLõ$U÷ a÷ að ar*   rƒ   c                   óX   a a€ ] tR tRt oRtRRR]P                  R3V 3R lltRtVt	V ;t
# )Ú	LinearFP4i€  z
Implements the FP4 data type.
TNc           
     ó4   <€ \         SV `  VVVVVRVV4       R# )á  
Args:
    input_features (`str`):
        Number of input features of the linear layer.
    output_features (`str`):
        Number of output features of the linear layer.
    bias (`bool`, defaults to `True`):
        Whether the linear class uses the bias term as well.
rz   N©r0   r1   ©	r7   r3  r4  r5  r0  r   r�   r	   r8   s	   &&&&&&&&€r'   r1   ÚLinearFP4.__init__…  ó*   ø€ ô& 	‰ÑØØØØØØØØö		
r*   r<   ©r`   ra   rb   rc   rd   r2   r#  r1   re   rf   rg   rh   s   @@r'   rV  rV  €  s)   ù‡ € ñð ØØ Ø—k‘kØ÷
÷ 
r*   rV  c                   óX   a a€ ] tR tRt oRtRRR]P                  R3V 3R lltRtVt	V ;t
# )Ú	LinearNF4i¤  a
  Implements the NF4 data type.

Constructs a quantization data type where each bin has equal area under a standard normal distribution N(0, 1) that
is normalized into the range [-1, 1].

For more information read the paper: QLoRA: Efficient Finetuning of Quantized LLMs (https://arxiv.org/abs/2305.14314)

Implementation of the NF4 data type in bitsandbytes can be found in the `create_normal_map` function in
the `functional.py` file: https://github.com/TimDettmers/bitsandbytes/blob/main/bitsandbytes/functional.py#L236.
TNc           
     ó4   <€ \         SV `  VVVVVRVV4       R# )rX  Únf4NrY  rZ  s	   &&&&&&&&€r'   r1   ÚLinearNF4.__init__°  r\  r*   r<   r]  rh   s   @@r'   r_  r_  ¤  s)   ù‡ € ñ	ð ØØ Ø—k‘kØ÷
÷ 
r*   r_  c                   óì   a a€ ] tR tRt oRV3R lR lltV 3R ltR tRV3R lR lltRV3R lR	 lltR
 t	]
RV3R lR ll4       t]
RV3R lR ll4       t]
RV3R lR ll4       tV 3R ltRtVtV ;t# )Ú
Int8ParamsiÏ  c                ó˜   <€ V ^8„  d   QhRS[ S[P                  ,          RS[ S[P                  ,          RS[ S[P                  ,          /# )r   r|   ÚCBÚSCB)r   r2   r   )r%   r&   s   "€r'   r(   ÚInt8Params.__annotate__Ð  sD   ø€ ÷ ñ á‘u—|‘|Õ$ðñ
 ‘U—\‘\Õ"ðñ ‘e—l‘lÕ#ñr*   c                óž   € Vf   \         P                  ! ^ 4      p\         P                  P                  WV4      pWGn        WWn        W7n        V# r?   )r2   rˆ   r   r‰   rf  rg  Úhas_fp16_weights)rŠ   r|   r‹   rj  rf  rg  rŒ   Úobjs   &&&&&&, r'   r�   ÚInt8Params.__new__Ð  sA   € ð Š<Ü—;’;˜q“>ˆDÜ�l‰l×)Ñ)¨#°]ÓCˆØŒØŒØ/ÔØˆ
r*   c                ó$  <€ V P                   '       d   \        SV `	  V4      # V P                  P	                  4       P                  V\
        P                  R 7      p\        P                  P                  V4      w  r4pW0n        W0n
        W@n        V # )©r	   r
   )rj  r0   rX   r|   rÓ   r2   r;  rÔ   rÕ   Úint8_vectorwise_quantrf  rg  )r7   r	   ÚBrf  rg  r  r8   s   &&    €r'   rÙ   ÚInt8Params._quantizeá  sr   ø€ Ø× × Ð Ü‘7‘:˜fÓ%Ð%ð �I‰I× Ñ Ó"×%Ñ%¨V¼5¿=¹=Ð%ÓIˆÜ—^‘^×9Ñ9¸!Ó<‰
ˆ�ØŒ	ØŒØŒàˆr*   c                ó&   € V P                  R R7      # rÜ   rÞ   rD   s   &r'   rÝ   ÚInt8Params.cpuî  rà   r*   c                óV   <€ V ^8„  d   QhRS[ S[S[,          S[,          ,          RS[/# râ   rä   )r%   r&   s   "€r'   r(   rh  ñ  s-   ø€ ÷ _ñ _™8¡C©&¥L±3Õ$6Õ7ð _Édñ _r*   c                ó@   € T P                  Vf	   RVR7      # TVR7      # )Nrç   rè   rÞ   rë   s   &&&r'   rç   ÚInt8Params.cudañ  s'   € Ø�w‰w¨ª˜fÐQ]ˆwÓ^Ð^¸FÐQ]ˆwÓ^Ð^r*   c                óV   <€ V ^8„  d   QhRS[ S[S[,          S[,          ,          RS[/# râ   rä   )r%   r&   s   "€r'   r(   rh  ô  s-   ø€ ÷ ^ñ ^™(¡3©¥<±#Õ#5Õ6ð ^ÉTñ ^r*   c                ó@   € T P                  Vf	   RVR7      # TVR7      # )Nrï   rè   rÞ   rë   s   &&&r'   rï   ÚInt8Params.xpuô  s'   € Ø�w‰w v¢~˜eÐP\ˆwÓ]Ð]¸6ÐP\ˆwÓ]Ð]r*   c                ó:  € \        V 4      P                  \        V 4      \        P                  ! V P                  V4      V P
                  V P                  \        P                  ! V P                  V4      \        P                  ! V P                  V4      R 7      pV# ))r|   r‹   rj  rf  rg  )	rž   r�   r‘   rÁ   r|   r‹   rj  rf  rg  )r7   rÂ   rÃ   s   && r'   rÄ   ÚInt8Params.__deepcopy__÷  sr   € ä˜D“z×)Ñ)Ü�‹JÜ—’˜tŸy™y¨$Ó/Ø×,Ñ,Ø!×2Ñ2Ü�}Š}˜TŸW™W dÓ+Ü—’˜dŸh™h¨Ó-ð *ó 
ˆð Ðr*   c          
      óx   <€ V ^8„  d   QhRS[ RS[S[S[,          ,          RS[S[S[,          ,          RS[RS[ /# rò   ró   )r%   r&   s   "€r'   r(   rh    rô   r*   c                ó   € R # r?   r<   rö   s   &&&&r'   rX   ÚInt8Params.to  rø   r*   c                óB   <€ V ^8„  d   QhRS[ RS[S[,          RS[RS[ /# rú   rû   )r%   r&   s   "€r'   r(   rh    rü   r*   c                ó   € R # r?   r<   rþ   s   &&&r'   rX   r~    rÿ   r*   c                ó2   <€ V ^8„  d   QhRS[ RS[RS[RS[ /# r  r  )r%   r&   s   "€r'   r(   rh    r  r*   c                ó   € R # r?   r<   r  s   &&&r'   rX   r~    r  r*   c                ó˜  <€ \         P                  P                  P                  ! V/ VB w  r4rVV P                  P
                  \         P                  8H  pV'       gL   VeH   VP                  R8w  d7   V P                  P                  P                  R8X  d   V P                  V4      # \        \        S	V `1  W4VR7      V P                  V P                  R7      pV'       di   VP                  Vn        VeT   V P                   eF   V P                   P                  P                  R8w  d!   V P                   P                  V4      Vn        V# )Nr	  rÝ   r
  )r‹   rj  )r2   r  r  r  r|   r
   Úint8rž   r	   rÙ   rd  r0   rX   r‹   rj  rf  rg  )
r7   r  rŒ   r	   r
   rã   r  Úis_quantizedr  r8   s
   &*,      €r'   rX   r~    s÷   ø€ Ü).¯©¯©×)?Ò)?ÀÐ)PÈÑ)PÑ&ˆ�|à—y‘y—‘¬%¯*©*Ñ4ˆç Ò 2°v·{±{ÀfÔ7LÐQU×QZÑQZ×QaÑQa×QfÑQfÐjoÔQoð —>‘> &Ó)Ð)ô Ü‰G‰J˜fÀˆJÓMØ×,Ñ,Ø!×2Ñ2ô
ˆ	÷ Ø$Ÿ>™>ˆIŒLàÒ! d§h¡hÒ&:¸t¿x¹x¿¹×?SÑ?SÐW]Ô?]Ø $§¡§¡¨FÓ 3�	”àÐr*   )rf  rg  r|   )NTFNNr   r!  r"  )r`   ra   rb   rc   r�   rÙ   rÝ   rç   rï   rÄ   r   rX   re   rf   rg   rh   s   @@r'   rd  rd  Ï  s}   ù‡ € ÷ò õ"ò%÷_ò _÷^ò ^ò
ð ÷ñ ó ðð ßKÑKó ØKàßGÑGó ØG÷õ r*   rd  c                 ó¨  € V P                  V R 24      pVf   R# V P                  V R2R4      p\        V\        P                  4      '       d   VP                  4       p\        V\        4      '       d   V\        9  d   \        RV 24      h\        V\        4      '       d   V\        9   d   \        V,          pVR8w  d   \        RV 24      hR# )r.   NÚweight_formatÚrowz'Expected supported weight format - got z+Only 'row' weight format is supported, got )	r›   Úpopr  r2   r   Úitemr"   r   Ú
ValueError)	Ú
state_dictrG  Úlocal_metadataÚstrictÚmissing_keysÚunexpected_keysÚ
error_msgsr.   r‡  s	   &&&&&&&  r'   Úmaybe_rearrange_weightr’  ,  s¾   € Ø�^‰^˜v˜h fÐ-Ó.€FØ‚~áØ—N‘N f X¨]Ð#;¸UÓC€Mä�-¤§¡×.Ò.Ø%×*Ñ*Ó,ˆô �-¤×%Ò%¨-Ô?iÔ*iÜÐBÀ=À/ÐRÓSÐSÜ	�M¤3×	'Ò	'¨MÔ=gÔ,gÜBÀ=ÕQˆà˜ÔÜÐFÀ}ÀoÐVÓWÐWñ r*   c                   óR   a a€ ] tR tRt oRtRV 3R lltR tV3R lR ltRtVt	V ;t
# )	ÚEmbedding8bitiA  a¬  
This class implements [LLM.int8()](https://arxiv.org/abs/2208.07339) algorithm for embedding layer

Quantization API is similar to Linear8bitLt:
```python
import torch
import torch.nn as nn

from bitsandbytes.nn import Embedding8bit

fp16_module = nn.Embedding(128, 64)
int8_module = Embedding8bit(128, 64)

int8_module.load_state_dict(fp16_module.state_dict())

int8_module = int8_module.to(0) # Quantization happens here
```
c                óÂ   <€ \         SV `  WW4R 7       V P                  P                  P                  V n        \        V P                  P                  RRR7      V n        R# )rn  F©rj  r‹   N)r0   r1   r.   r|   r
   rd  )r7   r   r   r	   r
   r8   s   &&&&&€r'   r1   ÚEmbedding8bit.__init__U  sG   ø€ Ü‰Ñ˜¸vÐÔSØ—[‘[×%Ñ%×+Ñ+ˆŒ
ä  §¡×!1Ñ!1ÀEÐY^Ô_ˆŽr*   c                ó   € \        R 4      h)z.Saving Embedding8bit module is not implemented©ÚNotImplementedError©r7   rF  rG  rH  s   &&&&r'   rB  Ú!Embedding8bit._save_to_state_dict[  ó   € Ü!Ð"RÓSÐSr*   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# rR   rT   )r%   r&   s   "€r'   r(   ÚEmbedding8bit.__annotate__^  s   ø€ ÷ %ñ %™Vð %©ñ %r*   c                ó  € \        V P                  R 4      '       g   \        R4      hV P                  P                  pV P                  P                  pVP
                  V P                  V P                  38X  g   Q hVP
                  V P                  38X  g   Q h\        P                  ! W4      p\        P                  ! WP                  V P                  ^4      4      pWER,          ,          pVP                  V P                  4      # )rg  zKEmbedding layer is not quantized. Please call .cuda() or .to(device) first.g     À_@)Úhasattrr.   ÚRuntimeErrorr|   rg  r+  r   r   rV   rW   ÚviewrX   r
   )r7   rS   ÚrowsÚ	row_statsÚcompressed_outputÚcompressed_output_statsÚoutputs   &&     r'   r\   ÚEmbedding8bit.forward^  sÉ   € Ü�t—{‘{ E×*Ò*ÜÐlÓmÐmà�{‰{×ÑˆØ—K‘K—O‘Oˆ	à�z‰z˜d×1Ñ1°4×3EÑ3EÐFÔFÐFÐFØ�‰ 4×#6Ñ#6Ð"8Ô8Ð8Ð8äŸKšK¨Ó4ÐÜ"#§+¢+¨e·^±^ÀD×DWÑDWÐYZÓ5[Ó"\Ðà"ÀÕ&EÕFˆà�y‰y˜Ÿ™Ó$Ð$r*   ©r
   r.   )NN)r`   ra   rb   rc   rd   r1   rB  r\   re   rf   rg   rh   s   @@r'   r”  r”  A  s%   ù‡ € ñ÷&`òT÷%÷ %ð %r*   r”  c                   ó€   a a€ ] tR tRt oRtRR]P                  R3V 3R lltV3R lR ltR t	V3R	 lR
 lt
RtVtV ;t# )r'  ip  aÿ  
This is the base class similar to Linear4bit. It implements the 4-bit quantization algorithm presented in
[QLoRA](https://arxiv.org/abs/2305.14314) for embeddings.

Quantization API is similar to Linear4bit:
```python
import torch
import torch.nn as nn

from bitsandbytes.nn import Embedding4bit

fp16_module = nn.Embedding(128, 64)
quantized_module = Embedding4bit(128, 64)

quantized_module.load_state_dict(fp16_module.state_dict())

quantized_module = quantized_module.to(0) # Quantization happens here
```
Nrz   c           	     óJ  <€ \         SV `  WWcR 7       V P                  P                  P                  V n        \        V P                  P                  RRVVV R7      V n        V P                  P                  pW',          ^ 8w  d   \        P                  RV RV R24       R# R# )rn  FNr/  zEmbedding size z  is not divisible by block size z#. This will lead to slow inference.)	r0   r1   r.   r|   r
   ry   r~   r)  r*  )	r7   r   r   r
   r€   r�   r	   r~   r8   s	   &&&&&&& €r'   r1   ÚEmbedding4bit.__init__…  sž   ø€ ô 	‰Ñ˜¸vÐÔSØ—[‘[×%Ñ%×+Ñ+ˆŒ
ä Ø�K‰K×ÑØØ $Ø!Ø'Øô
ˆŒð —K‘K×)Ñ)ˆ	àÕ$¨Ô)Ü�N‰NØ! - Ð0PÐQZÐP[ð \4ð 4öñ *r*   c                ó    <€ V ^8„  d   QhRS[ /# )r   rS   rT   )r%   r&   s   "€r'   r(   ÚEmbedding4bit.__annotate__¢  s   ø€ ÷ %ñ %±fñ %r*   c                óä  € V P                   V P                  P                  P                  ,          ^ 8X  g   Q hV P                  P                  P                  \        P                  4      P                  V P                  V P                   ,          ^,          ^4      p\        P                  P                  P                  VP                  V P                  V P                   ^,          4      VR7      P                  R^4      pVP                  VP                  4       V P                   ,          ^,          ^38X  g   Q hV P                   V P                  P                  ,          pV P                  P                  P                  pVP                  V P                  V,          38X  g   Q h\        P                  P                  P                  VP                  V P                  V4      VR7      P                  R4      pVP                  VP                  4       V,          38X  g   Q h\        P                   ! V P                  P                  4      pWgn        \        P"                  ! . VP                  OV P                   N54      Vn        \$        P                  P'                  W74      pVP                  . VP                  OV P                   N58X  g   Q hVP)                  V P*                  4      # )r   ©r.   rS   r8  )r   r.   r}   r~   r|   r£  r2   r#  r   r   rÕ   rW   r+  r<  rœ   r‘   rÁ   ÚSizerÔ   Údequantize_4bitrX   r
   )	r7   rS   Úw_4bit_uint8Úoutput_4bitÚblocks_per_embrœ   Úoutput_absmaxÚoutput_quant_stater¨  s	   &&       r'   Ú _forward_with_partial_dequantizeÚ.Embedding4bit._forward_with_partial_dequantize¢  sC  € Ø×!Ñ! D§K¡K×$;Ñ$;×$EÑ$EÕEÈÔJÐJÐJà—{‘{×'Ñ'×,Ñ,¬U¯[©[Ó9×>Ñ>¸t×?RÑ?RÐUY×UgÑUgÕ?gÐklÕ?lÐnoÓpˆä—h‘h×)Ñ)×3Ñ3Ø×$Ñ$ T×%8Ñ%8¸$×:LÑ:LÐPQÕ:QÓRØð 4ó 
÷ ‰$ˆr�1‹+ð 	ð × Ñ  U§[¡[£]°T×5GÑ5GÕ%GÈ1Õ%LÈaÐ$PÔPÐPÐPà×+Ñ+¨t¯{©{×/DÑ/DÕDˆà—‘×(Ñ(×/Ñ/ˆØ�|‰| × 3Ñ 3°nÕ DÐFÔFÐFÐFäŸ™×+Ñ+×5Ñ5Ø—;‘;˜t×2Ñ2°NÓCØð 6ó 
÷ ‰$Øó
ð 	ð ×"Ñ" u§{¡{£}°~Õ'EÐ&GÔGÐGÐGä!Ÿ]š]¨4¯;©;×+BÑ+BÓCÐØ$1Ô!Ü#(§:¢:Ð.P°·±Ð.P¸T×=OÑ=OÑ.PÓ#QÐÔ ä—‘×/Ñ/°ÓPˆØ�|‰|ÐA §¡ÐA¨d×.@Ñ.@ÑAÔAÐAÐAà�y‰y˜Ÿ™Ó$Ð$r*   c                ó   € \        R 4      h)z.Saving Embedding4bit module is not implementedr™  r›  s   &&&&r'   rB  Ú!Embedding4bit._save_to_state_dictÃ  r�  r*   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# rR   rT   )r%   r&   s   "€r'   r(   r¯  Æ  s   ø€ ÷ ñ ™Vð ©ñ r*   c                ó¾  € \        V 4       V P                  V P                  P                  P                  ,          ^ 8X  d   V P                  V4      # \        P                  P                  V P                  P                  V P                  P                  4      p\        P                  P                  P                  VVR7      P                  V P                  4      # )r   r±  )r,  r   r.   r}   r~   r¹  rÔ   rÕ   r³  r|   r2   r   rW   rX   r
   )r7   rS   Údequantized_weights   && r'   r\   ÚEmbedding4bit.forwardÆ  s    € Ü/°Ô5à×Ñ §¡× 7Ñ 7× AÑ AÕAÀQÔFØ×8Ñ8¸Ó?Ð?ä Ÿ^™^×;Ñ;¸D¿K¹K×<LÑ<LÈdÏkÉk×NeÑNeÓfÐä�x‰x×"Ñ"×,Ñ,Ø%Øð -ó 
÷ ‰"ˆT�Z‰Z‹.ð	r*   rª  )r`   ra   rb   rc   rd   r2   r#  r1   r¹  rB  r\   re   rf   rg   rh   s   @@r'   r'  r'  p  sA   ù‡ € ñð0 ØØ—k‘kØ÷÷:%ð %òBT÷÷ ð r*   r'  c                   óP   a a€ ] tR tRt oR]P
                  R3V 3R lltRtVtV ;t	# )ÚEmbeddingFP4iÔ  Nc           	     ó2   <€ \         SV `  VVVR VVR7       R# )rz   ©r
   r€   r�   r	   NrY  ©r7   r   r   r
   r�   r	   r8   s   &&&&&&€r'   r1   ÚEmbeddingFP4.__init__Õ  ó)   ø€ ô 	‰ÑØØØØØ'Øð 	ö 	
r*   r<   ©
r`   ra   rb   rc   r2   r#  r1   re   rf   rg   rh   s   @@r'   rÂ  rÂ  Ô  ó   ù‡ € ð
 Ø—k‘kØ÷
÷ 
r*   rÂ  c                   óP   a a€ ] tR tRt oR]P
                  R3V 3R lltRtVtV ;t	# )ÚEmbeddingNF4iç  Nc           	     ó2   <€ \         SV `  VVVR VVR7       R# )ra  rÄ  NrY  rÅ  s   &&&&&&€r'   r1   ÚEmbeddingNF4.__init__è  rÇ  r*   r<   rÈ  rh   s   @@r'   rË  rË  ç  rÉ  r*   rË  c                   ó‚   a a€ ] tR tRt oRtRV3R lV 3R llltV 3R ltV 3R ltR tV 3R lt	V3R	 lR
 lt
RtVtV ;t# )ÚLinear8bitLtiú  a  
This class is the base module for the [LLM.int8()](https://arxiv.org/abs/2208.07339) algorithm.
To read more about it, have a look at the paper.

In order to quantize a linear layer one should first load the original fp16 / bf16 weights into
the Linear8bitLt module, then call `int8_module.to("cuda")` to quantize the fp16 weights.

Example:

```python
import torch
import torch.nn as nn

import bitsandbytes as bnb
from bitsandbytes.nn import Linear8bitLt

fp16_model = nn.Sequential(
    nn.Linear(64, 64),
    nn.Linear(64, 64)
)

int8_model = nn.Sequential(
    Linear8bitLt(64, 64, has_fp16_weights=False),
    Linear8bitLt(64, 64, has_fp16_weights=False)
)

int8_model.load_state_dict(fp16_model.state_dict())
int8_model = int8_model.to(0) # Quantization happens here
```
c                ó&   <€ V ^8„  d   QhRS[ RS[ /# )r   r3  r4  )r"   )r%   r&   s   "€r'   r(   ÚLinear8bitLt.__annotate__  s#   ø€ ÷ +Hñ +Háð+Hñ ñ+Hr*   c                ó^  <€ \         SV `  WW74       \        P                  ! 4       V n        W`n        WPP                  n        W@P                  n        VR8”  d   V'       g   RV P                  n        \        V P                  P                  WDR7      V n
        V P                  \        4       R# )a.  
Initialize Linear8bitLt class.

Args:
    input_features (`int`):
        Number of input features of the linear layer.
    output_features (`int`):
        Number of output features of the linear layer.
    bias (`bool`, defaults to `True`):
        Whether the linear class uses the bias term as well.
    has_fp16_weights (`bool`, defaults to `True`):
        If False, weights are quantized to int8 on ``.to(device)``. If True,
        weights remain in fp16 and are quantized on-the-fly during each forward pass.
    threshold (`float`, defaults to `0.0`):
        Outlier threshold for mixed-precision decomposition (LLM.int8()). During the
        forward pass, activation columns where any value exceeds this threshold are
        computed in fp16, while the remaining columns use int8. This operates on
        **activations** (inputs), not on weight values. Set to 0.0 to disable
        mixed-precision decomposition and quantize all columns to int8.
    index: Indices for weight reordering (used internally).
    device: Device to initialize the layer on.
ç        Tr–  N)r0   r1   rÔ   ÚMatmulLtStater“   ÚindexÚ	thresholdrj  Úuse_poolrd  r.   r|   Ú"_register_load_state_dict_pre_hookr’  )	r7   r3  r4  r5  rj  rÖ  rÕ  r	   r8   s	   &&&&&&&&€r'   r1   ÚLinear8bitLt.__init__  s|   ø€ ô@ 	‰Ñ˜¸$ÔGÜ×&Ò&Ó(ˆŒ
ØŒ
à(�
‰
ÔØ&6�
‰
Ô#à�sŒ?×#3Ø"&ˆD�J‰JÔä  §¡×!1Ñ!1ÐDTÔuˆŒØ×/Ñ/Ô0FÖGr*   c                ó  <€ \         S	V `  WV4       R p\        V P                  VR4      p\        V P                  V4      pW$ ,           pVR,           pV P                  P
                  '       g—   VeG   V'       d   TMVP                  4       W&   \        P                  ! ^ \        P                  R7      W&   R# VeG   V'       d   TMVP                  4       W&   \        P                  ! ^ \        P                  R7      W&   R# R# R# )rg  Nr‡  )r
   )
r0   rB  rê   r.   r“   rj  rE  r2   r  r#  )
r7   rF  rG  rH  Úscb_nameÚparam_from_weightÚparam_from_stateÚkey_nameÚformat_namer8   s
   &&&&     €r'   rB  Ú Linear8bitLt._save_to_state_dictG  s×   ø€ Ü‰Ñ# K¸ÔCð ˆô $ D§K¡K°¸4Ó@Ðä" 4§:¡:¨xÓ8Ðà˜jÕ)ˆð ˜Õ.ˆà�z‰z×*×*Ð*Ø Ò,ß=FÑ(9ÐL]×LdÑLdÓLf�Ñ%Ü+0¯<ª<¸ÄÇÁÔ+M�Ó(Ø!Ò-ß<EÑ(8ÐK[×KbÑKbÓKd�Ñ%Ü+0¯<ª<¸ÄÇÁÔ+M�Ó(ñ .ñ	 +r*   c           	     ó¢  <€ \         SV `  VVVVVVV4       \        V4      pV F§  p	V	\        V4      R  p
V
R8X  g   K  \	        V P
                  RR 4      pVf   \        R4      hW,          pVP                  V4       V P                  P                  e&   V P
                  P                  V P                  n	        VP                  V	4       K©  	  R # )Nrg  zŠLoading a quantized checkpoint into non-quantized Linear8bitLt is not supported. Please call module.cuda() before module.load_state_dict())r0   Ú_load_from_state_dictÚlistÚlenrê   r.   r¢  Úcopy_r“   rg  Úremove)r7   rŒ  rG  r�  rŽ  r�  r�  r‘  Úunexpected_copyÚkeyÚ
input_nameÚ
weight_scbÚinput_paramr8   s   &&&&&&&&     €r'   râ  Ú"Linear8bitLt._load_from_state_dict_  sÆ   ø€ ô 	‰Ñ%ØØØØØØØô	
ô ˜Ó/ˆã"ˆCØœS ›[˜]Ð+ˆJØ˜UÖ"Ü$ T§[¡[°%¸Ó>�
ØÒ%ä&ðcóð ð
 )�o�Ø× Ñ  Ô-à—:‘:—>‘>Ò-Ø%)§[¡[§_¡_�D—J‘J”Nà×&Ñ& sÖ+ó# #r*   c                óÞ   € V P                   P                  V P                  n        V P                   P                  V P                  n        R V P                   n        R V P                   n        R # r?   )r.   rf  r“   rg  rD   s   &r'   Úinit_8bit_stateÚLinear8bitLt.init_8bit_state‡  s>   € ØŸ™Ÿ™ˆ�
‰
ŒØŸ™Ÿ™ˆ�
‰
ŒØˆ�‰ŒØˆ�‰Žr*   c                ó¾  <€ \         SV `  ! V/ VB p\        P                  P                  P
                  ! V/ VB w  p  pVe™   VP                  P                  e5   VP                  P                  P                  V4      VP                  n        VP                  P                  e5   VP                  P                  P                  V4      VP                  n        V# r?   )	r0   rX   r2   r  r  r  r“   rf  rg  )r7   r  rŒ   r  r	   r  r8   s   &*,   €r'   rX   ÚLinear8bitLt.to�  s¥   ø€ ä‘’˜TÐ, VÑ,ˆäŸ(™(Ÿ,™,×0Ò0°$ÐA¸&ÑA‰ˆ��1�að ÒØ�|‰|�‰Ò*Ø"(§,¡,§/¡/×"4Ñ"4°VÓ"<�—‘”Ø�|‰|×ÑÒ+Ø#)§<¡<×#3Ñ#3×#6Ñ#6°vÓ#>�—‘Ô àˆr*   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rM  rN  )r%   r&   s   "€r'   r(   rÑ  œ  s   ø€ ÷ ñ ™Ÿ™ñ r*   c                óŽ  € V P                   V P                  n        V P                  P                  e   V P                  4        V P                  ed   V P                  P                  VP                  8w  d?   V P                  P                  P                  VP                  4      V P                  n        \        P                  ! WP                  V P                  V P                  R7      pV P                  P                  '       g>   V P                  P                  e&   V P                  P                  V P                  n        V# )N)r5  r“   )rQ  r“   Úis_trainingr.   rf  rî  r5  r
   r|   rX   rÔ   Úmatmulrj  )r7   r=  Úouts   && r'   r\   ÚLinear8bitLt.forwardœ  sÁ   € Ø!%§¡ˆ�
‰
ÔØ�;‰;�>‰>Ò%Ø× Ñ Ô"ð �9‰9Ò  T§Y¡Y§_¡_¸¿¹Ô%?Ø!ŸY™YŸ^™^×.Ñ.¨q¯w©wÓ7ˆD�I‰IŒNä�jŠj˜ŸK™K¨d¯i©i¸t¿z¹zÔJˆà�z‰z×*×*Ð*¨t¯z©z¯}©}Ò/HØ#Ÿz™zŸ}™}ˆD�K‰KÔàˆ
r*   )rÕ  r“   r.   )TTrÓ  NN)r`   ra   rb   rc   rd   r1   rB  râ  rî  rX   r\   re   rf   rg   rh   s   @@r'   rÏ  rÏ  ú  s<   ù‡ € ñ÷>+Hõ +HõZNõ0&,òPõ÷÷ ð r*   rÏ  c                   óH   a a€ ] tR tRt oRV 3R lltR tR tR tRtVt	V ;t
# )ÚOutlierAwareLineari­  c                óD   <€ \         SV `  WW44       R V n        RV n        R # r   )r0   r1   Úoutlier_dimr…  )r7   r3  r4  r5  r	   r8   s   &&&&&€r'   r1   ÚOutlierAwareLinear.__init__®  s"   ø€ Ü‰Ñ˜¸$ÔGØˆÔØ!ˆÖr*   c                ó   € \        R 4      h)zJPlease override the `forward_with_outliers(self, x, outlier_idx)` functionr™  )r7   r=  Úoutlier_idxs   &&&r'   Úforward_with_outliersÚ(OutlierAwareLinear.forward_with_outliers³  s   € Ü!Ð"nÓoÐor*   c                ó   € \        R 4      h)zEPlease override the `quantize_weights(self, w, outlier_idx)` functionr™  )r7   r×   rþ  s   &&&r'   Úquantize_weightÚ"OutlierAwareLinear.quantize_weight¶  s   € Ü!Ð"iÓjÐjr*   c                ó°  € V P                   fb   \        P                  ! 4       pVP                  4       '       g   \        P                  R4       VP                  V P                  4      pW0n         V P                  '       gU   V P                  V P                  V P                   4      pV P                  P                  P                  V4       RV n        R # R # )NzTPlease use OutlierTracer.initialize(model) before using the OutlierAwareLinear layerT)rû  r   r5   Úis_initializedr)  r*  Úget_outliersr.   r…  r  r|   rå  )r7   r=  Útracerrþ  r×   s   &&   r'   r\   ÚOutlierAwareLinear.forward¹  sŸ   € Ø×ÑÒ#Ü"×/Ò/Ó1ˆFØ×(Ñ(×*Ò*Ü—‘ÐuÔvØ ×-Ñ-¨d¯k©kÓ:ˆKØ*Ôà× × Ð Ø×$Ñ$ T§[¡[°$×2BÑ2BÓCˆAØ�K‰K×Ñ×"Ñ" 1Ô%Ø $ˆDÖñ !r*   )r…  rû  )TN)r`   ra   rb   rc   r1   rÿ  r  r\   re   rf   rg   rh   s   @@r'   rù  rù  ­  s    ù‡ € ÷"ò
pòk÷%ò %r*   rù  )1r‘   ÚloggingÚtypingr   r   r   r   r   r2   r   r	   r
   r   Útorch.nn.functionalrÕ   rV   ÚbitsandbytesrÔ   Úbitsandbytes.functionalr   r   r   r   Úbitsandbytes.optimr   Úbitsandbytes.utilsr   r   Ú	getLoggerr`   r)  r   rj   r   Ú	Parameterry   r,  ÚLinearrƒ   rV  r_  rd  r’  r”  r'  rÂ  rË  rÏ  rù  r<   r*   r'   Ú<module>r     sS  ðó
 Û ß :Õ :ã ß +Ó +ß Ð ã ÷ó õ 2ß Xà	×	Ò	˜8Ó	$€áˆCÐ(Ô)€ôg4�e—h‘h×(Ñ(ô g4ôTL�—‘×"Ñ"ô Lô^OE�—‘×#Ñ#ô OEõd3ô"Ea�—‘ô EaôP!
�
ô !
ôH(
�
ô (
ôVZ�—‘×#Ñ#ô ZòzXô*,%�B—L‘Lô ,%ô^a�B—L‘Lô aôH
�=ô 
ô&
�=ô 
ô&p�2—9‘9ô pôf%˜Ÿ™ö %r*   