Ë
    S^(h  ã                   ób   — d dl mZmZmZ  e«       rddlZ ej
                  e«      Z	 	 	 	 dd„Zy)é   )Úis_optimum_quanto_availableÚis_torch_availableÚloggingé    Nc                 ó"  ‡— ddl m} t        «       rddlm}m}m}m}	m}
m	} 
	dœ}d||dœ}|€g }| j                  «       D �]º  \  }}‰€g Š‰j                  |«       t        ˆfd„|D «       «      �sA |«       5  t        |t        j                  j                   «      rŠ |j"                  |j$                  |j&                  du|j(                  j*                  ||j,                     ||j.                     ¬«      | j0                  |<   | j0                  |   j3                  d	«       d
}nƒt        |t        j                  j4                  «      r_|j.                  �S |j6                  |j8                  |j:                  |j&                  du||j.                     ¬«      | j0                  |<   d
}ddd«       t=        t?        |jA                  «       «      «      dkD  rtC        |||‰|¬«      \  }}‰jE                  d«       �Œ½ | |fS # 1 sw Y   ŒYxY w)a[  
    Public method that recursively replaces the Linear layers of the given model with Quanto quantized layers.
    Returns the converted model and a boolean that indicates if the conversion has been successfull or not.

    Args:
        model (`torch.nn.Module`):
            The model to convert, can be any `torch.nn.Module` instance.
        quantization_config (`AqlmConfig`, defaults to `None`):
            The quantization config object that contains the quantization parameters.
        modules_to_not_convert (`list`, *optional*, defaults to `None`):
            A list of modules to not convert. If a module name is in the list (e.g. `lm_head`), it will not be
            converted.
        current_key_name (`list`, *optional*, defaults to `None`):
            A list that contains the current key name. This is used for recursion and should not be passed by the user.
        has_been_replaced (`bool`, *optional*, defaults to `None`):
            A boolean that indicates if the conversion has been successful or not. This is used for recursion and
            should not be passed by the user.
    r   )Úinit_empty_weights)Ú
QLayerNormÚQLinearÚqfloat8Úqint2Úqint4Úqint8)Úfloat8Úint8Úint4Úint2N)Nr   r   c              3   óD   •K  — | ]  }|d j                  ‰«      v –— Œ y­w)ú.N)Újoin)Ú.0ÚkeyÚcurrent_key_names     €ú^/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/integrations/quanto.pyú	<genexpr>z-replace_with_quanto_layers.<locals>.<genexpr>A   s    øè ø€ ÒW¸�3˜#Ÿ(™(Ð#3Ó4Ô4ÑWùs   ƒ )Úin_featuresÚout_featuresÚbiasÚdtypeÚweightsÚactivationsFT)r    )Úquantization_configÚmodules_to_not_convertr   Úhas_been_replacedéÿÿÿÿ)#Ú
accelerater   r   Úoptimum.quantor	   r
   r   r   r   r   Únamed_childrenÚappendÚanyÚ
isinstanceÚtorchÚnnÚLinearr   r   r   Úweightr   r   r    Ú_modulesÚrequires_grad_Ú	LayerNormÚnormalized_shapeÚepsÚelementwise_affineÚlenÚlistÚchildrenÚreplace_with_quanto_layersÚpop)Úmodelr!   r"   r   r#   r   r	   r
   r   r   r   r   Ú	w_mappingÚ	a_mappingÚnameÚmoduleÚ_s      `             r   r8   r8      sñ  ø€ õ2 .ä"Ô$ßT×Tà"¨E¸5È%ÑP€IØ w¸Ñ>€IàÐ%Ø!#Ðà×,Ñ,Ó.ó %!‰ˆˆfØÐ#Ø!ÐØ×Ñ Ô%äÓWÐ@VÔWÕWÙ#Ó%ñ 1Ü˜f¤e§h¡h§o¡oÔ6Ù+2Ø$*×$6Ñ$6Ø%+×%8Ñ%8Ø#Ÿ[™[°Ð4Ø$Ÿm™m×1Ñ1Ø )Ð*=×*EÑ*EÑ FØ$-Ð.A×.MÑ.MÑ$Nô,�E—N‘N 4Ñ(ð —N‘N 4Ñ(×7Ñ7¸Ô>Ø(,Ñ%Ü ¬¯©×(:Ñ(:Ô;Ø*×6Ñ6ÐBÙ/9Ø"×3Ñ3Ø"ŸJ™JØ"×5Ñ5Ø"ŸK™K¨tÐ3Ø(1Ð2E×2QÑ2QÑ(Rô0˜Ÿ™ tÑ,ð -1Ð)÷+1ô, Œt�F—O‘OÓ%Ó&Ó'¨!Ò+Ü#=ØØ$7Ø'=Ø!1Ø"3ô$Ñ ˆAÐ ð 	×Ñ˜RÖ ðK%!ðL Ð#Ð#Ð#÷A1ð 1ús   Á;D2HÈH	)NNNF)	Úutilsr   r   r   r+   Ú
get_loggerÚ__name__Úloggerr8   © ó    r   ú<module>rF      s?   ð÷ MÑ Lñ ÔÛà	ˆ×	Ñ	˜HÓ	%€ð
 ØØØôJ$rE   