
    qi'                         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)	z9VPTQ (Vector Post-Training Quantization) integration file   )should_convert_module)is_torch_availablelogging    Nmodules_to_not_convertc                    ddl m} d}|j                  }|j                  }| j	                         D ]  \  }}t        ||      st        j                  d      5  t        |t        j                        r|j                  |d      xs$ |j                  |j                  d      d   d      }	 ||j                  |j                  |	d   |	d	   |	d
   |	d   |	d   |	d   |	d   |	d   |	d   dd|j                  du      }
| j                   |   j#                  d       | j%                  ||
       d}ddd       	 |st&        j)                  d       | S # 1 sw Y   -xY w)a]  
    Public method that replaces the Linear layers of the given model with SPQR 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 (`VptqConfig`):
            The quantization config object that contains the quantization parameters.
    r   )VQuantLinearFmetaN.   vector_lensnum_centroidsnum_res_centroids	group_num
group_sizeoutlier_sizeindices_as_floatenable_normenable_permT)r   r   r   r   r   r   r   r   r   is_indice_packedenable_proxy_errorbiaszYou 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.)vptqr	   shared_layer_configconfig_for_layersnamed_modulesr   torchdevice
isinstancennLineargetrsplitin_featuresout_featuresr   _modulesrequires_grad_set_submoduleloggerwarning)modelr   quantization_configr	   has_been_replacedr   r   module_namemodulelayer_params
new_modules              P/opt/pipecat/venv/lib/python3.12/site-packages/transformers/integrations/vptq.pyreplace_with_vptq_linearr3      s    "-AA+==$224 )V$[2HI\\&! 	)&")),044[$G  K^KbKb&&s+A.L *&&'' ,] ;"."?&23F&G*;7+L9!-n!=%12D%E ,] ; ,] ;%)',D0
" {+::5A##K<$(!1	) 	)): 	
 LC	) 	)s   CEE	)NN)__doc__quantizers.quantizers_utilsr   utilsr   r   r   torch.nnr    
get_logger__name__r)   liststrr3        r2   <module>r>      sE    < ? / 			H	%7DI<L 7r=   