ó
    oM‡j«  ã                  óø  • S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSK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  \" 5       (       a  SSKr\R0                  " \5      r " S
 S\\5      r\
 " S S5      5       r\
 " S S\5      5       r\
 " S S\5      5       r\
 " S S\5      5       r \
 " S S\5      5       r!\
 " S S\5      5       r"\
 " S S\5      5       r#\
 " S S\5      5       r$ " S S\5      r%g)z–
Adapted from
https://github.com/huggingface/transformers/blob/52cb4034ada381fe1ffe8d428a1076e5411a8026/src/transformers/utils/quantization_config.py
é    )ÚannotationsN)Ú	dataclass)ÚEnum)ÚAnyÚCallable)Úversioné   )Ú	deprecateÚis_torch_availableÚis_torchao_versionÚloggingc                  ó4   • \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rg)ÚQuantizationMethodé-   ÚbitsandbytesÚggufÚnunchaku_liteÚtorchaoÚquantoÚmodeloptz
auto-roundÚsdnq© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚBITS_AND_BYTESÚGGUFÚNUNCHAKU_LITEÚTORCHAOÚQUANTOÚMODELOPTÚ	AUTOROUNDÚSDNQÚ__static_attributes__r   ó    Ú¶C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\diffusers/quantizers/quantization_config.pyr   r   -   s*   † Ø#€NØ€DØ#€MØ€GØ€FØ€HØ€IØƒDr&   r   c                  óp   • \ rS rSr% SrS\S'   / r\SS j5       rSS jr	SS jr
S rS	 rSSS
 jjrS rSrg)ÚQuantizationConfigMixiné8   z%
Mixin class for quantization config
r   Úquant_methodc                óô   • U " S0 UD6n/ nUR                  5        H4  u  pg[        XF5      (       d  M  [        XFU5        UR                  U5        M6     U H  nUR	                  US5        M     U(       a  XC4$ U$ )an  
Instantiates a [`QuantizationConfigMixin`] from a Python dictionary of parameters.

Args:
    config_dict (`dict[str, Any]`):
        Dictionary that will be used to instantiate the configuration object.
    return_unused_kwargs (`bool`, *optional*, defaults to `False`):
        Whether or not to return a list of unused keyword arguments. Used for `from_pretrained` method in
        `PreTrainedModel`.
    kwargs (`dict[str, Any]`):
        Additional parameters from which to initialize the configuration object.

Returns:
    [`QuantizationConfigMixin`]: The configuration object instantiated from those parameters.
Nr   )ÚitemsÚhasattrÚsetattrÚappendÚpop)ÚclsÚconfig_dictÚreturn_unused_kwargsÚkwargsÚconfigÚ	to_removeÚkeyÚvalues           r'   Ú	from_dictÚ!QuantizationConfigMixin.from_dictA   sw   € ñ$ Ñ#�{Ñ#ˆàˆ	Ø Ÿ,™,ž.‰JˆCÜ�v×#Ó#Ü˜ UÔ+Ø× Ñ  Ö%ñ )ó ˆCØ�J‰J�s˜DÖ!ñ ö  Ø�>Ð!àˆMr&   c                óÂ   • [        USSS9 nU R                  5       n[        R                  " USSS9S-   nUR	                  U5        SSS5        g! , (       d  f       g= f)	aƒ  
Save this instance to a JSON file.

Args:
    json_file_path (`str` or `os.PathLike`):
        Path to the JSON file in which this configuration instance's parameters will be saved.
    use_diff (`bool`, *optional*, defaults to `True`):
        If set to `True`, only the difference between the config instance and the default
        `QuantizationConfig()` is serialized to JSON file.
