
    Z j
                         S SK Jr  SSKJr  \(       a  SSKJr  SSKJr  SSKJ	r	  SSK
JrJrJrJr  SS	KJr  \" 5       (       a  S S
Kr\R"                  " \5      r " S S\5      rg
)    )TYPE_CHECKING   )HfQuantizer   )PreTrainedModel)
SpQRConfig)replace_with_spqr_linear)is_accelerate_availableis_spqr_availableis_torch_availablelogging)QuantizationConfigMixinNc                   x   ^  \ rS rSr% SrSrS\S'   S\4U 4S jjrS r	SS jr
  SS	 jr\S
 5       rS rSrU =r$ )SpQRHfQuantizer"   zK
Quantizer of the SpQR method. Enables the loading of prequantized models.
Tr   quantization_configc                 (   > [         TU ]  " U40 UD6  g )N)super__init__)selfr   kwargs	__class__s      w/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/quantizers/quantizer_spqr.pyr   SpQRHfQuantizer.__init__*   s    ,77    c                     [         R                  R                  5       (       d  [        S5      e[	        5       (       d  [        S5      e[        5       (       d  [        S5      eg )Nz,GPU is required to run SpQR quantized model.zGUsing `spqr` quantization requires Accelerate: `pip install accelerate`zFUsing `spqr` quantization requires SpQR: `pip install spqr_quant[gpu]`)torchcudais_availableRuntimeErrorr
   ImportErrorr   )r   argsr   s      r   validate_environment$SpQRHfQuantizer.validate_environment-   sP    zz&&((MNN&((ghh ""fgg #r   c                 D    U[         R                  :w  a  [        S5      eU$ )NzdYou cannot use any type other than torch.float16 for SpQR. Please set it totorch.float16 explicitly.)r   float16
ValueError)r   dtypes     r   update_dtypeSpQRHfQuantizer.update_dtype7   s%    EMM!v  r   c                     U R                  XR                  R                  UR                  5      U l        [	        UU R                  U R                  S9  g )N)r   modules_to_not_convert)get_modules_to_not_convertr   r,   _keep_in_fp32_modulesr	   )r   modelr   s      r   $_process_model_before_weight_loading4SpQRHfQuantizer._process_model_before_weight_loading>   sM    
 '+&E&E++BBED_D_'
# 	! $ 8 8#'#>#>	
r   c                     g)NF r   s    r   is_trainableSpQRHfQuantizer.is_trainableL   s    r   c                     g)NTr3   r4   s    r   is_serializableSpQRHfQuantizer.is_serializableP   s    r   )r,   )r(   torch.dtypereturnr:   )r/   r   )__name__
__module____qualname____firstlineno____doc__requires_calibration__annotations__r   r   r#   r)   r0   propertyr5   r8   __static_attributes____classcell__)r   s   @r   r   r   "   sY      %%8,C 8h
 
   r   r   )typingr   baser   modeling_utilsr   utils.quantization_configr   integrationsr	   utilsr
   r   r   r   r   r   
get_loggerr<   loggerr   r3   r   r   <module>rN      sN    !  06 3 [ [ ? 			H	%/k /r   