
    +h                         S r SSKrSSKJrJrJr  SSKJrJr  SSK	J
r
  SSK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)DictOptionalUnion   )BnB4BitDiffusersQuantizerBnB8BitDiffusersQuantizer)GGUFQuantizer)BitsAndBytesConfigGGUFQuantizationConfigQuantizationConfigMixinQuantizationMethodQuantoConfigTorchAoConfig)QuantoQuantizer)TorchAoHfQuantizer)bitsandbytes_4bitbitsandbytes_8bitggufquantotorchaoc                       \ rS rSrSr\S\4S j5       r\S\\	\4   4S j5       r
\S 5       r\S\\\	4   S\\	   4S	 j5       rS
rg)DiffusersAutoQuantizer5   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/james-whalen/.local/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_configP   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_pretrainedi   s    'DOO<!6=E;<Y;Z  [M  N  $0#C#C !mm,DE""6*233r0   quantization_config_from_argsc                     Ub  SnOSn[        U[        5      (       a  U R                  U5      n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*   warningswarn)r+   r1   r@   warning_msgs       r.   merge_quantization_configs1DiffusersAutoQuantizer.merge_quantization_configsw   sT     )4y 
 K)400"%--0C"D"MM+&""r0    N)__name__
__module____qualname____firstlineno____doc__classmethodr   r*   r   r   r6   r>   r4   r   rF   __static_attributes__rH   r0   r.   r   r   5   s    
 > > >( 9e4KT4Q.R 9 90 4 4 #"4)@#@A# (00G'H# #r0   r   )rM   rC   typingr   r   r   bitsandbytesr   r   r   r	   r1   r
   r   r   r   r   r   r   r   r   r   r)   r&   r   rH   r0   r.   <module>rR      sk   
  ( ( N   $ ' 32!  ,+"$  Z# Z#r0   