§
    ‚ŠtjN  ã                   óF   — d Z ddlZddlmZ ddlmZ  G d„ de¦  «        ZdS )z"CompressedTensors integration fileé    N)Únné   )ÚConversionOpsc                   ó¢   — e Zd ZdZd„ Z	 ddeeej        f         de	e         de	e         dedz  deeej        f         f
d	„Z
edd„¦   «         ZdS )ÚDecompressExpertsa�  
    Dequantize MoE layers when they are in new layout, because they aren't `nn.Module` anymore!

    Takes packed weights and scales from the loaded state dict, creates a dummy Module
    to take advantage of higher-lvl API `decompress_module` and dequantizes all weights.

    Requires MoE conversion to be defined on conversion mapping, so that decompressed weights
    are stacked/merged for all experts.
    c                 ó   — || _         d S ©N)Úhf_quantizer)Úselfr
   s     új/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/integrations/compressed_tensors.pyÚ__init__zDecompressExperts.__init__!   s   € Ø(ˆÔÐÐó    NÚ
input_dictÚsource_patternsÚtarget_patternsÚfull_layer_nameÚreturnc                 ó°  — ddl m} ddlm} | j        j        j        }t          |j         	                    ¦   «         ¦  «        d         }	|	j
        p |t          j        |	¦  «        }
|                     |
¦  «        } G d„ dt          j        ¦  «        }d|	j        j        z  }i }|                     ¦   «         D �]\  }}d|vrŒ|}||                     dd¦  «                 }d }t'          t)          ||¦  «        ¦  «        D ]É\  }\  }}t+          j        |j        d         |j        d	         |z  g¦  «        } ||||¦  «        }|	|_        |                     |¦  «         |€Ft+          j        t7          |¦  «        g|j        j        ¢R |j        j        |j        j        ¬
¦  «        }||                              |j        ¦  «         ~ŒÊ~~|�|||<   �Œ|S )Nr   )ÚBaseCompressor)Úinfer_module_formatc                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )ú.DecompressExperts.convert.<locals>.DummyModulec                 óê   •— t          ¦   «                              ¦   «          t          j        |d¬¦  «        | _        t          j        |d¬¦  «        | _        t          j        |d¬¦  «        | _        d S )NF)Úrequires_grad)Úsuperr   r   Ú	ParameterÚweight_packedÚweight_scaleÚweight_shape)r   ÚweightÚscaleÚshapeÚ	__class__s       €r   r   z7DecompressExperts.convert.<locals>.DummyModule.__init__6   sd   ø€ Ý‘”× Ò Ñ"Ô"Ð"Ý%'¤\°&ÈÐ%NÑ%NÔ%N�Ô"Ý$&¤L°ÀeÐ$LÑ$LÔ$L�Ô!Ý$&¤L°ÀeÐ$LÑ$LÔ$L�Ô!Ð!Ð!r   )Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__)r#   s   @r   ÚDummyModuler   5   sA   ø€ € € € € ðMð Mð Mð Mð Mð Mð Mð Mð Mr   r(   é    r   r   é   )ÚdtypeÚdevice) Úcompressed_tensors.compressorsr   Ú%compressed_tensors.compressors.formatr   r
   Ú
compressorÚquantization_configÚlistÚconfig_groupsÚvaluesÚformatr   ÚLinearÚget_value_from_registryÚModuleÚweightsÚnum_bitsÚitemsÚreplaceÚ	enumerateÚzipÚtorchÚtensorr"   Úquantization_schemeÚdecompress_moduleÚemptyÚlenr    r+   r,   Úcopy_)r   r   r   r   r   Úkwargsr   r   Úct_quantization_configr@   r4   r/   r(   Úpack_factorÚprocessed_outÚkeyÚvalueÚ	quantizedÚscalesÚoutputÚiÚquantr!   r"   Úmodules                            r   ÚconvertzDecompressExperts.convert$   s-  € ð 	BÐAÐAÐAÐAÐAØMÐMÐMÐMÐMÐMà!%Ô!2Ô!=Ô!QÐå"Ð#9Ô#G×#NÒ#NÑ#PÔ#PÑQÔQÐRSÔTÐØ$Ô+ÐbÐ/BÐ/BÅ2Ä9ÐNaÑ/bÔ/bˆØ#×;Ò;¸FÑCÔCˆ
ð	Mð 	Mð 	Mð 	Mð 	M�"œ)ñ 	Mô 	Mð 	Mð Ð/Ô7Ô@Ñ@ˆð ˆØ$×*Ò*Ñ,Ô,ð "	,ñ "	,‰JˆC�Ø cÐ)Ð)ØØˆIØ §¢¨O¸^Ñ LÔ LÔMˆFð
 ˆFÝ%.­s°9¸fÑ/EÔ/EÑ%FÔ%Fð ð Ñ!�‘>�E˜5õ œ e¤k°!¤n°e´kÀ!´nÀ{Ñ6RÐ%SÑTÔT�Ø$˜ U¨E°5Ñ9Ô9�Ø-@�Ô*Ø×,Ò,¨VÑ4Ô4Ð4à�>å"œ[Ý˜Y™œÐ>¨&¬-Ô*=Ð>Ð>Ø$œmÔ1Ø%œ}Ô3ðñ ô �Fð
 �q”	—’ ¤Ñ.Ô.Ð.à�Fà˜6ØÐ!ð &,�˜cÑ"ùàÐr   r   c                 ó   — d S r	   © )r   s    r   Ú
reverse_opzDecompressExperts.reverse_opg   s   € àˆtr   r	   )r   r   )r$   r%   r&   Ú__doc__r   ÚdictÚstrr>   ÚTensorr1   rQ   ÚpropertyrT   rS   r   r   r   r      sÊ   € € € € € ðð ð)ð )ð )ð '+ðAð Aà˜˜eœlÐ*Ô+ðAð ˜cœðAð ˜cœð	Að
 ˜t™ðAð 
ˆc�5”<ÐÔ	 ðAð Að Að AðF ðð ð ñ „Xðð ð r   r   )rU   r>   r   Úcore_model_loadingr   r   rS   r   r   ú<module>r[      sx   ðð %Ð $à €€€Ø Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .ðSð Sð Sð Sð S˜ñ Sô Sð Sð Sð Sr   