L i ddlmZddlmZerddlmZddlmZmZeje Z ddd d d d d ddZ GddeZ y)) TYPE_CHECKING) HfQuantizer)PreTrainedModel)is_quark_availableloggingzweight_quantizer.scalezbias_quantizer.scalezinput_quantizer.scalezoutput_quantizer.scalezweight_quantizer.zero_pointzbias_quantizer.zero_pointzinput_quantizer.zero_pointzoutput_quantizer.zero_point) weight_scale bias_scale input_scale output_scaleweight_zero_pointbias_zero_pointinput_zero_pointoutput_zero_pointcxeZdZdZdZdgZdZfdZdZddZ ddd e d e fd Z d Z dd ZddZedZxZS)QuarkHfQuantizerz? Quark quantizer (https://quark.docs.amd.com/latest/). Tquarkc Ht||fi||j|_yN)super__init__json_export_config)selfquantization_configkwargs __class__s m/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_quark.pyrzQuarkHfQuantizer.__init__7s$ ,77"5"H"Hc.ts tdy)NzLoading a Quark quantized model requires the `quark` library but it was not found in the environment. Please refer to https://quark.docs.amd.com/latest/install.html.)r ImportError)rargsrs rvalidate_environmentz%QuarkHfQuantizer.validate_environment<s !#x $rmodelrc ddlm}|||jj|jj |jj |S)Nr) _map_to_quark) pack_method custom_mode)quark.torch.export.apir&r quant_configrr'r()rr$rr&s r$_process_model_before_weight_loadingz5QuarkHfQuantizer._process_model_before_weight_loadingBsD8   $ $ 1 1//;;00<<   r param_namereturnc y)NT)rr$r,rs rparam_needs_quantizationz)QuarkHfQuantizer.param_needs_quantizationNsrc ddlm}|jdd}|tvr|j |t|}||||j |y)Nr)_load_parameter_into_model.)modeling_utilsr2splitCHECKPOINT_KEYSreplaceto)rr$paramr, param_devicerr2postfixs rcreate_quantized_paramz'QuarkHfQuantizer.create_quantized_paramQsN?""3'+ o %#++G_W5MNJ"5*ehh|6LMrc |Srr/)rr$rs r#_process_model_after_weight_loadingz4QuarkHfQuantizer._process_model_after_weight_loading[s rcyNFr/)rsafe_serializations ris_serializablez QuarkHfQuantizer.is_serializable^srcyrAr/)rs r is_trainablezQuarkHfQuantizer.is_trainableasr)r$rr)__name__ __module__ __qualname____doc__requires_calibrationrequired_packages requires_parameters_quantizationrr#r+strboolr0r=r?rCpropertyrE __classcell__)rs@rrr*sp   (,$I  .?S_cNrrN)typingrbaserr5rutilsrr get_loggerrFloggerr7rr/rrrVsY !0/   H %-(*,6246 9{9r