L i5ddlZddlmZmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZdd l m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'dd l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddlm?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGide%de)de+d e7d!e!d"e?d#eAd$e5d%e/d&e9d'e;d(e-d)e1d*eEd+e'd,eGd-eCe3e#e=d.ZHide de de d%ed ed!e d"ed#ed$ed'ed(ed)ed&ed*ed+e d,ed-eee ed.ZIejeKZLGd/d0ZMGd1d2ZNd3eOfd4ZPd5eOfd6ZQd7ZRy)8N)OptionalUnion) AutoConfig)logging) AqlmConfigAutoRoundConfig AwqConfigBitNetQuantConfigBitsAndBytesConfigCompressedTensorsConfig EetqConfigFbgemmFp8ConfigFineGrainedFP8Config FPQuantConfig GPTQConfig HiggsConfig HqqConfig Mxfp4ConfigQuantizationConfigMixinQuantizationMethod QuantoConfig QuarkConfig SpQRConfig TorchAoConfig VptqConfig) HfQuantizer)AqlmHfQuantizer)AutoRoundQuantizer) AwqQuantizer)BitNetHfQuantizer)Bnb4BitHfQuantizer)Bnb8BitHfQuantizer)CompressedTensorsHfQuantizer)EetqHfQuantizer)FbgemmFp8HfQuantizer)FineGrainedFP8HfQuantizer)FPQuantHfQuantizer)GptqHfQuantizer)HiggsHfQuantizer)HqqHfQuantizer)Mxfp4HfQuantizer)QuantoHfQuantizer)QuarkHfQuantizer)SpQRHfQuantizer)TorchAoHfQuantizer)VptqHfQuantizerawqbitsandbytes_4bitbitsandbytes_8bitgptqaqlmquantoquarkfp_quanteetqhiggshqqzcompressed-tensors fbgemm_fp8torchaobitnetvptqspqr)fp8z auto-roundmxfp4c6eZdZdZedefdZedZy)AutoQuantizationConfigz The Auto-HF quantization config class that takes care of automatically dispatching to the correct quantization config given a quantization config stored in a dictionary. quantization_config_dictc v|jd}|jdds|jddr*|jddrdnd}tj|z}n | td|tvr,td|d t t jt|}|j|S) N quant_method load_in_8bitF load_in_4bit_4bit_8bitThe model's quantization config from the arguments has no `quant_method` attribute. Make sure that the model has been correctly quantizedUnknown quantization type, got  - supported types are: ) getrBITS_AND_BYTES ValueError AUTO_QUANTIZATION_CONFIG_MAPPINGlistAUTO_QUANTIZER_MAPPINGkeys from_dict)clsrGrIsuffix target_clss b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/quantizers/auto.pyrXz AutoQuantizationConfig.from_dictys/33NC # ' ' >BZB^B^_motBu 8 < <^U SWY`F-<>>( # #r]rFczeZdZdZedeeeffdZedZ edeeefde efdZ e dZ y) AutoHfQuantizerz The Auto-HF quantizer class that takes care of automatically instantiating to the correct `HfQuantizer` given the `QuantizationConfig`. r_c Dt|trtj|}|j}|t j k(r|jr|dz }n|dz }|tvr,td|dttjt|}||fi|S)NrMrLrOrP) isinstancerlrFrXrIrrRrJrVrSrUrW)rYr_rerIr[s r\ from_configzAutoHfQuantizer.from_configs )4 0"8"B"BCV"W *77  -<< <"//' ' 5 51,@/44678:  ,L9 -888r]c Ptj|fi|}|j|S)N)rFrarq)rYrdrer_s r\razAutoHfQuantizer.from_pretraineds*4DDEbmflm233r]quantization_config_from_argsc |d}nd}t|tr;t|trtj|}ntj|}|g|j j |j j k7r:td|j j d|j j dt|ttttttfrW|U|j}|jD]\}}t||||dt!|j#dz }|dk7r't|tst%j&||St(j+||S)z handles situations where both quantization_config from args and quantization_config from model config are present. zYou passed `quantization_config` or equivalent parameters to `from_pretrained` but the model you're loading already has a `quantization_config` attribute. The `quantization_config` from the model will be used.zThe model is quantized with z but you are passing a z| config. Please make sure to pass the same quantization config class to `from_pretrained` with different loading attributes.z"However, loading attributes (e.g. z]) will be overwritten with the one you passed to `from_pretrained`. The rest will be ignored.)rprlr rXrF __class__rgrSrr rr rget_loading_attributesitemssetattrrUrWwarningswarnloggerinfo)rYr_rs warning_msgloading_attr_dictattrvals r\merge_quantization_configsz*AutoHfQuantizer.merge_quantization_configss ) 4y  K )4 07I&5&?&?@S&T#&<&F&FGZ&[# * 5#--66:W:a:a:j:jj./B/L/L/U/U.VVmoLoVoVo_o_n``FF  #YJacno .9 = T T V .446 8 c+T37 8 ?EVE[E[E]@^?_`}~ ~K " Z0C[%Q MM+ &#" KK $""r]c ^|jdd}|jdds|jddr*|jddrdnd}tj|z}n | td|tvr8t j d|d ttjd yy ) NrIrJFrKrLrMrNrOrPz~. Hence, we will skip the quantization. To remove the warning, you can delete the quantization_config attribute in config.jsonT) rQrrRrSrTr|warningrUrVrW)rGrIrZs r\supports_quant_methodz%AutoHfQuantizer.supports_quant_methods/33NDI # ' ' >BZB^B^_motBu 8 < <^U SWY`F-<.register_config_fn sH 5 5xx/CDE E#67HI I36(0 r]r`)rrs` r\register_quantization_configr s r]namecfd}|S)zRegister a custom quantizer.c~tvrtddt|ts td|t<|S)Nz Quantizer 'rz!Quantizer must extend HfQuantizer)rVrSrr)rYrs r\register_quantizer_fnz1register_quantizer..register_quantizer_fnsG ) ){4&0DEF F#{+@A A'*t$ r]r`)rrs` r\register_quantizerrs ! r]cLt|d}|r!tj|jsd}|s|Q|r&tj |j||_n||_tj |j|} nd} | | j |||||| j|}| j|}| j|}| j|}t| jdds&| jj} t| d| |d<| |||fS)Nr_F) pre_quantized)dtypefrom_tf from_flax device_map weights_only dequantizevaluequant) hasattrrnrr_rrqvalidate_environment update_dtypeupdate_device_mapupdate_tp_planupdate_ep_planrbrI) configr_rrrrr user_agentr hf_quantizerrIs r\get_hf_quantizerr*s8F$9:M_BB6C]C]^ +7 )8)S)S**,?*F &*=F &&22  & &'3  ))!% * ))%0!33J? ,,V4,,V4|77uM';;HHL"),"NJw   22r])Srztypingrrmodels.auto.configuration_autorutilsrutils.quantization_configrr r r r r rrrrrrrrrrrrrrrbaserquantizer_aqlmrquantizer_auto_roundr quantizer_awqr!quantizer_bitnetr"quantizer_bnb_4bitr#quantizer_bnb_8bitr$quantizer_compressed_tensorsr%quantizer_eetqr&quantizer_fbgemm_fp8r'quantizer_finegrained_fp8r(quantizer_fp_quantr)quantizer_gptqr*quantizer_higgsr+ quantizer_hqqr,quantizer_mxfp4r-quantizer_quantor.quantizer_quarkr/quantizer_spqrr0quantizer_torchaor1quantizer_vptqr2rVrT get_loggerrgr|rFrnstrrrrr`r]r\rs"7.+4'/22F+6@2+-)-/-+1+ <++ O   O     " O  >6&!   O!" O#$ %$ ).$ 9$+$+$ J $  J $  J $ l$ [$ $ 9$1$/$ [$}$ $  J!$" J#$$ ! )$ .   H %&#&#Rkk\   !S ! %3r]