Úwzutf-8)Úencodingr	   T©ÚindentÚ	sort_keysÚ
N)ÚopenÚto_dictÚjsonÚdumpsÚwrite)ÚselfÚjson_file_pathÚwriterr3   Újson_strings        r'   Úto_json_fileÚ$QuantizationConfigMixin.to_json_fileb   sL   € ô �. #°Ò8¸FØŸ,™,›.ˆKÜŸ*š* [¸ÀdÑKÈdÑRˆKà�L‰L˜Ô%÷	 9×8Ö8ús   Œ;AÁ
Ac                óB   • [         R                  " U R                  5      $ )úœ
Serializes this instance to a Python dictionary. Returns:
    `dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance.
)ÚcopyÚdeepcopyÚ__dict__©rH   s    r'   rD   ÚQuantizationConfigMixin.to_dicts   s   € ô
 �}Š}˜TŸ]™]Ó+Ð+r&   c              #  ó„   #   • [         R                  " U R                  5      R                  5        H
  u  pX4v •  M     g7f)zTallows `dict(obj)` for situations where obj may be a dict or QuantizationConfigMixinN)rP   rQ   rR   r-   )rH   Úattrr9   s      r'   Ú__iter__Ú QuantizationConfigMixin.__iter__z   s0   é € äŸ=š=¨¯©Ó7×=Ñ=Ö?‰KˆDØ�+Ôò @ùs   ‚>A c                óT   • U R                   R                   SU R                  5        3$ )NÚ )Ú	__class__r   Úto_json_stringrS   s    r'   Ú__repr__Ú QuantizationConfigMixin.__repr__   s(   € Ø—.‘.×)Ñ)Ð*¨!¨D×,?Ñ,?Ó,AÐ+BÐCÐCr&   c                ó€   • USL a  U R                  5       nOU R                  5       n[        R                  " USSS9S-   $ )ar  
Serializes this instance to a JSON string.

Args:
    use_diff (`bool`, *optional*, defaults to `True`):
        If set to `True`, only the difference between the config instance and the default `PretrainedConfig()`
        is serialized to JSON string.

Returns:
    `str`: String containing all the attributes that make up this configuration instance in JSON format.
Tr	   r?   rB   )Úto_diff_dictrD   rE   rF   )rH   Úuse_diffr3   s      r'   r\   Ú&QuantizationConfigMixin.to_json_string‚   s=   € ð �tÒØ×+Ñ+Ó-‰KàŸ,™,›.ˆKÜ�zŠz˜+¨a¸4Ñ@À4ÑGÐGr&   c                óü   • / nUR                  5        H4  u  p4[        X5      (       d  M  [        XU5        UR                  U5        M6     UR                  5        VVs0 s H  u  p4X2;  d  M  X4_M     nnnU$ s  snnf )ao  
Updates attributes of this class instance with attributes from `kwargs` if they match existing attributes,
returning all the unused kwargs.

Args:
    kwargs (`dict[str, Any]`):
        Dictionary of attributes to tentatively update this class.

Returns:
    `dict[str, Any]`: Dictionary containing all the key-value pairs that were not used to update the instance.
)r-   r.   r/   r0   )rH   r5   r7   r8   r9   Úunused_kwargss         r'   ÚupdateÚQuantizationConfigMixin.update”   sq   € ð ˆ	Ø Ÿ,™,ž.‰JˆCÜ�t×!Ó!Ü˜ 5Ô)Ø× Ñ  Ö%ñ )ð 7=·l±l´nÔ]²n©
¨ÈÑH\›˜š±nˆÑ]ØÐùó ^s   ÁA8Á-A8r   N©F)rI   zstr | os.PathLike©Úreturnzdict[str, Any])T)ra   Úboolri   Ústr)r   r   r   r   Ú__doc__Ú__annotations__Ú_exclude_attributes_at_initÚclassmethodr:   rL   rD   rW   r]   r\   re   r%   r   r&   r'   r)   r)   8   sH   ‡ ñð %Ó$Ø"$Ðàóó ðô@&ô",òò
DöHõ$r&   r)   c                  óÚ   • \ rS rSrSr/ SQr          SS jr\S 5       r\R                  SS j5       r\S 5       r
\
R                  SS	 j5       r
S
 rS rS rSS jrS rSS jrSrg)ÚBitsAndBytesConfigé«   aÉ  
This is a wrapper class about all possible attributes and features that you can play with a model that has been
loaded using `bitsandbytes`.

This replaces `load_in_8bit` or `load_in_4bit` therefore both options are mutually exclusive.

Currently only supports `LLM.int8()`, `FP4`, and `NF4` quantization. If more methods are added to `bitsandbytes`,
then more arguments will be added to this class.

Args:
    load_in_8bit (`bool`, *optional*, defaults to `False`):
        This flag is used to enable 8-bit quantization with LLM.int8().
    load_in_4bit (`bool`, *optional*, defaults to `False`):
        This flag is used to enable 4-bit quantization by replacing the Linear layers with FP4/NF4 layers from
        `bitsandbytes`.
    llm_int8_threshold (`float`, *optional*, defaults to 6.0):
        This corresponds to the outlier threshold for outlier detection as described in `LLM.int8() : 8-bit Matrix
        Multiplication for Transformers at Scale` paper: https://huggingface.co/papers/2208.07339 Any hidden states
        value that is above this threshold will be considered an outlier and the operation on those values will be
        done in fp16. Values are usually normally distributed, that is, most values are in the range [-3.5, 3.5],
        but there are some exceptional systematic outliers that are very differently distributed for large models.
        These outliers are often in the interval [-60, -6] or [6, 60]. Int8 quantization works well for values of
        magnitude ~5, but beyond that, there is a significant performance penalty. A good default threshold is 6,
        but a lower threshold might be needed for more unstable models (small models, fine-tuning).
    llm_int8_skip_modules (`list[str]`, *optional*):
        An explicit list of the modules that we do not want to convert in 8-bit. This is useful for models such as
        Jukebox that has several heads in different places and not necessarily at the last position. For example
        for `CausalLM` models, the last `lm_head` is typically kept in its original `dtype`.
    llm_int8_enable_fp32_cpu_offload (`bool`, *optional*, defaults to `False`):
        This flag is used for advanced use cases and users that are aware of this feature. If you want to split
        your model in different parts and run some parts in int8 on GPU and some parts in fp32 on CPU, you can use
        this flag. This is useful for offloading large models such as `google/flan-t5-xxl`. Note that the int8
        operations will not be run on CPU.
    llm_int8_has_fp16_weight (`bool`, *optional*, defaults to `False`):
        This flag runs LLM.int8() with 16-bit main weights. This is useful for fine-tuning as the weights do not
        have to be converted back and forth for the backward pass.
    bnb_4bit_compute_dtype (`torch.dtype` or str, *optional*, defaults to `torch.float32`):
        This sets the computational type which might be different than the input type. For example, inputs might be
        fp32, but computation can be set to bf16 for speedups.
    bnb_4bit_quant_type (`str`,  *optional*, defaults to `"fp4"`):
        This sets the quantization data type in the bnb.nn.Linear4Bit layers. Options are FP4 and NF4 data types
        which are specified by `fp4` or `nf4`.
    bnb_4bit_use_double_quant (`bool`, *optional*, defaults to `False`):
        This flag is used for nested quantization where the quantization constants from the first quantization are
        quantized again.
    bnb_4bit_quant_storage (`torch.dtype` or str, *optional*, defaults to `torch.uint8`):
        This sets the storage type to pack the quanitzed 4-bit prarams.
    kwargs (`dict[str, Any]`, *optional*):
        Additional parameters from which to initialize the configuration object.
)Ú_load_in_4bitÚ_load_in_8bitr+   Nc                ó¨  ^ • [         R                  T l        U(       a  U(       a  [        S5      eUT l        UT l        UT l        UT l        UT l        UT l	        UT l
        U	T l        Uc  [        R                  T l        O][        U[         5      (       a  [#        [        U5      T l        O2[        U[        R$                  5      (       a  UT l        O[        S5      eU
c  [        R&                  T l        On[        U
[         5      (       a'  U
S;  a  [        S5      e[#        [        U
5      T l        O2[        U
[        R$                  5      (       a  U
T l        O[        S5      eU(       aW  [+        U 4S jU 5       5      (       d=  [,        R/                  S[1        UR3                  5       5       ST R4                   S	35        T R7                  5         g )
NúVload_in_4bit and load_in_8bit are both True, but only one can be used at the same timez8bnb_4bit_compute_dtype must be a string or a torch.dtype)Úfloat16Úfloat32Úint8Úuint8Úfloat64Úbfloat16zv`bnb_4bit_quant_storage` must be a valid string (one of 'float16', 'float32', 'int8', 'uint8', 'float64', 'bfloat16') z8bnb_4bit_quant_storage must be a string or a torch.dtypec              3  ó@   >#   • U  H  oTR                   ;   v •  M     g 7f©N)rn   )Ú.0ÚkrH   s     €r'   Ú	<genexpr>Ú.BitsAndBytesConfig.__init__.<locals>.<genexpr>  s   øé € ÐTÊVÈ 4×#CÑ#CÖCÊVùs   ƒzUnused kwargs: z. These kwargs are not used in Ú.)r   r   r+   Ú
ValueErrorrt   rs   Úllm_int8_thresholdÚllm_int8_skip_modulesÚ llm_int8_enable_fp32_cpu_offloadÚllm_int8_has_fp16_weightÚbnb_4bit_quant_typeÚbnb_4bit_use_double_quantÚtorchrx   Úbnb_4bit_compute_dtypeÚ
isinstancerk   ÚgetattrÚdtyperz   Úbnb_4bit_quant_storageÚallÚloggerÚwarningÚlistÚkeysr[   Ú	post_init)rH   Úload_in_8bitÚload_in_4bitr…   r†   r‡   rˆ   rŒ   r‰   rŠ   r�   r5   s   `           r'   Ú__init__ÚBitsAndBytesConfig.__init__â   s‚  ø€ ô /×=Ñ=ˆÔæžLÜÐuÓvÐvà)ˆÔØ)ˆÔØ"4ˆÔØ%:ˆÔ"Ø0PˆÔ-Ø(@ˆÔ%Ø#6ˆÔ Ø)BˆÔ&à!Ñ)Ü*/¯-©-ˆDÕ'ÜÐ.´×4Ñ4Ü*1´%Ð9OÓ*PˆDÕ'ÜÐ.´·±×<Ñ<Ø*@ˆDÕ'äÐWÓXÐXà!Ñ)Ü*/¯+©+ˆDÕ'ÜÐ.´×4Ñ4Ø%ð .ó ô !ð Móð ô +2´%Ð9OÓ*PˆDÕ'ÜÐ.´·±×<Ñ<Ø*@ˆDÕ'äÐWÓXÐXæœ#ÔTÉVÓT×TÑTÜ�N‰N˜_¬T°&·+±+³-Ó-@Ð,AÐA`Ðae×aoÑaoÐ`pÐpqÐrÔsà�‰Õr&   c                ó   • U R                   $ r~   )rs   rS   s    r'   r˜   ÚBitsAndBytesConfig.load_in_4bit   ó   € à×!Ñ!Ð!r&   c                ó–   • [        U[        5      (       d  [        S5      eU R                  (       a  U(       a  [	        S5      eXl        g )Núload_in_4bit must be a booleanrv   )r�   rj   Ú	TypeErrorr—   r„   rs   ©rH   r9   s     r'   r˜   rœ   $  ó8   € ä˜%¤×&Ñ&ÜÐ<Ó=Ð=à××¦ÜÐuÓvÐvØ"Õr&   c                ó   • U R                   $ r~   )rt   rS   s    r'   r—   ÚBitsAndBytesConfig.load_in_8bit-  r�   r&   c                ó–   • [        U[        5      (       d  [        S5      eU R                  (       a  U(       a  [	        S5      eXl        g )Núload_in_8bit must be a booleanrv   )r�   rj   r    r˜   r„   rt   r¡   s     r'   r—   r¤   1  r¢   r&   c                ó  • [        U R                  [        5      (       d  [        S5      e[        U R                  [        5      (       d  [        S5      e[        U R
                  [        5      (       d  [        S5      eU R                  b*  [        U R                  [        5      (       d  [        S5      e[        U R                  [        5      (       d  [        S5      e[        U R                  [        5      (       d  [        S5      eU R                  b4  [        U R                  [        R                  5      (       d  [        S5      e[        U R                  [        5      (       d  [        S	5      e[        U R                   [        5      (       d  [        S
5      eU R                  (       aW  ["        R$                  " [&        R(                  R#                  S5      5      ["        R$                  " S5      :¼  d  [+        S5      egg)zn
Safety checker that arguments are correct - also replaces some NoneType arguments with their default values.
rŸ   r¦   z"llm_int8_threshold must be a floatNz/llm_int8_skip_modules must be a list of stringsz2llm_int8_enable_fp32_cpu_offload must be a booleanz*llm_int8_has_fp16_weight must be a booleanz*bnb_4bit_compute_dtype must be torch.dtypez$bnb_4bit_quant_type must be a stringz+bnb_4bit_use_double_quant must be a booleanr   z0.39.0z[4 bit quantization requires bitsandbytes>=0.39.0 - please upgrade your bitsandbytes version)r�   r˜   rj   r    r—   r…   Úfloatr†   r”   r‡   rˆ   rŒ   r‹   r�   r‰   rk   rŠ   r   ÚparseÚ	importlibÚmetadatar„   rS   s    r'   r–   ÚBitsAndBytesConfig.post_init:  s�  € ô ˜$×+Ñ+¬T×2Ñ2ÜÐ<Ó=Ð=ä˜$×+Ñ+¬T×2Ñ2ÜÐ<Ó=Ð=ä˜$×1Ñ1´5×9Ñ9ÜÐ@ÓAÐAà×%Ñ%Ñ1¼*ÀT×E_ÑE_Ôae×:fÑ:fÜÐMÓNÐNÜ˜$×?Ñ?Ä×FÑFÜÐPÓQÐQä˜$×7Ñ7¼×>Ñ>ÜÐHÓIÐIà×&Ñ&Ñ2¼:Àd×FaÑFaÔch×cnÑcn×;oÑ;oÜÐHÓIÐIä˜$×2Ñ2´C×8Ñ8ÜÐBÓCÐCä˜$×8Ñ8¼$×?Ñ?ÜÐIÓJÐJà××¤W§]¢]´9×3EÑ3E×3MÑ3MÈnÓ3]Ó%^Ôbi×boÒboØóc
ó &
ô Ømóð ð&
Ðr&   c                ó@   • U R                   =(       d    U R                  $ )z@
Returns `True` if the model is quantizable, `False` otherwise.
)r—   r˜   rS   s    r'   Úis_quantizableÚ!BitsAndBytesConfig.is_quantizable_  s   € ð × Ñ ×5 D×$5Ñ$5Ð5r&   c                ó°   • U R                   (       a  gU R                  (       a  U R                  S:X  a  gU R                  (       a  U R                  S:X  a  gg)zu
This method returns the quantization method used for the model. If the model is not quantizable, it returns
`None`.
Úllm_int8Úfp4Únf4N)r—   r˜   r‰   rS   s    r'   Úquantization_methodÚ&BitsAndBytesConfig.quantization_methode  sE   € ð
 ××ØØ×× 4×#;Ñ#;¸uÓ#DØØ×× 4×#;Ñ#;¸uÓ#DØàr&   c                ó  • [         R                  " U R                  5      n[        US   5      R	                  S5      S   US'   [        US   5      R	                  S5      S   US'   U R
                  US'   U R                  US'   U$ )rO   rŒ   rƒ   é   r�   r˜   r—   )rP   rQ   rR   rk   Úsplitr˜   r—   )rH   Úoutputs     r'   rD   ÚBitsAndBytesConfig.to_dicts  s‹   € ô
 —’˜tŸ}™}Ó-ˆÜ+.¨vÐ6NÑ/OÓ+P×+VÑ+VÐWZÓ+[Ð\]Ñ+^ˆÐ'Ñ(Ü+.¨vÐ6NÑ/OÓ+P×+VÑ+VÐWZÓ+[Ð\]Ñ+^ˆÐ'Ñ(Ø!%×!2Ñ!2ˆˆ~ÑØ!%×!2Ñ!2ˆˆ~Ñàˆr&   c                ó‚   • U R                  5       nU R                  R                   S[        R                  " USSS9 S3$ ©NrZ   r	   Tr?   rB   ©rD   r[   r   rE   rF   ©rH   r3   s     r'   r]   ÚBitsAndBytesConfig.__repr__€  ó;   € Ø—l‘l“nˆØ—.‘.×)Ñ)Ð*¨!¬D¯JªJ°{È1ÐX\Ñ,]Ð+^Ð^`ÐaÐar&   c                ó¨   • U R                  5       n[        5       R                  5       n0 nUR                  5        H  u  pEXRU   :w  d  M  XSU'   M     U$ )zÿ
Removes all attributes from config which correspond to the default config attributes for better readability and
serializes to a Python dictionary.

Returns:
    `dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance,
)rD   rq   r-   )rH   r3   Údefault_config_dictÚserializable_config_dictr8   r9   s         r'   r`   ÚBitsAndBytesConfig.to_diff_dict„  s[   € ð —l‘l“nˆô 1Ó2×:Ñ:Ó<Ðà#%Ð ð &×+Ñ+Ö-‰JˆCØ¨CÑ0Õ0Ø05¨Ó-ñ .ð (Ð'r&   )rs   rt   rŒ   r�   r‰   rŠ   r‡   rˆ   r†   r…   r+   )
FFg      @NFFNr²   FN)r9   rj   rh   )r   r   r   r   rl   rn   r™   Úpropertyr˜   Úsetterr—   r–   r®   r´   rD   r]   r`   r%   r   r&   r'   rq   rq   «   s³   † ñ1òf #UÐð ØØØ"Ø).Ø!&Ø#Ø!Ø"'Ø#ô<ð| ñ"ó ð"ð ×Ñó#ó ð#ð ñ"ó ð"ð ×Ñó#ó ð#ò#òJ6òôòb÷(r&   rq   c                  ó&   • \ rS rSrSrSSS jjrSrg)ÚGGUFQuantizationConfigi›  a5  This is a config class for GGUF Quantization techniques.

Args:
    compute_dtype: (`torch.dtype`, defaults to `torch.float32`):
        This sets the computational type which might be different than the input type. For example, inputs might be
        fp32, but computation can be set to bf16 for speedups.

Nc                óœ   • [         R                  U l        Xl        SU l        S U l        U R                  c  [        R                  U l        g g )NT)r   r   r+   Úcompute_dtypeÚpre_quantizedÚmodules_to_not_convertr‹   rx   )rH   rÊ   s     r'   r™   ÚGGUFQuantizationConfig.__init__¦  sE   € Ü.×3Ñ3ˆÔØ*ÔØ!ˆÔð '+ˆÔ#à×ÑÑ%Ü!&§¡ˆDÕð &r&   )rÊ   rÌ   rË   r+   r~   )rÊ   z'torch.dtype' | None)r   r   r   r   rl   r™   r%   r   r&   r'   rÈ   rÈ   ›  s   † ñ÷	/ñ 	/r&   rÈ   c                  óT   ^ • \ rS rSrSr   S     SS jjrS rS	U 4S jjrSrU =r	$ )
ÚNunchakuLiteQuantizationConfigi²  a  Configuration for loading Nunchaku Lite checkpoints.

Nunchaku Lite support in Diffusers loads prequantized checkpoints. To create a compatible checkpoint, use
[`diffuse-compressor`](https://github.com/rootonchair/diffuse-compressor) to choose or adapt a target configuration
for the model architecture, quantize and export the transformer, and package it as a Diffusers pipeline with the
compact `quantization_config` stored in `config.json`.

The exported state dict must match the target Diffusers model architecture exactly. Checkpoints quantized with
fused QKV projections won't load into a model config that expects separate Q, K, and V projection modules.

Example compact `config.json` config:

```json
{
  "_class_name": "ErnieImageTransformer2DModel",
  "quantization_config": {
    "quant_method": "nunchaku_lite",
    "compute_dtype": "bfloat16",
    "svdq_w4a4": {
      "precision": "nvfp4",
      "group_size": 16,
      "rank": 32,
      "targets": ["layers.0.self_attention.to_q"]
    },
    "awq_w4a16": {
      "precision": "int4",
      "group_size": 64,
      "targets": ["final_linear"]
    }
  }
}
```

Args:
    compute_dtype (`torch.dtype`, defaults to `torch.bfloat16`):
        Runtime dtype used by the floating-point buffers in the quantized modules.
    svdq_w4a4 (`dict`, *optional*):
        Explicit SVDQ W4A4 target configuration with `precision`, `group_size`, `rank`, and `targets`.
    awq_w4a16 (`dict`, *optional*):
        Explicit AWQ W4A16 target configuration with `precision`, `group_size`, and `targets`.
c                óŽ  • [         R                  U l        Uc  [        R                  n[        U[        5      (       a5  [        [        U5      (       d  [        SU< S35      e[        [        U5      n[        U[        R                  5      (       d  [        S5      eXl        SU l        X l        X0l        U R                  5         g )Nz$Unsupported Nunchaku compute dtype: rƒ   z9Nunchaku compute_dtype must be a string or a torch.dtype.T)r   r   r+   r‹   r|   r�   rk   r.   r„   rŽ   r�   rÊ   rË   Ú	svdq_w4a4Ú	awq_w4a16r–   )rH   rÊ   rÑ   rÒ   r5   s        r'   r™   Ú'NunchakuLiteQuantizationConfig.__init__Þ  s�   € ô /×<Ñ<ˆÔØÑ Ü!ŸN™NˆMÜ�m¤S×)Ñ)Üœ5 -×0Ñ0Ü Ð#GÈÑGXÐXYÐ!ZÓ[Ð[Ü#¤E¨=Ó9ˆMÜ˜-¬¯©×5Ñ5ÜÐXÓYÐYØ*ÔØ!ˆÔØ"ŒØ"Œà�‰Õr&   c                óð  • U R                   c  U R                  c  [        S5      eSU R                   4SU R                  44 GH°  u  pUc  M  [        U[        5      (       d  [        SU< S35      eS[
        4S[        4S[        44 HR  u  p4X2;  a  [        SU< S	U< S
35      e[        X#   U5      (       a  M3  [        SU< SU< SUR                   S
35      e   US   nUS   nUS   nUS;  a  [        SU< SU< S
35      eUS::  a  [        SU< S35      eU(       d  [        SU< S35      e[        S U 5       5      (       d  [        SU< S35      eUS:X  a  SU;  a  [        SU< S35      e[        US   [        5      (       d  [        SU< S35      eUS   S:  a  [        SU< S35      eUS:X  a  SOSnXh:w  a  [        SU< SU SU S
35      eGMŸ  US:w  d  GM¨  [        S 5      e   g )!Nz]Nunchaku compact quantization config must include `svdq_w4a4.targets` or `awq_w4a16.targets`.rÑ   rÒ   z Nunchaku compact config section z must be a JSON object.Ú	precisionÚ
group_sizeÚtargetsz is missing required field rƒ   z field z	 must be )Úint4Únvfp4zUnsupported Nunchaku precision z for r   z must have positive group_size.z" must contain at least one target.c              3  óB   #   • U  H  n[        U[        5      v •  M     g 7fr~   )r�   rk   )r   Útargets     r'   r�   Ú;NunchakuLiteQuantizationConfig.post_init.<locals>.<genexpr>  s   é € ÐEºW°6”z &¬#×.Ð.ºWùs   ‚z targets must be strings.Úrankz" is missing required field 'rank'.z field 'rank' must be int.z must have non-negative rank.rÙ   é   é@   z$Nunchaku SVDQ config with precision=z requires group_size=z, got rØ   z.Nunchaku AWQ target requires precision='int4'.)
rÑ   rÒ   r„   r�   Údictrk   Úintr”   r   r‘   )	rH   ÚopÚrawr8   Úexpected_typerÕ   rÖ   r×   Úexpected_group_sizes	            r'   r–   Ú(NunchakuLiteQuantizationConfig.post_initõ  sm  € Ø�>‰>Ñ! d§n¡nÑ&<ÜØoóð ð % d§n¡nÐ5¸ÀTÇ^Á^Ð7TÔU‰GˆBØ‰{ÙÜ˜c¤4×(Ñ(Ü Ð#CÀBÁ6ÐI`Ð!aÓbÐbà(3´SÐ'9¸LÌ#Ð;NÐQZÔ\`ÐPaÓ&bÑ"�Ø“>Ü$Ð'GÈÁvÐMhÐilÑhoÐopÐ%qÓrÐrÜ! #¡(¨M×:Ó:Ü$Ø:¸2¹&ÀÈÁwÈiÐXe×XnÑXnÐWoÐopÐqóð ñ	 'cð ˜KÑ(ˆIØ˜\Ñ*ˆJØ˜)‘nˆGØÐ 1Ó1Ü Ð#BÀ9Á-ÈuÐUWÑTZÐZ[Ð!\Ó]Ð]Ø˜Q‹Ü Ð#CÀBÁ6ÐIhÐ!iÓjÐjÞÜ Ð#CÀBÁ6ÐIkÐ!lÓmÐmÜÑE¹WÓE×EÑEÜ Ð#CÀBÁ6ÐIbÐ!cÓdÐdà�[Ó Ø Ó$Ü$Ð'GÈÁvÐMoÐ%pÓqÐqÜ! # f¡+¬s×3Ñ3Ü$Ð'GÈÁvÐMgÐ%hÓiÐiØ�v‘; “?Ü$Ð'GÈÁvÐMjÐ%kÓlÐlØ,5¸Ó,@¡bÀbÐ#ØÓ4Ü$Ø>¸y¹mð L&Ø&9Ð%:¸&ÀÀÈAðOóð ò 5ð
 ˜fÖ$Ü Ð!QÓRÐRòQ Vr&   c                ój   >• [         TU ]  5       n[        US   5      R                  S5      S   US'   U$ )NrÊ   rƒ   r·   )ÚsuperrD   rk   r¸   ©rH   r¹   r[   s     €r'   rD   Ú&NunchakuLiteQuantizationConfig.to_dict%  s8   ø€ Ü‘‘Ó"ˆÜ"% f¨_Ñ&=Ó">×"DÑ"DÀSÓ"IÈ!Ñ"LˆˆÑØˆr&   )rÒ   rÊ   rË   r+   rÑ   )NNN)rÊ   z'torch.dtype' | str | NonerÑ   údict[str, Any] | NonerÒ   rë   rh   )
r   r   r   r   rl   r™   r–   rD   r%   Ú__classcell__©r[   s   @r'   rÏ   rÏ   ²  sF   ø† ñ(ðX 59Ø+/Ø+/ð	à1ðð )ðð )õ	ò..S÷`õ r&   rÏ   c                  ól   ^ • \ rS rSrSr S
     SS jjrS rU 4S jr\SS j5       r	S r
S rS	rU =r$ )ÚTorchAoConfigi+  a�  This is a config class for torchao quantization/sparsity techniques.

Args:
    quant_type (`AOBaseConfig`):
        An `AOBaseConfig` subclass instance specifying the quantization type. See the [torchao
        documentation](https://docs.pytorch.org/ao/main/api_ref_quantization.html#inference-apis-for-quantize) for
        available config classes (e.g. `Int4WeightOnlyConfig`, `Int8WeightOnlyConfig`, `Float8WeightOnlyConfig`,
        `Float8DynamicActivationFloat8WeightConfig`, etc.).
    modules_to_not_convert (`list[str]`, *optional*, default to `None`):
        The list of modules to not quantize, useful for quantizing models that explicitly require to have some
        modules left in their original precision.

Example:
    ```python
    from diffusers import FluxTransformer2DModel, TorchAoConfig
    from torchao.quantization import Int8WeightOnlyConfig

    quantization_config = TorchAoConfig(Int8WeightOnlyConfig())
    transformer = FluxTransformer2DModel.from_pretrained(
        "black-forest-labs/Flux.1-Dev",
        subfolder="transformer",
        quantization_config=quantization_config,
        torch_dtype=torch.bfloat16,
    )
    ```
c                óf   • [         R                  U l        Xl        X l        U R                  5         g r~   )r   r    r+   Ú
quant_typerÌ   r–   )rH   rñ   rÌ   r5   s       r'   r™   ÚTorchAoConfig.__init__H  s'   € ô /×6Ñ6ˆÔØ$ŒØ&<Ô#à�‰Õr&   c                óÔ   • [        SS5      (       a  [        S5      eSSKJn  [	        U R
                  U5      (       d+  [        S[        U R
                  5      R                   35      eg )NÚ<ú0.15.0zWTorchAoConfig requires torchao >= 0.15.0. Please upgrade with `pip install -U torchao`.r   )ÚAOBaseConfigz1quant_type must be an AOBaseConfig instance, got )	r   r„   Útorchao.quantization.quant_apirö   r�   rñ   r    Útyper   )rH   rö   s     r'   r–   ÚTorchAoConfig.post_initT  s[   € Ü˜c 8×,Ñ,ÜÐvÓwÐwå?ä˜$Ÿ/™/¨<×8Ñ8ÜÐOÔPTÐUY×UdÑUdÓPe×PnÑPnÐOoÐpÓqÐqð 9r&   c                ó^   >• [         TU ]  5       nSSKJn  SU" U R                  5      0US'   U$ )z&Convert configuration to a dictionary.r   )Úconfig_to_dictÚdefaultrñ   )rè   rD   Útorchao.core.configrû   rñ   )rH   Údrû   r[   s      €r'   rD   ÚTorchAoConfig.to_dict]  s2   ø€ ä‰G‰OÓˆõ 	7ð
 %¡n°T·_±_Ó&EÐFˆˆ,‰àˆr&   c                óî   • [        SS5      (       d  [        S5      eUR                  5       nUR                  S5      n[	        U5      S:X  a  SU;   d   S5       eUS   nSS	KJn  U" U5      nU " S
SU0UD6$ )z'Create configuration from a dictionary.z>=rõ   zCTorchAoConfig requires torchao >= 0.15.0 for construction from dictrñ   r·   rü   z8Expected only one key 'default' in quant_type dictionaryr   )Úconfig_from_dictr   )r   ÚNotImplementedErrorrP   r1   Úlenrý   r  )r2   r3   r4   r5   rñ   r  s         r'   r:   ÚTorchAoConfig.from_dictk  sŒ   € ô " $¨×1Ñ1Ü%Ð&kÓlÐlØ!×&Ñ&Ó(ˆØ —_‘_ \Ó2ˆ
ô �:‹ !Ó#¨	°ZÓ(?ð 	
ØFó	
Ð?ð   	Ñ*ˆ
õ 	9á% jÓ1ˆ
áÑ8˜jÐ8¨KÑ8Ð8r&   c                ó   • U R                   $ )zBCreate the appropriate quantization method based on configuration.)rñ   rS   s    r'   Úget_apply_tensor_subclassÚ'TorchAoConfig.get_apply_tensor_subclass�  s   € à�‰Ðr&   c                ó‚   • U R                  5       nU R                  R                   S[        R                  " USSS9 S3$ r¼   r½   r¾   s     r'   r]   ÚTorchAoConfig.__repr__…  rÀ   r&   )rÌ   r+   rñ   r~   )rñ   z'AOBaseConfig'rÌ   úlist[str] | Noneri   ÚNonerg   )r   r   r   r   rl   r™   r–   rD   ro   r:   r  r]   r%   rì   rí   s   @r'   rï   rï   +  s^   ø† ñð< 48ð
à"ð
ð !1ð
ð
 
õ
òrõð ó9ó ð9ò*÷bð br&   rï   c                  ó6   • \ rS rSrSr  S   SS jjrS rSrg)	ÚQuantoConfigiŠ  a]  
This is a wrapper class about all possible attributes and features that you can play with a model that has been
loaded using `quanto`.

Args:
    weights_dtype (`str`, *optional*, defaults to `"int8"`):
        The target dtype for the weights after quantization. Supported values are ("float8","int8","int4","int2")
   modules_to_not_convert (`list`, *optional*, default to `None`):
        The list of modules to not quantize, useful for quantizing models that explicitly require to have some
        modules left in their original precision (e.g. Whisper encoder, Llava encoder, Mixtral gate layers).
Nc                ó„   • Sn[        SSU5        [        R                  U l        Xl        X l        U R                  5         g )NzB`QuantoConfig` is deprecated and will be removed in version 1.0.0.r  z1.0.0)r
   r   r!   r+   Úweights_dtyperÌ   r–   )rH   r  rÌ   r5   Údeprecation_messages        r'   r™   ÚQuantoConfig.__init__˜  s<   € ð cÐÜ�. 'Ð+>Ô?Ü.×5Ñ5ˆÔØ*ÔØ&<Ô#à�‰Õr&   c                ób   • / SQnU R                   U;  a  [        SU SU R                    35      eg)z+
Safety checker that arguments are correct
)Úfloat8ry   rØ   Úint2zOnly support weights in z but found N)r  r„   )rH   Úaccepted_weightss     r'   r–   ÚQuantoConfig.post_init¦  sA   € ò >ÐØ×ÑÐ%5Ó5ÜÐ7Ð8HÐ7IÈÐUY×UgÑUgÐThÐiÓjÐjð 6r&   )rÌ   r+   r  )ry   N)r  rk   rÌ   r
  )r   r   r   r   rl   r™   r–   r%   r   r&   r'   r  r  Š  s,   † ñ
ð $Ø37ðàðð !1õõkr&   r  c                  ó¤   • \ rS rSrSrSSSSSS.rSSS.r          S                       SS
 jjrSSS jjrSS jr	SS jr
Srg	)ÚNVIDIAModelOptConfigi¯  a9  This is a config class to use nvidia modelopt for quantization.

Args:
    quant_type (`str`):
        The type of quantization we want to use, following is how to use:
            **weightquant_activationquant ==> FP8_FP8** In the above example we have use FP8 for both weight and
            activation quantization. Following are the all the options:
                - FP8
                - INT8
                - INT4
                - NF4
                - NVFP4
    modules_to_not_convert (`list[str]`, *optional*, default to `None`):
        The list of modules to not quantize, useful for quantizing models that explicitly require to have some
    weight_only (`bool`, *optional*, default to `False`):
        If set to `True`, the quantization will be applied only to the weights of the model.
    channel_quantize (`int`, *optional*, default to `None`):
        The channel quantization axis, useful for quantizing models across different axes.
    block_quantize (`int`, *optional*, default to `None`):
        The block size, useful to further quantize each channel/axes into blocks.
    scale_channel_quantize (`int`, *optional*, default to `None`):
        The scale channel quantization axis, useful for quantizing calculated scale across different axes.
    scale_block_quantize (`int`, *optional*, default to `None`):
        The scale block size, useful for quantizing each scale channel/axes into blocks.
    algorithm (`str`, *optional*, default to `"max"`):
        The algorithm to use for quantization, currently only supports `"max"`.
    forward_loop (`Callable`, *optional*, default to `None`):
        The forward loop function to use for calibration during quantization.
    modelopt_config (`dict`, *optional*, default to `None`):
        The modelopt config, useful for passing custom configs to modelopt.
    disable_conv_quantization (`bool`, *optional*, default to `False`):
        If set to `True`, the quantization will be disabled for convolutional layers.
    kwargs (`dict[str, Any]`, *optional*):
        Additional parameters which are to be used for calibration.
)é   é   é   r  )r	   r·   )ÚFP8ÚINT8ÚINT4ÚNF4ÚNVFP4)r  r   Nc                óþ   • [         R                  U l        U R                  U5        X l        X0l        X@l        XPl        SU0U l        X�l	        X`l
        Xpl        U
(       d  U R                  5       OU
U l        X°l        g )NÚmethod)r   r"   r+   Ú_normalize_quant_typerÌ   Úweight_onlyÚchannel_quantizeÚblock_quantizeÚ	calib_cfgÚforward_loopÚscale_channel_quantizeÚscale_block_quantizeÚget_config_from_quant_typeÚmodelopt_configÚdisable_conv_quantization)rH   rñ   rÌ   r$  r%  r&  r)  r*  Ú	algorithmr(  r,  r-  r5   s                r'   r™   ÚNVIDIAModelOptConfig.__init__á  sv   € ô /×7Ñ7ˆÔØ×"Ñ" :Ô.Ø&<Ô#Ø&ÔØ 0ÔØ,Ôà�ið
ˆŒð )ÔØ&<Ô#Ø$8Ô!ÞHW˜t×>Ñ>Ô@Ð]lˆÔØ)BÕ&r&   c                óh   • SSK Jn  [        U5      S:X  a  SU S3n[        R                  " U5        g g )Nr   )Ú_PATCHED_CLASSESzNot zþ weights in modelopt format. This might cause unreliable behavior.Please make sure to run the following code before loading/saving model weights:

    from modelopt.torch.opt import enable_huggingface_checkpointing
    enable_huggingface_checkpointing()
)Ú&modelopt.torch.opt.plugins.huggingfacer1  r  ÚwarningsÚwarn)rH   Ú	operationr1  Úwarning_msgs       r'   Úcheck_model_patchingÚ)NVIDIAModelOptConfig.check_model_patching   s<   € åKäÐÓ  AÓ%à�y�kð ";ð ;ð ô �MŠM˜+Õ&ð &r&   c                óš  • UR                  S5      nUS   n[        U5      S:”  a  US   OSn[        U5      S:”  a  [        R                  SU S35        SnSnOaU[        R
                  ;  a  [        R                  S	U S
35        SnUb/  U[        R
                  ;  a  [        R                  SU S35        SnX4b  SU-   OS-   U l        g)av  
Validates and normalizes the quantization type string.

Splits the quant_type into weight and activation components, verifies them against supported types, and
replaces unsupported values with safe defaults.

Args:
    quant_type (str): The input quantization type string (e.g., 'FP8_INT8').

Returns:
    str: A valid quantization type string (e.g., 'FP8_INT8' or 'FP8').
Ú_r   r·   Nr	   zQuantization type z. is not supported. Picking FP8_INT8 as defaultr  zWeight Quantization type z) is not supported. Picking FP8 as defaultzActivation Quantization type z* is not supported. Picking INT8 as defaultÚ )r¸   r  r’   r“   r  Úquanttype_to_numbitsrñ   )rH   rñ   ÚpartsÚw_typeÚact_types        r'   r#  Ú*NVIDIAModelOptConfig._normalize_quant_type  sÏ   € ð × Ñ  Ó%ˆØ�q‘ˆÜ" 5›z¨A›~�5˜’8°4ˆÜˆu‹:˜‹>Ü�N‰NÐ/°
¨|Ð;iÐjÔkØˆFØ‰HàÔ1×FÑFÓFÜ—‘Ð!:¸6¸(ÐBkÐlÔmØ�ØÑ#¨Ô8L×8aÑ8aÓ(aÜ—‘Ð!>¸x¸jÐHrÐsÔtØ�Ø Ñ6J C¨(¢NÐPRÑSˆ�r&   c                ó  • SSK Js  Jn  SS00 SS00 0 0 0 S.UR                  R                  EU R
                  S.nUS   nU R                  (       a#  U H  nS	U;  d  M  X4   (       a  M  SX4   S'   M     U R                  R                  S
5      nUS   n[        U5      S:”  a  US   R                  SS5      OSnU Hc  nXAR                  R                  ;  d  M  SX4   ;  d  M(  US:X  a  Ub  [        R                  U   X4   S'   MK  [        R                  U   X4   S'   Me     U R                  bL  U R                  b?  U R                  U R                  0US	   S'   U R                  U R                  SS0US   S'   O9U R                  b,  U R                  US	   S'   U R                  US   S'   SUS   S'   U R                  b¾  U R                   b±  U[        R"                  ;   aA  US	   S   R%                  [        R"                  U   U R                  U R                   0S.5        U(       aU  U[        R"                  ;   aA  US   S   R%                  [        R"                  U   U R                  U R                   0S.5        U$ )z,
Get the config from the quantization type.
r   NÚ
fake_quantFÚenable)ú*weight_quantizerú*input_quantizerz*output_quantizerz*q_bmm_quantizerz*k_bmm_quantizerz*v_bmm_quantizerz*softmax_quantizer)Ú	quant_cfgr.  rF  rD  r:  r·   ÚAr;  rE  Únum_bitsÚblock_sizesrø   ÚdynamicÚaxis)Ú
scale_bitsÚscale_block_sizes)Úmodelopt.torch.quantizationr‹   Úquantizationr6   Ú_default_disabled_quantizer_cfgr'  r$  rñ   r¸   r  Úreplacer  r<  r&  r%  r)  r*  Úquanttype_to_scalingbitsre   )rH   ÚmtqÚBASE_CONFIGrF  r€   r=  r>  r?  s           r'   r+  Ú/NVIDIAModelOptConfig.get_config_from_quant_type*  s§  € ÷ 	2Ð1ð '3°EÐ%:Ø$&Ø&.°Ð%6Ø$&Ø$&Ø$&Ø&(ñ	ð —*‘*×<Ñ<ð	ð Ÿ™ñ
ˆð   Ñ,ˆ	Ø××Û�Ø&¨aÕ/¸	¿¹Ø-2�I‘L Ó*ñ ð —‘×%Ñ% cÓ*ˆØ�q‘ˆÜ03°E³
¸Q³�5˜‘8×#Ñ# C¨Ô,ÀDˆÛˆAØŸ
™
×BÑBÕBÀxÐW`ÑWcÕGcØÐ*Ó*ØÑ+Ü3G×3\Ñ3\Ð]eÑ3f˜	™ ZÑ0ÙÜ+?×+TÑ+TÐU[Ñ+\�	‘˜ZÓ(ñ ð ×ÑÑ*¨t×/DÑ/DÑ/PØ=A×=RÑ=RÐTX×TgÑTgÐ<hˆIÐ)Ñ*¨=Ñ9à×%Ñ% t×':Ñ':Ø˜	ð<ˆIÐ(Ñ)¨-Ò8ð ×"Ñ"Ñ.Ø59×5JÑ5JˆIÐ)Ñ*¨6Ñ2Ø48×4IÑ4IˆIÐ(Ñ)¨&Ñ1Ø4=ˆIÐ(Ñ)¨&Ñ1ð ×&Ñ&Ñ2°t×7PÑ7PÑ7\ØÔ-×FÑFÓFØÐ-Ñ.¨}Ñ=×DÑDä&:×&SÑ&SÐTZÑ&[Ø.2×.IÑ.IÈ4×KdÑKdÐ-eñôö ˜HÔ(<×(UÑ(UÓUØÐ,Ñ-¨mÑ<×CÑCä&:×&SÑ&SÐT\Ñ&]Ø.2×.IÑ.IÈ4×KdÑKdÐ-eñôð Ðr&   )r&  r'  r%  r-  r(  r,  rÌ   r+   rñ   r*  r)  r$  )
NTNNNNÚmaxNNF)rñ   rk   rÌ   r
  r$  rj   r%  ú
int | Noner&  rW  r)  rW  r*  rW  r.  rk   r(  zCallable | Noner,  zdict | Noner-  rj   ri   r  )Úloading)r5  rk   )rñ   rk   ri   rk   rh   )r   r   r   r   rl   r<  rR  r™   r7  r#  r+  r%   r   r&   r'   r  r  ¯  sê   † ñ"ðJ ØØØØñÐð Øñ Ðð 48Ø Ø'+Ø%)Ø-1Ø+/ØØ(,Ø'+Ø*/ðCàðCð !1ðCð ð	Cð
 %ðCð #ðCð !+ðCð )ðCð ðCð &ðCð %ðCð $(ðCð 
õCö>'ôT÷:Ar&   r  c                  ó„   ^ • \ rS rSrSr/ SQr    S	         S
S jjrS rSU 4S jjr\	SSU 4S jjj5       r
SrU =r$ )ÚAutoRoundConfigin  uª  Configuration class for AutoRound quantization.

AutoRound is a weight-only quantization algorithm that uses sign gradient descent to jointly optimize weight
rounding and min-max values. This config targets the W4A16 (4-bit weights, 16-bit activations) setting.

Reference: https://github.com/intel/auto-round

Args:
    bits (`int`, *optional*, defaults to `4`):
        The number of bits to quantize weights to. For W4A16 this should be 4.
    group_size (`int`, *optional*, defaults to `128`):
        The group size for weight quantization. Weights in each group share the same scale and zero-point. Common
        choices: 32, 64, 128, -1 (per-channel).
    sym (`bool`, *optional*, defaults to `True`):
        Whether to use symmetric quantization (zero-point fixed at 0) or asymmetric quantization (zero-point is
        learned).
    backend (`str`, *optional*, defaults to `"auto"`):
        The backend kernel to use for quantized inference. Available backends:
        - `"auto"`: Automatically select the best available backend for the current device.
        - `"torch"`: Pure PyTorch kernel â€” works on CPU and CUDA.
        - `"tritonv2"`: Triton-based kernel â€” requires CUDA.
        - `"exllamav2"`: Exllamav2 kernel via GPTQModel â€” requires CUDA and `gptqmodel>=5.8.0`. Offers good CUDA
          inference performance.
        - `"marlin"`: Marlin kernel via GPTQModel â€” requires CUDA and `gptqmodel>=5.8.0`. Offers the best CUDA
          inference performance.
    kwargs (`dict[str, Any]`, *optional*):
        Additional keyword arguments forwarded to AutoRound (e.g. `iters`, `seqlen`, `batch_size`, `lr`,
        `minmax_lr` for calibration when quantizing from scratch).
)Úautor‹   Útritonv2Ú	exllamav2Úmarlinc                óÊ   • [         R                  U l        U R                  U5        Xl        X l        X0l        X@l        UR                  5        H  u  pg[        XU5        M     g r~   )
r   r#   r+   Ú_validate_backendÚbitsrÖ   ÚsymÚbackendr-   r/   )rH   ra  rÖ   rb  rc  r5   r€   Úvs           r'   r™   ÚAutoRoundConfig.__init__�  sP   € ô /×8Ñ8ˆÔØ×Ñ˜wÔ'ØŒ	Ø$ŒØŒØŒØ—L‘L–N‰DˆAÜ�D˜QÖò #r&   c                óX   • XR                   ;  a  [        SU SU R                    35      eg )NzInvalid backend 'z'. Valid options are: )ÚVALID_BACKENDSr„   )rH   rc  s     r'   r`  Ú!AutoRoundConfig._validate_backend¡  s5   € Ø×-Ñ-Ó-ÜÐ0°°	Ð9OÐPT×PcÑPcÐOdÐeÓfÐfð .r&   c                óH   >• [         TU ]  5       nUS   R                  US'   U$ )z¸Serialize the config to a JSON-compatible dict.

Output: A dict containing all config fields. The `quant_method` is stored as its string value so it can be
round-tripped through JSON.
r+   )rè   rD   r9   ré   s     €r'   rD   ÚAutoRoundConfig.to_dict¥  s+   ø€ ô ‘‘Ó"ˆØ!'¨Ñ!7×!=Ñ!=ˆˆ~ÑØˆr&   c                óŽ   >• UR                  5        VVs0 s H  u  pEUS:w  d  M  XE_M     nnn[        TU ]  " U4SU0UD6$ s  snnf )zµInstantiate an AutoRoundConfig from a dictionary.

Input: config_dict with keys like bits, group_size, sym, etc. Output: An AutoRoundConfig instance (and
optionally unused kwargs).
r+   r4   )r-   rè   r:   )r2   r3   r4   r5   r€   rd  r[   s         €r'   r:   ÚAutoRoundConfig.from_dict¯  sS   ø€ ð )4×(9Ñ(9Ô(;ÔSÒ(;¡ ¸qÀNÑ?R“t�q’tÑ(;ˆÑSÜ‰wÒ  ÑbÐCWÐbÐ[aÑbÐbùó Ts
   •A¥A)rc  ra  rÖ   r+   rb  )r  é€   Tr[  )
ra  rá   rÖ   rá   rb  rj   rc  rk   ri   r  )ri   rà   rg   )r3   rà   r4   rj   )r   r   r   r   rl   rg  r™   r`  rD   ro   r:   r%   rì   rí   s   @r'   rZ  rZ  n  sz   ø† ñò< J€Nð ØØØð àð ð ð ð ð	 ð
 ð ð 
õ ò"g÷ð ÷	cð 	có ö	cr&   rZ  c                  ó   • \ rS rSrSrS rSrg)Ú
SDNQConfigi¼  a  Configuration class for SDNQ (SD.Next Quantization).

The `sdnq` library ships its own diffusers-compatible config and quantizer; this class is a thin factory that
defers to them so that `quant_method="sdnq"` checkpoints load natively with diffusers. All arguments are forwarded
to `sdnq.SDNQConfig`. Requires the `sdnq` library: `pip install sdnq`.

Reference: https://github.com/Disty0/sdnq

Args:
    weights_dtype (`str`, *optional*, defaults to `"int8"`):
        The target dtype for the weights after quantization, e.g. `"int8"`, `"uint4"`, `"float8_e4m3fn"`. See
        `sdnq.common.accepted_weight_dtypes` for all supported values.
    group_size (`int`, *optional*, defaults to `0`):
        How many elements of a tensor share the same quantization group. `0` auto-selects based on `weights_dtype`,
        `-1` disables grouping and uses row-wise quantization.
    use_svd (`bool`, *optional*, defaults to `False`):
        Whether to apply the SVDQuant algorithm on top of SDNQ quantization.
    use_quantized_matmul (`bool`, *optional*, defaults to `False`):
        Whether to use quantized INT8 / FP8 / FP16 matmul on the forward pass instead of BF16 / FP16.
    modules_to_not_convert (`list`, *optional*, defaults to `None`):
        The list of modules to skip during quantization.
    kwargs (`dict[str, Any]`, *optional*):
        Additional keyword arguments forwarded to `sdnq.SDNQConfig` (e.g. `quantized_matmul_dtype`, `svd_rank`,
        `use_hadamard`, `quant_conv`, `quant_embedding`, `modules_dtype_dict`).
c                ó8   • SSK Jn  U" 5         SSKJn  U" U0 UD6$ )Nr·   )Ú_check_sdnq_requirementr   )ro  )Úsdnq.sdnq_quantizerrq  r   ro  )r2   Úargsr5   rq  ÚSDNQLibConfigs        r'   Ú__new__ÚSDNQConfig.__new__×  s   € Ý@áÔ!Ý4á˜dÐ- fÑ-Ð-r&   r   N)r   r   r   r   rl   ru  r%   r   r&   r'   ro  ro  ¼  s   † ñõ4.r&   ro  )&rl   Ú
__future__r   rP   Úimportlib.metadatarª   rE   Úosr3  Údataclassesr   Úenumr   Útypingr   r   Ú	packagingr   Úutilsr
   r   r   r   r‹   Ú
get_loggerr   r’   rk   r   r)   rq   rÈ   rÏ   rï   r  r  rZ  ro  r   r&   r'   Ú<module>r€     sh  ðñ$õ
 #ã Û Û Û 	Û Ý !Ý ß  å ç NÓ Nñ ×ÑÛà	×	Ò	˜HÓ	%€ô˜˜dô ð ÷oð oó ðoðd ôl(Ð0ó l(ó ðl(ð^ ô/Ð4ó /ó ð/ð, ôuÐ%<ó uó ðuðp ô[bÐ+ó [bó ð[bð| ô!kÐ*ó !kó ð!kðH ô{Ð2ó {ó ð{ð| ôJcÐ-ó Jcó ðJcôZ!.Ð(õ !.r&   