Ë
    ÛÓ^jN  ã                   ó>   — d Z ddlZddlmZ ddlmZ  G d„ de«      Zy)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y)Ú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                 ó   — || _         y ©N)Úhf_quantizer)Úselfr
   s     úw/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/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                  j                  «       «      d   }	|	j                  xs  |t        j                  |	«      }
|j                  |
«      } G d„ dt        j                  «      }d|	j                  j                   z  }i }|j#                  «       D �]'  \  }}d|vrŒ|}||j%                  dd«         }d }t'        t)        ||«      «      D ]à  \  }\  }}t+        j,                  |j.                  d   |j.                  d	   |z  g«      } ||||«      }|	|_        |j3                  |«       |€at+        j4                  t7        |«      g|j8                  j.                  ¢­|j8                  j:                  |j8                  j<                  ¬
«      }||   j?                  |j8                  «       ~Œâ ~~|€�Œ#|||<   �Œ* |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¬«      | _        y )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   sG   ø€ Ü‘Ñ Ô"Ü%'§\¡\°&ÈÔ%N�Ô"Ü$&§L¡L°ÀeÔ$L�Ô!Ü$&§L¡L°ÀeÔ$L�Õ!r   )Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__)r#   s   @r   ÚDummyModuler   5   s   ø„ ÷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ÝMà!%×!2Ñ!2×!=Ñ!=×!QÑ!QÐä"Ð#9×#GÑ#G×#NÑ#NÓ#PÓQÐRSÑTÐØ$×+Ñ+ÒbÑ/BÄ2Ç9Á9ÐNaÓ/bˆØ#×;Ñ;¸FÓCˆ
ô	Mœ"Ÿ)™)ô 	Mð Ð/×7Ñ7×@Ñ@Ñ@ˆð ˆØ$×*Ñ*Ó,ó "	,‰JˆC�Ø cÑ)ØØˆIØ §¡¨O¸^Ó LÑMˆFð
 ˆFÜ%.¬s°9¸fÓ/EÓ%Fò Ñ!�‘>�E˜5ô Ÿ™ e§k¡k°!¡n°e·k±kÀ!±nÀ{Ñ6RÐ%SÓT�Ù$ U¨E°5Ó9�Ø-@�Ô*Ø×,Ñ,¨VÔ4à�>ä"Ÿ[™[Ü˜Y›Ð>¨&¯-©-×*=Ñ*=Ñ>Ø$Ÿm™m×1Ñ1Ø%Ÿ}™}×3Ñ3ô�Fð
 �q‘	—‘ §¡Ô.áð%ð( ˜6ØÒ!ð &,�˜cÓ"ðE"	,ðH Ðr   c                  ó   — y r	   © )r   s    r   Ú
reverse_opzDecompressExperts.reverse_opg   s   € àr   r	   )r   r   )r$   r%   r&   Ú__doc__r   ÚdictÚstrr>   ÚTensorr1   rQ   ÚpropertyrT   rS   r   r   r   r      s‰   „ ñò)ð '+ñAà˜˜eŸl™lÐ*Ñ+ðAð ˜c™ðAð ˜c™ð	Að
 ˜t™ðAð 
ˆc�5—<‘<ÐÑ	 óAðF òó ñr   r   )rU   r>   r   Úcore_model_loadingr   r   rS   r   r   ú<module>r[      s!   ðñ %ã Ý å .ôS˜õ Sr   