
    
3jv                         S r SSKrSSKJrJr  SSKJr  SSKJr  SSK	J
r
JrJrJrJrJrJr  SSKJr  SS	KJr  \\\\\\S
.r\
\
\\\\S
.r " S S5      rg)z
Adapted from
https://github.com/huggingface/transformers/blob/c409cd81777fb27aadc043ed3d8339dbc020fb3b/src/transformers/quantizers/auto.py
    N   )BnB4BitDiffusersQuantizerBnB8BitDiffusersQuantizer)GGUFQuantizer)NVIDIAModelOptQuantizer)BitsAndBytesConfigGGUFQuantizationConfigNVIDIAModelOptConfigQuantizationConfigMixinQuantizationMethodQuantoConfigTorchAoConfig)QuantoQuantizer)TorchAoHfQuantizer)bitsandbytes_4bitbitsandbytes_8bitggufquantotorchaomodeloptc                       \ rS rSrSr\S\4S j5       r\S\\-  4S j5       r	\S 5       r
\S\\-  S\S	-  4S
 j5       rSrg	)DiffusersAutoQuantizer8   z
 The auto diffusers quantizer class that takes care of automatically instantiating to the correct
`DiffusersQuantizer` given the `QuantizationConfig`.
quantization_config_dictc           	         UR                  SS 5      nUR                  SS5      (       d  UR                  SS5      (       a/  UR                  SS5      (       a  SOSn[        R                  U-   nOUc  [        S5      eU[        R                  5       ;  a,  [        SU S	[        [        R                  5       5       35      e[        U   nUR                  U5      $ )
Nquant_methodload_in_8bitFload_in_4bit_4bit_8bitzThe model's quantization config from the arguments has no `quant_method` attribute. Make sure that the model has been correctly quantizedUnknown quantization type, got  - supported types are: )	getr   BITS_AND_BYTES
ValueError AUTO_QUANTIZATION_CONFIG_MAPPINGkeyslistAUTO_QUANTIZER_MAPPING	from_dict)clsr   r   suffix
target_clss        S/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/quantizers/auto.pyr*    DiffusersAutoQuantizer.from_dict>   s    /33NDI#''>>BZB^B^_motBuBu 8 < <^U S SWY`F-<<vEL! \  ?DDFF1, @/44678: 
 6lC
##$<==    quantization_configc           	      r   [        U[        5      (       a  U R                  U5      nUR                  nU[        R
                  :X  a  UR                  (       a  US-  nOUS-  nU[        R                  5       ;  a,  [        SU S[        [        R                  5       5       35      e[        U   nU" U40 UD6$ )Nr    r   r!   r"   )
isinstancedictr*   r   r   r$   r   r)   r'   r%   r(   )r+   r1   kwargsr   r-   s        r.   from_config"DiffusersAutoQuantizer.from_configS   s     )400"%--0C"D*77 -<<<"//''5::<<1, @/44678: 
 ,L9
-888r0   c                     U R                   " U40 UD6n[        USS 5      c  [        SU S35      eUR                  nU R	                  U5      nUR                  U5        U R                  U5      $ )Nr1   z)Did not found a `quantization_config` in z2. Make sure that the model is correctly quantized.)load_configgetattrr%   r1   r*   updater6   )r+   pretrained_model_name_or_pathr5   model_configr   r1   s         r.   from_pretrained&DiffusersAutoQuantizer.from_pretrainedl   s    'DOO<!6=E;<Y;Z  [M  N  $0#C#C !mm,DE""6*233r0   quantization_config_from_argsNc                     Ub  SnOSn[        U[        5      (       a  U R                  U5      n[        U[        5      (       a  UR	                  5         US:w  a  [
        R                  " U5        U$ )zt
handles situations where both quantization_config from args and quantization_config from model config are
present.
zYou passed `quantization_config` or equivalent parameters to `from_pretrained` but the model you're loading already has a `quantization_config` attribute. The `quantization_config` from the model will be used. )r3   r4   r*   r
   check_model_patchingwarningswarn)r+   r1   r@   warning_msgs       r.   merge_quantization_configs1DiffusersAutoQuantizer.merge_quantization_configsz   so     )4y 
 K)400"%--0C"D)+?@@446"MM+&""r0    )__name__
__module____qualname____firstlineno____doc__classmethodr4   r*   r   r6   r>   rG   __static_attributes__rI   r0   r.   r   r   8   s    
 > > >( 9.E.L 9 90 4 4 #!$;;# (?'E# #r0   r   )rN   rD   bitsandbytesr   r   r   r   r   r   r1   r   r	   r
   r   r   r   r   r   r   r   r   r)   r&   r   rI   r0   r.   <module>rR      ss   
  N  -   $ ' 32!'  ,+"$$  ]# ]#r0   