From a76cac2c3bb9c0c9edf36980f86d1fcac4c2c56a Mon Sep 17 00:00:00 2001 From: Sunny-bot1 <592045536@qq.com> Date: Fri, 26 Sep 2025 16:46:13 +0800 Subject: [PATCH] fix machete pre quant --- fastdeploy/model_executor/layers/linear.py | 1 + fastdeploy/model_executor/layers/quantization/weight_only.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fastdeploy/model_executor/layers/linear.py b/fastdeploy/model_executor/layers/linear.py index d17ab1be34..b8f65fb492 100644 --- a/fastdeploy/model_executor/layers/linear.py +++ b/fastdeploy/model_executor/layers/linear.py @@ -128,6 +128,7 @@ def __init__( self.with_bias = with_bias self.add_bias = add_bias self.prefix = prefix + self.is_quantized = fd_config.model_config.is_quantized # key if weight_key: self.weight_key = f"{prefix}.{weight_key}" diff --git a/fastdeploy/model_executor/layers/quantization/weight_only.py b/fastdeploy/model_executor/layers/quantization/weight_only.py index 070d0fbf41..8d18b86075 100644 --- a/fastdeploy/model_executor/layers/quantization/weight_only.py +++ b/fastdeploy/model_executor/layers/quantization/weight_only.py @@ -20,6 +20,7 @@ import paddle from paddle.nn.quant import weight_quantize +from paddleformers.utils.log import logger from fastdeploy import envs from fastdeploy.model_executor.layers.linear import ( @@ -159,9 +160,11 @@ def get_quant_method(self, layer) -> Optional[QuantMethodBase]: if ( _ENABLE_MACHETE and envs.FD_USE_MACHETE == "1" + and not layer.is_quantized and layer.weight_shape[1] and layer.weight_shape[1] % 128 == 0 ): + logger.info("Using Machete kernel for WeightOnlyLinearMethod") return MacheteWeightOnlyLinearMethod(self) return GPUWeightOnlyLinearMethod(self) @@ -399,7 +402,7 @@ def __init__( super().__init__(quant_config) def process_prequanted_weights(self, layer, state_dict) -> None: - pass + raise NotImplementedError("Machete kernel doesn't support prequant. Please set FD_USE_MACHETE to 0.") def process_loaded_weights(self, layer, weight) -> None: from fastdeploy.model_executor.layers.quantization.ops import (