+
    QV-jt9  ã                   óŠ  € ^ RI t ^RIHt ^RIHtHt ^RIHtHtH	t	H
t
Ht ]	! 4       '       d   ^ RIt]
! 4       '       d   ^ RIt^ RIHt ^RIHt ]! 4       '       d   ^ RIt^ RIHtHt ]P.                  ! ]4      t ! R R]4      t ! R	 R
]4      t ! R R]4      t ! R R]4      tRR R lltRR R lltR t RR lt!RR lt"R# )é    N)ÚConversionOps)Úget_module_from_nameÚshould_convert_module)Úget_available_devicesÚis_accelerate_availableÚis_bitsandbytes_availableÚis_torch_availableÚlogging)ÚConv1D)Úadd_hook_to_moduleÚremove_hook_from_modulec                   ó<   a € ] tR t^t o R tRV 3R lR lltRtV tR# )ÚBnb4bitQuantizec                ó   € Wn         R # ©N©Úhf_quantizer©Úselfr   s   &&Úw/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/integrations/bitsandbytes.pyÚ__init__ÚBnb4bitQuantize.__init__   ó   € Ø(Öó    Nc          
      óÚ   <€ V ^8„  d   QhRS[ S[S[S[P                  ,          3,          RS[R,          RS[P
                  P                  R,          RS[ S[S[P                  3,          /# )é   Ú
input_dictÚfull_layer_nameNÚmodelÚreturn©ÚdictÚstrÚlistÚtorchÚTensorÚnnÚModule)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚBnb4bitQuantize.__annotate__"   se   ø€ ÷ ñ á™™d¡5§<¡<Õ0Ð0Õ1ðñ ˜t�ðñ �x‰x�‰ Õ%ð	ñ 
‰c‘5—<‘<ÐÕ	 ñr   c                ó°  € / pVP                  4        F¿  w  rg\        V\        4      '       d
   V^ ,          p\        W64      w  r‰\	        VP
                  \        4      '       d   VP                  pVP                  V4      p
\        P                  P                  ! V3RR/V
P                  B P                  VP                  4      pRVn        WµV&   KÁ  	  V# )a*  
we need to store some parameters to create the quantized weight. For example, bnb requires 6 values that are stored in the checkpoint to recover the quantized weight. So we store them in a dict that it stored in hf_quantizer for now as we can't save it in the op since we create an op per tensor.
Úrequires_gradFT)ÚitemsÚ
isinstancer$   r   Ú
issubclassÚ
source_clsr   ÚTÚget_parameter_or_bufferÚbnbr'   Ú
Params4bitÚ__dict__ÚtoÚdeviceÚ_is_hf_initialized)r   r   r   r   ÚkwargsÚresultÚ
param_nameÚvalueÚmoduleÚ_Ú	old_valueÚ	new_values   &&&&,       r   ÚconvertÚBnb4bitQuantize.convert"   s¾   € ð ˆØ!+×!1Ñ!1Ö!3ÑˆJÜ˜%¤×&Ò&Ø˜a��ô -¨UÓ?‰IˆFô ˜&×+Ñ+¬V×4Ò4ØŸ™�à×5Ñ5°jÓAˆIÜŸ™×)Ò)¨%Ñ[¸uÐ[È	×HZÑHZÑ[×^Ñ^Ð_d×_kÑ_kÓlˆIØ(,ˆFÔ%Ø!*�:Óñ "4ð  ˆr   r   ©NN©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   rC   Ú__static_attributes__Ú__classdictcell__©r*   s   @r   r   r      s   ø‡ € ò)÷÷ ð r   r   c                   ó<   a € ] tR t^@t o R tRV 3R lR lltRtV tR# )ÚBnb4bitDeserializec                ó   € Wn         R # r   r   r   s   &&r   r   ÚBnb4bitDeserialize.__init__A   r   r   Nc          
      óÚ   <€ V ^8„  d   QhRS[ S[S[S[P                  ,          3,          RS[P
                  P                  R,          RS[R,          RS[ S[S[P                  3,          /# ©r   r   r   Nr   r    r!   )r)   r*   s   "€r   r+   ÚBnb4bitDeserialize.__annotate__D   se   ø€ ÷ 'ñ 'á™™d¡5§<¡<Õ0Ð0Õ1ð'ñ �x‰x�‰ Õ%ð'ñ ˜t�ð	'ñ 
‰c‘5—<‘<ÐÕ	 ñ'r   c                ób  € \        V4      ^8X  d   V# VP                  4        F(  w  rV\        V\        4      '       g   K  V^ ,          W&   K*  	  RpVP	                  V4      p\        W#4      w  rš\        P                  P                  P                  VVRVP                  V	R7      pRV	n        W{/# )zO
Deserialization of bnb keys. We need 6 keys to recreate the quantized weights
ÚweightF)ÚdataÚquantized_statsr.   r9   r?   T)Úlenr/   r0   r$   Úpopr   r5   r'   r6   Úfrom_prequantizedr9   r:   )r   r   r   r   r;   Úkeyr>   Ú
key_weightrV   r?   r@   rB   s   &&&&,       r   rC   ÚBnb4bitDeserialize.convertD   s©   € ô ˆz‹?˜aÔØÐà$×*Ñ*Ö,‰JˆCÜ˜%¤×&Ô&Ø"'¨¥(�
“ñ -ð ˆ
Ø—‘ 
Ó+ˆÜ(¨Ó@‰	ˆÜ—F‘F×%Ñ%×7Ñ7ØØ&ØØ—=‘=Øð 8ó 
ˆ	ð %)ˆÔ!ØÐ&Ð&r   r   rE   rF   rM   s   @r   rO   rO   @   s   ø‡ € ò)÷'÷ 'ð 'r   rO   c                   ó<   a € ] tR t^ct o R tRV 3R lR lltRtV tR# )ÚBnb8bitQuantizec                ó   € Wn         R # r   r   r   s   &&r   r   ÚBnb8bitQuantize.__init__d   r   r   Nc          
      óÚ   <€ V ^8„  d   QhRS[ S[S[S[P                  ,          3,          RS[P
                  P                  R,          RS[R,          RS[ S[S[P                  3,          /# rS   r!   )r)   r*   s   "€r   r+   ÚBnb8bitQuantize.__annotate__g   se   ø€ ÷ ñ á™™d¡5§<¡<Õ0Ð0Õ1ðñ �x‰x�‰ Õ%ðñ ˜t�ð	ñ 
‰c‘5—<‘<ÐÕ	 ñr   c                óì  € / pVP                  4        FÝ  w  rg\        V\        4      '       d
   V^ ,          MTp\        W&4      w  r‰\	        VP
                  \        4      '       d   VP                  pVP                  p
VP                  V4      P                  pVP                  RR4       \        P                  P                  ! VP                  R4      3RR/VB P                  V
4      pWÅV&   Kß  	  V# )r   ÚSCBNÚcpur.   F)r/   r0   r$   r   r1   r2   r   r3   r9   r4   r7   rZ   r5   r'   Ú
Int8Paramsr8   )r   r   r   r   r;   r<   r=   r>   r?   r@   Úvalue_deviceÚparams_kwargsrB   s   &&&&,        r   rC   ÚBnb8bitQuantize.convertg   sÑ   € ð ˆØ!+×!1Ñ!1Ö!3ÑˆJÜ *¨5´$× 7Ò 7�E˜!–H¸UˆEä,¨UÓ?‰IˆFô ˜&×+Ñ+¬V×4Ò4ØŸ™�Ø Ÿ<™<ˆLØ!×9Ñ9¸*ÓE×NÑNˆMØ×Ñ˜e TÔ*ÜŸ™×)Ò)¨%¯(©(°5«/Ñ`ÈÐ`ÐR_Ñ`×cÑcÐdpÓqˆIØ!*�:Óñ "4ð ˆr   r   rE   rF   rM   s   @r   r`   r`   c   s   ø‡ € ò)÷÷ ð r   r`   c                   ó<   a € ] tR t^€t o R tRV 3R lR lltRtV tR# )ÚBnb8bitDeserializec                ó   € Wn         R # r   r   r   s   &&r   r   ÚBnb8bitDeserialize.__init__�   r   r   Nc          
      óÚ   <€ V ^8„  d   QhRS[ S[S[S[P                  ,          3,          RS[P
                  P                  R,          RS[R,          RS[ S[S[P                  3,          /# rS   r!   )r)   r*   s   "€r   r+   ÚBnb8bitDeserialize.__annotate__„   se   ø€ ÷ 'ñ 'á™™d¡5§<¡<Õ0Ð0Õ1ð'ñ �x‰x�‰ Õ%ð'ñ ˜t�ð	'ñ 
‰c‘5—<‘<ÐÕ	 ñ'r   c                ó¦  € \        V4      ^8X  d   V# VP                  4        F(  w  rV\        V\        4      '       g   K  V^ ,          W&   K*  	  \	        W#4      w  rxRp	W,          p
VP                  V4      P                  pVR,          VR&   \        P                  P                  ! V
3RR/VB P                  V
P                  4      pRVn        W›/# )z
Deserialization of bnb keys.
rV   rf   r.   FT)rY   r/   r0   r$   r   r4   r7   r5   r'   rh   r8   r9   r:   )r   r   r   r   r;   r\   r>   r?   r@   r]   rV   rB   s   &&&&,       r   rC   ÚBnb8bitDeserialize.convert„   sÅ   € ô ˆz‹?˜aÔð Ðà$×*Ñ*Ö,‰JˆCÜ˜%¤×&Ô&Ø"'¨¥(�
“ñ -ô )¨Ó@‰	ˆàˆ
ØÕ'ˆØ×.Ñ.¨Ó?×HÑHˆØ" 5Õ)ˆˆu‰Ü—F‘F×%Ò% fÑL¸EÐLÀVÑL×OÑOÐPV×P]ÑP]Ó^ˆ	Ø$(ˆÔ!ØÐ&Ð&r   r   rE   rF   rM   s   @r   rm   rm   €   s   ø‡ € ò)÷'÷ 'ð 'r   rm   c                ó|   € V ^8„  d   QhR\         P                  P                  R\        \        ,          R,          /# )r   r   Úmodules_to_not_convertN)r%   r'   r(   r$   r#   )r)   s   "r   r+   r+   ¢   s1   € ÷ Jñ JÜ�8‰8�?‰?ðJä ¤�I¨Õ,ñJr   c                ó  € RpV P                  4        EF;  w  rV\        WQ4      '       g   K  Rp\        P                  ! R4      ;_uu_ 4        \	        V\
        4      '       g   \        V4      \        P                  J EdÆ   \	        V\
        4      '       d   VP                  P                  w  r‰MVP                  pVP                  p	VP                  4       R8X  d‘   \        P                  P                  VV	VP                   RJVP"                  VP$                  R7      pV'       dD   VP                  P&                  P)                  \        P*                  R7      VP                  n        M¡\        P                  P-                  VV	VP                   RJVP.                  VP0                  VP2                  VP4                  R7      pV'       d@   VP                  P&                  P)                  VP4                  R7      VP                  n        Ve5   \        V4      Vn        VP9                  R4       V P;                  WW4       RpRRR4       EK>  	  V'       g   \<        P?                  R	4       V #   + '       g   i     EKq  ; i)
a¢  
A helper function to replace all `torch.nn.Linear` modules by bnb modules from the `bitsandbytes` library.

Args:
    model (`torch.nn.Module`):
        The model to convert, can be any `torch.nn.Module` instance.
    modules_to_not_convert (`list[str]`, defaults to `None`):
        A list of nn.Linear weights to not convert. If a parameter path is in the list (e.g. `lm_head.weight`), the corresponding module will not be
        converted.
    quantization_config (`BitsAndBytesConfig`):
        The quantization config object that contains the quantization parameters.
    pre_quantized (`book`, defaults to `False`):
        Whether the model is pre-quantized or not
FNÚmetaÚllm_int8)Úhas_fp16_weightsÚ	threshold)Údtype)Úcompress_statisticsÚ
quant_typeÚquant_storageTz»You are loading your model using eetq but no linear modules were found in your model. Please double check your model architecture, or submit an issue on github if you think this is a bug.) Únamed_modulesr   r%   r9   r0   r   Útyper'   ÚLinearrV   ÚshapeÚin_featuresÚout_featuresÚquantization_methodr5   ÚLinear8bitLtÚbiasÚllm_int8_has_fp16_weightÚllm_int8_thresholdrW   r8   Úint8Ú
Linear4bitÚbnb_4bit_compute_dtypeÚbnb_4bit_use_double_quantÚbnb_4bit_quant_typeÚbnb_4bit_quant_storager2   Úrequires_grad_Úset_submoduleÚloggerÚwarning)
r   ru   Úquantization_configÚpre_quantizedÚhas_been_replacedÚmodule_namer?   Ú
new_modulerƒ   r„   s
   &&&&      r   Úreplace_with_bnb_linearr™   ¢   s  € ð( Ðà$×2Ñ2×4ÑˆÜ$ [×IÒIÙØˆ
Ü�\Š\˜&×!Õ!Ü˜&¤&×)Ò)¬T°&«\¼R¿Y¹YÔ-FÜ˜f¤f×-Ò-Ø06·±×0CÑ0CÑ-�K à"(×"4Ñ"4�KØ#)×#6Ñ#6�LØ&×:Ñ:Ó<À
ÔJÜ!$§¡×!4Ñ!4Ø#Ø$ØŸ™¨4Ð/Ø)<×)UÑ)UØ"5×"HÑ"Hð "5ó "�J÷ %ð 2<×1BÑ1B×1GÑ1G×1JÑ1JÔQV×Q[ÑQ[Ð1JÓ1\˜
×)Ñ)Ô.øä!$§¡×!2Ñ!2Ø#Ø$ØŸ™¨4Ð/Ø+×BÑBØ,?×,YÑ,YØ#6×#JÑ#JØ&9×&PÑ&Pð "3ó "�J÷ %à1;×1BÑ1B×1GÑ1G×1JÑ1JØ"5×"LÑ"Lð 2Kó 2˜
×)Ñ)Ô.ð Ò)ä,0°«L�JÔ)à×-Ñ-¨eÔ4Ø×'Ñ'¨Ô@Ø(,Ð%÷Q "Ò!ñ	  5÷\ Ü�‰ðô	
ð
 €L÷a "×!Ñ!ús   ÁCI2Ä)B%I2ÇA7I2É2Jc                ó   € V ^8„  d   QhRR/# )r   rV   ztorch.nn.Parameter© )r)   s   "r   r+   r+   ð   s   € ÷ ñ Ð"6ñ r   c                ó”  € \        V \        P                  P                  4      '       g   \	        R\        V 4       R24      hV P                  P                  pVR9  d   V # VR8X  d7   \        P                  P                  V P                  V P                  4      pV# VP                  f   V P                  Vn        \        \        P                  R4      '       d7   \        P                  P                  V P                  VP                  4      pV# V P                  VP                  P!                  R^4      ,          R,          pV# )z‚
Helper function to dequantize 4bit or 8bit bnb weights.

If the weight is not a bnb quantized weight, it will be returned as is.
z1Input weight should be of type nn.Parameter, got z insteadr6   Úint8_vectorwise_dequantg   €@ €?)r6   rh   éÿÿÿÿ)r0   r%   r'   Ú	ParameterÚ	TypeErrorr€   Ú	__class__rG   r5   Ú
functionalÚdequantize_4bitrW   Úquant_staterf   Úhasattrr�   Úview)rV   ÚstateÚcls_nameÚoutput_tensorÚdequantizeds   &&   r   Údequantize_bnb_weightr«   ð   sû   € ô �fœeŸh™h×0Ñ0×1Ò1ÜÐKÌDÐQWËLÈ>ÐYaÐbÓcÐcà×Ñ×(Ñ(€HØÐ3Ô3Øˆà�<ÔÜŸ™×6Ñ6°v·{±{ÀF×DVÑDVÓWˆØÐà‡y�yÒØ—J‘JˆŒ	äŒs�~‰~Ð8×9Ò9ä—n‘n×<Ñ<¸V¿[¹[È%Ï)É)ÓTˆð
 Ðð —k‘k E§I¡I§N¡N°2°qÓ$9Õ9Ð<PÕPˆàÐr   c                ó  € \        \        P                  V P                  P                  4      pV P
                  p/ p\        P                  ! VP                  4      pV F  pWTP                  9   g   K  W%,          W5&   K!  	  V! R/ VB pV# )zó
Creates a new hook based on the old hook. Use it only if you know what you are doing !
This method is a copy of: https://github.com/huggingface/peft/blob/748f7968f3a31ec06a1c2b0328993319ad9a150a/src/peft/utils/other.py#L245
with some changes
r›   )
ÚgetattrÚ
accelerateÚhooksr¡   rG   r7   ÚinspectÚ	signaturer   Ú
parameters)Úold_hookÚold_hook_clsÚold_hook_attrÚfiltered_old_hook_attrÚold_hook_init_signatureÚkÚnew_hooks   &      r   Ú_create_accelerate_new_hookrº     s�   € ô œ:×+Ñ+¨X×-?Ñ-?×-HÑ-HÓI€LØ×%Ñ%€MØÐÜ%×/Ò/°×0EÑ0EÓFÐÛˆØ×2Ñ2Ö2Ø(5Õ(8Ð"Ó%ñ ñ Ñ5Ð4Ñ5€HØ€Or   c           	     ó   € VP                  4       pVR8X  d   \        P                  P                  M\        P                  P                  pV P                  4        EFì  w  rV\        Wd4      '       g   K  \        P                  ! R4      ;_uu_ 4        \        VRR4      p\        P                  P                  VP                  VP                  VRJR7      pRRR4       VR8X  d   VP                  MRp	\        P                  P                  \        VP                   V	4      4      Xn        \        VP                   V	4      p
Vf%   \"        P%                  RV
P&                   R24       M7\"        P%                  RV
P&                   RV R	24       V
P)                  V4      p
\        P                  P                  V
4      Vn        Xe   Wxn        \-        VR
4      '       d.   VP.                  p\1        V4      p\3        V4       \5        WŒ4       VP)                  VP                   P                  4       V P7                  WX4       RpEKï  	  X'       g   \"        P9                  R4       V #   + '       g   i     ELœ; i)a  
Converts a quantized model into its dequantized original version. The newly converted model will have
some performance drop compared to the original model before quantization - use it only for specific usecases
such as QLoRA adapters merging.

Returns the converted model.
rx   rw   r‡   N)r‡   zThe modules are dequantized in zK. If you want to change the dtype, please specify `dtype` in `dequantize`. z and casted to Ú.Ú_hf_hookTz_For some reason the model has not been properly dequantized. You might see unexpected behavior.)r…   r5   r'   r†   r‹   r   r0   r%   r9   r­   r�   rƒ   r„   r§   rŸ   r«   rV   r’   Úwarning_oncer{   r8   r‡   r¥   r½   rº   r   r   r‘   r“   )r   r”   r{   Úquant_methodÚ
target_clsr—   r?   r‡   r˜   r§   rV   r³   r¹   r–   s   &&&           r   Údequantize_and_replacerÁ     sî  € ð '×:Ñ:Ó<€Là(4¸
Ô(B”—‘×$Ò$ÌÏÉ×HYÑHY€JØ$×2Ñ2×4ÑˆÜ�f×)Ô)Ü—’˜f×%Õ%Ü˜v v¨tÓ4�Ü"ŸX™XŸ_™_¨V×-?Ñ-?À×ATÑATÐ[_ÐgkÐ[k˜_Ól�
÷ &ð %1°JÔ$>�F—L’LÀDˆEÜ %§¡× 2Ñ 2Ô3HÈÏÉÐX]Ó3^Ó _ˆJÔÜ*¨6¯=©=¸%Ó@ˆFØŠ}Ü×#Ñ#Ø5°f·l±l°^ð  DOð  Põô ×#Ñ#Ð&EÀfÇlÁlÀ^ÐSbÐchÐbiÐijÐ$kÔlØŸ™ 5Ó)�Ü %§¡× 2Ñ 2°6Ó :ˆJÔØÒØ"&”Ü�v˜z×*Ò*Ø!Ÿ?™?�Ü6°xÓ@�Ü'¨Ô/Ü" :Ô8Ø�M‰M˜&Ÿ-™-×.Ñ.Ô/Ø×Ñ Ô8Ø $Óñ3  5÷6 Ü�‰Ømô	
ð €L÷; &×%Ð%ús   ÂAI,É,I=c                ó  € \        \        R\        4       4      p\        \        4       4      pVP	                  V4      '       g>   V '       d   RT;'       g    R RV R2p\        V4      h\        P                  R4       R# R# )	zk
Validates if the available devices are supported by bitsandbytes, optionally raising an exception if not.
Úsupported_torch_devicesz3None of the available devices `available_devices = NzY` are supported by the bitsandbytes version you have installed: `bnb_supported_devices = z¢`. Please check the docs to see if the backend you intend to use is available and how to install it: https://huggingface.co/docs/bitsandbytes/main/en/installationz+No supported devices found for bitsandbytesFT)r­   r5   Úsetr   ÚintersectionÚRuntimeErrorr’   r“   )Úraise_exceptionÚbnb_supported_devicesÚavailable_devicesÚerr_msgs   &   r   Ú!validate_bnb_backend_availabilityrË   L  s“   € ô $¤CÐ)BÄCÃEÓJÐÜÔ1Ó3Ó4Ðà×)Ñ)Ð*?×@Ò@ßàEÐFW×F_ÐF_Ð[_ÐE`ð  azð  {Pð  zQð Qrð rð ô ˜wÓ'Ð'ä�‰ÐDÔEÙÙr   )NNFr   rE   )F)#r°   Úcore_model_loadingr   Úquantizers.quantizers_utilsr   r   Úutilsr   r   r   r	   r
   Úbitsandbytesr5   r%   Útorch.nnr'   Úpytorch_utilsr   r®   Úaccelerate.hooksr   r   Ú
get_loggerrG   r’   r   rO   r`   rm   r™   r«   rº   rÁ   rË   r›   r   r   Ú<module>rÔ      s¦   ðÛ å .ß U÷õ ñ ×ÒÛá×ÒÛÝå&á×ÒÛßLà	×	Ò	˜HÓ	%€ô�mô ôD '˜ô  'ôF�mô ô:'˜ô '÷DJ÷\ò<ô"*öZr   