
    eTh                     n    S SK JrJrJr  \" 5       (       a  SSKr\R
                  " \5      r    SS jrg)   )is_optimum_quanto_availableis_torch_availablelogging    Nc                 D  ^ SSK Jn  [        5       (       a  SSKJnJnJnJn	Jn
J	n  WWW
W	S.nSXS.nUc  / nU R                  5        GH  u  pTc  / mTR                  U5        [        U4S jU 5       5      (       GdC  U" 5          [        U[        R                  R                   5      (       a  W" UR"                  UR$                  UR&                  SLUR(                  R*                  XR,                     XR.                     S9U R0                  U'   U R0                  U   R3                  S	5        S
nO[        U[        R                  R4                  5      (       a\  UR.                  bO  W" UR6                  UR8                  UR:                  UR&                  SLXR.                     S9U R0                  U'   S
nSSS5        [=        [?        URA                  5       5      5      S:  a  [C        UUUTUS9u  nnTRE                  S5        GM     X4$ ! , (       d  f       N]= f)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 successful 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   J   >#    U  H  oS R                  T5      ;   v   M     g7f).N)join).0keycurrent_key_names     X/var/www/auris/envauris/lib/python3.13/site-packages/transformers/integrations/quanto.py	<genexpr>-replace_with_quanto_layers.<locals>.<genexpr>A   s      W@V#((#344@Vs    #)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   r9   r9      s   2 ."$$TT"E5%PIw>I%!#,,.#!%W@VWWW#%fehhoo66+2$*$6$6%+%8%8#[[4$mm11 )*E*E F$-.M.M$N,ENN4( NN4(77>(,%(:(:;;*66B/9"33"JJ"55"KKt3(12Q2Q(R0t, -1)+ &, tFOO%&'!+#=$7'=!1"3$ A  	R K /L ##A &%s   D4H
H	)NNNF)	utilsr   r   r   r,   
get_logger__name__loggerr9        r   <module>rG      s@    M L 			H	%
 J$rF   