
    qi                         d Z ddlmZ ddlmZ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)	z7SpQR (Sparse-Quantized Representation) integration file   )should_convert_module)is_spqr_availableis_torch_availablelogging    Nmodules_to_not_convertc                 p   t               rddlm} d}| j                         D ]  \  }}t	        ||      st        j                  d      5  t        |t        j                        r|j                  }j                  |j                  |j                  |j                  |j                  |j                   || d   || d   || d   || d   		      }| 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 (`SpQRConfig`):
            The quantization config object that contains the quantization parameters.
    r   )QuantizedLinearFmetaz.dense_weights.shapez.row_offsets.shapez.col_vals.shapez.in_perm.shape)	rowscolsbitsbeta1beta2dense_weights_shaperow_offsets_shapecol_vals_shapein_perm_shapeTNzYou 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.)r   
spqr_quantr
   named_modulesr   torchdevice
isinstancennLinearshapescreate_placehodlerout_featuresin_featuresr   r   r   _modulesrequires_grad_set_submoduleloggerwarning)	modelr   quantization_configr
   has_been_replacedmodule_namemoduler   
new_modules	            P/opt/pipecat/venv/lib/python3.12/site-packages/transformers/integrations/spqr.pyreplace_with_spqr_linearr,      sJ    .$224 )V$[2HI\\&! 	)&")),,33,??,,++,11-33-33(.+>R/S(T&,}<N-O&P#)[M*I#J"(K=)G"H @ 

 {+::5A##K<$(!%	) 	)), 	
 L5	) 	)s   B=D++D5	)NN)__doc__quantizers.quantizers_utilsr   utilsr   r   r   r   torch.nnr   
get_logger__name__r#   liststrr,        r+   <module>r7      sH    : ? B B 			H	%/DI<L /r6   