[Bugfix] compressed-tensors: mixed-precision checkpoints silently load unquantized (#32736)
Co-authored-by: Mohammad Miadh Angkad <176301910+mmangkad@users.noreply.github.com>
This commit is contained in:
co-authored by
Mohammad Miadh Angkad
parent
fddfc1fb5e
commit
f69af7b7ad
@@ -305,7 +305,18 @@ class CompressedTensorsConfig(QuantizationConfig):
|
||||
)
|
||||
|
||||
target_scheme_map[target]["input_activations"] = None
|
||||
if is_activation_quantization_format(quant_format):
|
||||
|
||||
# A config_group may carry its own format. When several groups
|
||||
# use different formats, compressed-tensors sets the top-level
|
||||
# format to "mixed-precision" and the real format lives on each
|
||||
# group, so the per-group value must win.
|
||||
group_format = quant_config.get("format")
|
||||
target_scheme_map[target]["format"] = group_format
|
||||
act_quant_format = is_activation_quantization_format(
|
||||
group_format if group_format is not None else quant_format
|
||||
)
|
||||
|
||||
if act_quant_format:
|
||||
input_activations = quant_config.get("input_activations")
|
||||
# When activation quant format is set but no
|
||||
# input_activations provided: valid for w8a16fp8 (FLOAT
|
||||
@@ -572,13 +583,20 @@ class CompressedTensorsConfig(QuantizationConfig):
|
||||
return is_w4 and weight_quant.symmetric and is_token and is_dynamic
|
||||
|
||||
def _get_scheme_from_parts(
|
||||
self, weight_quant: BaseModel, input_quant: BaseModel
|
||||
self,
|
||||
weight_quant: BaseModel,
|
||||
input_quant: BaseModel,
|
||||
format: Optional[str] = None,
|
||||
) -> CompressedTensorsLinearScheme:
|
||||
# The format of the config_group this layer matched, when it declares
|
||||
# one. Falls back to the top-level format, which is "mixed-precision"
|
||||
# (i.e. meaningless on its own) for multi-group checkpoints.
|
||||
quant_format = format if format is not None else self.quant_format
|
||||
|
||||
# Detect If Mixed Precision
|
||||
if self._is_wNa16_group_channel(weight_quant, input_quant):
|
||||
if (
|
||||
self.quant_format == CompressionFormat.pack_quantized.value
|
||||
quant_format == CompressionFormat.pack_quantized.value
|
||||
and weight_quant.num_bits in WNA16_SUPPORTED_BITS
|
||||
):
|
||||
return CompressedTensorsWNA16(
|
||||
@@ -593,7 +611,7 @@ class CompressedTensorsConfig(QuantizationConfig):
|
||||
"Other method (CompressedTensorsW4A16Sparse24) is not supported now"
|
||||
)
|
||||
|
||||
if is_activation_quantization_format(self.quant_format):
|
||||
if is_activation_quantization_format(quant_format):
|
||||
if self._is_fp4a4_nvfp4(weight_quant, input_quant):
|
||||
is_fp4a4_nvfp4_supported = self._check_scheme_supported(
|
||||
CompressedTensorsW4A4Fp4.get_min_capability(), error=False
|
||||
@@ -796,9 +814,11 @@ class CompressedTensorsConfig(QuantizationConfig):
|
||||
scheme_dict = self.get_scheme_dict(layer, layer_name)
|
||||
weight_quant = None
|
||||
input_quant = None
|
||||
scheme_format = None
|
||||
if scheme_dict:
|
||||
weight_quant = scheme_dict.get("weights")
|
||||
input_quant = scheme_dict.get("input_activations")
|
||||
scheme_format = scheme_dict.get("format")
|
||||
|
||||
# Find the sparsity scheme of the layer
|
||||
# assume that fused layers inerhit first component's sparsity scheme
|
||||
@@ -834,6 +854,7 @@ class CompressedTensorsConfig(QuantizationConfig):
|
||||
scheme = self._get_scheme_from_parts( # type: ignore
|
||||
weight_quant=weight_quant,
|
||||
input_quant=input_quant,
|
||||
format=scheme_format,
|
||||
)
|
||||
|
||||
# Raise error if device does not support the scheme
|
||||
|
||||
@@ -80,9 +80,22 @@ def check_equal_or_regex_match(layer_name: str, targets: Iterable[str]) -> bool:
|
||||
"""
|
||||
Checks whether a layer_name is exactly equal or a regex match for
|
||||
if target starts with 're:' to any target in list.
|
||||
|
||||
A plain (non-regex) target additionally matches a dotted-path *suffix* of
|
||||
layer_name, so a target may be written as a module suffix, e.g.
|
||||
"self_attn.kv_b_proj" matches "model.layers.0.self_attn.kv_b_proj".
|
||||
|
||||
It must never match a *prefix*: llm-compressor writes parent modules into
|
||||
the `ignore` list (e.g. "model.layers.0.mlp.experts.0"), and a plain
|
||||
substring match would let such an entry silently swallow its quantized
|
||||
children ("model.layers.0.mlp.experts.0.gate_proj"), dropping the layer
|
||||
back to an unquantized method.
|
||||
"""
|
||||
for target in targets:
|
||||
if _is_equal_or_regex_match(layer_name, target, check_contains=True):
|
||||
if target.startswith("re:"):
|
||||
if _is_equal_or_regex_match(layer_name, target):
|
||||
return True
|
||||
elif target == layer_name or layer_name.endswith("." + target):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user