PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
add warnings for lm_head activation scale fallback (#1728)
Heng Guo99d49574e945
diff --git a/auto_round/compressors/base.py b/auto_round/compressors/base.pyindex 69fbb2b57..985ccfc46 100644--- a/auto_round/compressors/base.py+++ b/auto_round/compressors/base.py@@ -2079,6 +2079,12 @@ class BaseCompressor(object):for layer_name in copy.deepcopy(layer_names):if layer_name not in layer_inputs:if self.act_bits < 16 and not self.act_dynamic:+ if "lm_head" in layer_name:+ logger.warning_once(+ "Static activation quantization for lm_head is not fully supported yet. "+ "If lm_head calibration inputs are missing, activation scale may fall back to unit scale "+ "or quantization may be skipped."+ )# Activation quantization requires collected inputsmsg_prefix = (f"Activation max hook for layer '{layer_name}' is unavailable due to "diff --git a/auto_round/wrapper.py b/auto_round/wrapper.pyindex a48a654be..9b329624e 100644--- a/auto_round/wrapper.py+++ b/auto_round/wrapper.py@@ -538,6 +538,7 @@ class WrapperLinear(torch.nn.Module):class WrapperWALayer(torch.nn.Module):+def __init__(self, orig_layer, enable_torch_compile=False, device="cpu"):super(WrapperWALayer, self).__init__()self.orig_layer = orig_layer@@ -806,6 +807,19 @@ def unwrapper_layer(model, layer, layer_name, best_params):if hasattr(layer, "orig_layer"):orig_layer = layer.unwrapper(best_params)+ act_max = getattr(orig_layer, "act_max", None)+ act_scale = getattr(orig_layer, "act_scale", None)+ if (+ "lm_head" in layer_name+ and getattr(layer, "enable_act_quant", False)+ and not getattr(orig_layer, "act_dynamic", True)+ and act_scale is not None+ and act_max is None+ ):+ logger.warning_once(+ "Static activation quantization for lm_head is not fully supported yet. "+ "lm_head activation statistics are missing, so activation scale falls back to unit scale."+ )orig_layer = orig_layer.to("cpu")set_module(model, layer_name, orig_layer)