L ibddlmZmZmZerddlZej eZ ddZy))is_optimum_quanto_availableis_torch_availableloggingNc "ddlm}trddlm}m}m}m} m} m }    d} d|| d} |g}|jD]\}}gj|tfd|DsA|5t|tjj r|j"|j$|j&du|j(j*| |j,| |j.|j0|<|j0|j3d d }nt|tjj4r_|j.S|j6|j8|j:|j&du| |j. |j0|<d }dddt=t?|jAdkDrtC|||| \}}jEd ||fS#1swYYxYw)aZ 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) QLayerNormQLinearqfloat8qint2qint4qint8)float8int8int4int2N)Nrrc3DK|]}|djvyw).N)join).0keycurrent_key_names f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/integrations/quanto.py z-replace_with_quanto_layers..As W3#((#344Ws ) in_features out_featuresbiasdtypeweights activationsFT)r )quantization_configmodules_to_not_convertrhas_been_replaced)# acceleraterroptimum.quantor r r r r rnamed_childrenappendany isinstancetorchnnLinearrrrweightrrr _modulesrequires_grad_ LayerNormnormalized_shapeepselementwise_affinelenlistchildrenreplace_with_quanto_layerspop)modelr!r"rr#rr r r r r r w_mapping a_mappingnamemodule_s ` rr8r8s2."$TT"E5%PIw>I%!#,,.%! f  #! %W@VWW#% 1fehhoo6+2$*$6$6%+%8%8#[[4$mm11 )*=*E*E F$-.A.M.M$N ,ENN4(NN4(77>(,%(:(:;*66B/9"33"JJ"55"KKt3(12E2Q2Q(R 0t,-1)+ 1, tFOO%& '! +#=$7'=!1"3 $ A  R K%!L # ##A 1 1s ;D2HH )NNNF) utilsrrrr+ get_logger__name__loggerr8rrFs?ML   H %  J$rE