
    謜i                         d Z ddlmZ ddlmZmZ  e       r
ddlZddlmZ  ej                  e
      Zddee   dz  fdZy)	z?AQLM (Additive Quantization of Language Model) integration file   )should_convert_module)is_torch_availablelogging    Nmodules_to_not_convertc                 .   ddl m} d}| j                         D ]  \  }}t        ||      st	        j
                  d      5  t        |t        j                        r ||j                  |j                  |j                  du|j                  |j                  |j                  |j                        }t!        |      |_        |j%                  d       | j'                  ||       d}ddd        |st(        j+                  d       | S # 1 sw Y   xY w)	ai  
    Public method that recursively replaces the Linear layers of the given model with AQLM quantized layers.

    Args:
        model (`torch.nn.Module`):
            The model to convert, can be any `torch.nn.Module` instance.
        modules_to_not_convert (`list[str]`, *optional*, defaults to `None`):
            A list of nn.Linear weights to not convert. If a parameter path is in the list (e.g. `lm_head.weight`), the corresponding module will not be
            converted.
        quantization_config (`AqlmConfig`):
            The quantization config object that contains the quantization parameters.
    r   )QuantizedLinearFmetaN)biasin_group_sizeout_group_sizenum_codebooksnbits_per_codebookTzYou are loading your model using eetq but no linear modules were found in your model. Please double check your model architecture, or submit an issue on github if you think this is a bug.)aqlmr	   named_modulesr   torchdevice
isinstancennLinearin_featuresout_featuresr   r   r   r   r   type
source_clsrequires_grad_set_submoduleloggerwarning)modelr   quantization_configr	   has_been_replacedmodule_namemodule
new_modules           Z/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/integrations/aqlm.pyreplace_with_aqlm_linearr&      s    %$224 )V$[2HI\\&! 	)&")),,&&''D0"5"C"C#6#E#E"5"C"C':'M'M
 )-V
%))%0##K<$(!	) 	))& 	
 L/	) 	)s   B'DD	)NN)__doc__quantizers.quantizers_utilsr   utilsr   r   r   torch.nnr   
get_logger__name__r   liststrr&        r%   <module>r1      sF    B ? / 			H	%+DI<L +r0   