§
    *`ƒi  ã            
       ó<  — d dl mZmZ d dlZd dlmZmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ dgZ	 ddee         d	ee         d
ee         defd„Z	 	 ddej        j        d
ee         dee         fd„Z	 	 ddej        j        d
ee         dee         dee         fd„ZdS )é    )ÚListÚOptionalN)ÚCompressionFormatÚSparsityStructure)ÚQuantizationArgsÚQuantizationStrategyÚQuantizationType)Úis_module_quantized)ÚloggerÚ,infer_and_set_per_module_quantization_formatÚ
input_argsÚweight_argsÚsparsity_structureÚreturnc                 óŽ  — t          |¦  «        t           j        k    }|duo| du }|j        dk    r=|j        t          j        j        k    r#|j        dk    rt          j	        S t          j
        S |rt|j        dv o|j        t          j        j        k    }|st          j        S |r5|j        t          j        j        t          j        j        fv rt          j        S t          j        S |j        t          j        j        k    r|j        dk    rt          j        S |j        t          j        j        k    rt          j        S t          j        S )a   
    Using the weight and input quantization args as well as an optional
    sparsity structure, determine the compression format that should be
    applied to a given module

    :param input_args: input quantization parameters
    :param weight_args: weight quantization parameters
    :param sparsity_structure: optional (global) modle sparsity
        structure
    :return CompresssionFormat for the module
    Né   é    )r   é   r   )r   ÚTWO_FOURÚnum_bitsÚtyper	   ÚFLOATÚvalueÚ
group_sizer   Úmxfp4_pack_quantizedÚnvfp4_pack_quantizedÚINTÚnaive_quantizedÚstrategyr   ÚCHANNELÚGROUPÚ	marlin_24Úpack_quantizedÚfloat_quantizedÚint_quantized)r   r   r   Úis_24_structureÚis_weight_onlyÚis_valid_packs         út/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/compressed_tensors/config/format.pyÚ_get_quant_compression_formatr*      sO  € õ" 	Ð,Ñ-Ô-Õ1BÔ1KÒKð ð !¨Ð,ÐC°¸tÐ1C€NàÔ˜qÒ Ð  [Ô%5Õ9IÔ9OÔ9UÒ%UÐ%UØÔ! RÒ'Ð'Ý$Ô9Ð9Ý Ô5Ð5àð 1àÔ  FÐ*ð ?ØÔ Õ$4Ô$8Ô$>Ò>ð 	ð ð 	5Ý$Ô4Ð4àð 	/˜{Ô3Ý Ô(Ô.Ý Ô&Ô,ð8
ð  
ð  
õ %Ô.Ð.Ý Ô/Ð/ð ÔÕ 0Ô 6Ô <Ò<Ð<ØÔ$¨Ò)Ð)å$Ô4Ð4ØÔÕ/Ô3Ô9Ò9Ð9Ý$Ô2Ð2å Ô0Ð0ó    ÚmoduleÚquantization_formatc                 óR  — | j         j        }| j         j        }|€dS t          |||¦  «        }|-||j        k    rt          j        d¦  «         || j         _        dS | j         j        -| j         j        |j        k    rt          j        d¦  «         dS dS |j        | j         _        dS )a[  
    Determine and set the per module quantization format given quantization args
    and sparsity structure.

    :param module: module which has its quantization inferred
    :param sparsity_structure: optional sparsity applied to the module
    :param quantization_format: optional global format to override
        the per module formats

    Nz\The provided format for the module does not match the inferred format. Compression may fail )Úquantization_schemeÚweightsÚinput_activationsr*   r   r   ÚwarningÚformat)r,   r   r-   Úweight_schemeÚinput_schemeÚcompression_formats         r)   Úset_per_module_formatr7   V   sä   € ð Ô.Ô6€MØÔ-Ô?€LØÐØˆÝ6ØmÐ%7ñô Ðð Ð&ØÐ"4Ô":Ò:Ð:ÝŒNð9ñô ð ð -@ˆÔ"Ô)Ð)Ð)à	Ô	#Ô	*Ð	6àÔ%Ô,Ð0BÔ0HÒHÐHÝŒNð9ñô ð ð ð ð IÐHð -?Ô,DˆÔ"Ô)Ð)Ð)r+   Úmodelc                 óX  — g }|                       ¦   «         D ]m}t          |¦  «        r\t          |d¦  «        sJ ‚t          |||¦  «         |j        j        r-|j        j        |vr|                     |j        j        ¦  «         Œnt          |¦  «        dk    r|S t          j	        j
        gS )a“  
    Infers the quantization format for a model based on its state and provided
    compression arguments. Updates thhe quantization_scheme.format value
    based on the inferred format. Returns the unique list of formats in the model.
    All None formats are mapped to CompressionFormat.dense.value

    For a summary of the formats, see `docs/guides/compression_formats.md`.

    :param model: model to check for quantization
    :param sparsity_structure: optional sparsity applied to the module
    :param quantization_format: optional global format to override
        the per module formats
    :return compression format appropriate for the model
    r/   r   )Úmodulesr
   Úhasattrr7   r/   r3   ÚappendÚlenr   Údenser   )r8   r   r-   Úunique_formatsÚ	submodules        r)   r   r   ƒ   sÁ   € ð& €NØ—]’]‘_”_ð Lð Lˆ	Ý˜yÑ)Ô)ð 	LÝ˜9Ð&;Ñ<Ô<Ð<Ð<Ð<Ý! )Ð-?ÐATÑUÔUÐUàÔ-Ô4ðLàÔ1Ô8ÀÐNÐNà×%Ò% iÔ&CÔ&JÑKÔKÐKøå
ˆ>ÑÔ˜QÒÐØÐÝÔ#Ô)Ð*Ð*r+   )N)NN)Útypingr   r   ÚtorchÚcompressed_tensors.configr   r   Úcompressed_tensors.quantizationr   r   r	   Ú%compressed_tensors.quantization.utilsr
   Úlogurur   Ú__all__Ústrr*   ÚnnÚModuler7   r   © r+   r)   ú<module>rL      s¥  ðð "Ð !Ð !Ð !Ð !Ð !Ð !Ð !à €€€Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jðð ð ð ð ð ð ð ð ð ð
 FÐ EÐ EÐ EÐ EÐ EØ Ð Ð Ð Ð Ð ð :Ð
:€ð )-ð41ð 41ØÐ)Ô*ð41àÐ*Ô+ð41ð ! œð41ð ð	41ð 41ð 41ð 41ðr )-Ø)-ð*Eð *EØŒHŒOð*Eà  œð*Eð " #œð*Eð *Eð *Eð *Eð^ )-Ø)-ð +ð  +ØŒ8Œ?ð +à  œð +ð " #œð +ð 
ˆ#„Yð	 +ð  +ð  +ð  +ð  +ð  +r+   