CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
quantizer_spqr.cpython-310.pyc25 linesDownload Raw Back to __pycache__
1o

20�Yi��@s�ddlmZmZddlmZerddlmZddlmZddl	m3Z4mZmZm
Z
ddlmZe�r5dd	lZe
�e�ZGd5d�de�Zd	S)�)�
TYPE_CHECKING�Optional�)�HfQuantizer�)�PreTrainedModel)�replace_with_spqr_linear)�is_accelerate_available�is_spqr_available�is_torch_available�logging)�QuantizationConfigMixinNcszeZdZdZdZdef�fdd�Zdd�Zddd�Z	
dddde	e6efdd�Zddd�Z
edd��Zddd�Z�ZS)�SpQRHfQuantizerzS7    Quantizer of the SpQR method. Enables the loading of prequantized models.8    T�quantization_configcst�j|fi|��||_dS�N)�super�__init__r)�selfr�kwargs��	__class__���E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\transformers/quantizers/quantizer_spqr.pyr(s9zSpQRHfQuantizer.__init__cOs2tj��s	td��t�std��t�std��dS)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�cudaZis_available�RuntimeErrorr	�ImportErrorr10)r�argsrrrr�validate_environment,s11�z$SpQRHfQuantizer.validate_environment�dtype�torch.dtype�returncCs2|durtj}t�d�|S|tjkrtd��|S)NzHAssuming SpQR inference on GPU and loading the model in `torch.float16`.z|You cannot use any type other than torch.float16 for SpQR. Please either leave it None or set it totorch.float16 explicitly.)rZfloat16�logger�info�12ValueError)rrrrr�update_dtype6s1314��zSpQRHfQuantizer.update_dtypeN�modelr�keep_in_fp32_modulescKs4|�||jj|�|_t||j|jd�|j|j_dS)N)r�modules_to_not_convert)Zget_modules_to_not_convertrr(r�config)rr&r'rrrr�$_process_model_before_weight_loadingAs15��z4SpQRHfQuantizer._process_model_before_weight_loadingcKs|Srr)rr&rrrr�#_process_model_after_weight_loadingR�z3SpQRHfQuantizer._process_model_after_weight_loadingcC�dS)NFr)rrrr�is_trainableUszSpQRHfQuantizer.is_trainablecCr-)NTr)rZsafe_serializationrrr�is_serializableYr,zSpQRHfQuantizer.is_serializable)rr r!r r)r&r)�__name__�16__module__�__qualname__�__doc__Zrequires_calibrationr
rrr%r�list�strr*r+�propertyr.r/�
__classcell__rrrrr!s 17 18��19202122r)�typingrr�baserZmodeling_utilsrZintegrationsr�utilsr	r23rrZutils.quantization_configr
rZ24get_loggerr0r"rrrrr�<module>s
25
Aluode/PerceptionLabPortable · CoolFace