[Bugfix][Quantization] Detect NVFP4 in ModelOpt mixed-precision checkpoints (#56050)
Signed-off-by: Stefano Castagnetta <scastagnetta@nvidia.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
fa212b8dc5
commit
f0b4b36890
+24
-1
@@ -124,6 +124,22 @@ _RUNNER_CONVERTS: dict[RunnerType, list[ConvertType]] = {
|
||||
"draft": [],
|
||||
}
|
||||
|
||||
|
||||
def _modelopt_mixed_has_nvfp4(quant_config: dict[str, Any] | None) -> bool:
|
||||
"""Whether a ModelOpt MIXED_PRECISION checkpoint quantizes any layer to NVFP4.
|
||||
|
||||
``W4A16_NVFP4`` is excluded on purpose: it quantizes weights only, so there
|
||||
is no activation quantization for the fusion passes to act on.
|
||||
"""
|
||||
layers = (quant_config or {}).get("quantized_layers")
|
||||
if not isinstance(layers, dict):
|
||||
return False
|
||||
return any(
|
||||
isinstance(info, dict) and info.get("quant_algo") == "NVFP4"
|
||||
for info in layers.values()
|
||||
)
|
||||
|
||||
|
||||
AttnTypeStr = Literal[
|
||||
"decoder", "encoder", "encoder_only", "encoder_decoder", "attention_free", "hybrid"
|
||||
]
|
||||
@@ -2249,13 +2265,20 @@ class ModelConfig:
|
||||
return getattr(self.hf_config, "quantization_config", None) is not None
|
||||
|
||||
def is_nvfp4_quantized(self) -> bool:
|
||||
quant_config = self.model_arch_config.quantization_config
|
||||
|
||||
# ModelOpt NVFP4 checkpoints resolve to modelopt_fp4 quantization method
|
||||
if self.quantization in ("modelopt_fp4",):
|
||||
return True
|
||||
|
||||
# A checkpoint mixing NVFP4 with another algorithm declares
|
||||
# quant_algo MIXED_PRECISION and resolves to modelopt_mixed, so the
|
||||
# per-layer algorithms decide.
|
||||
if self.quantization == "modelopt_mixed":
|
||||
return _modelopt_mixed_has_nvfp4(quant_config)
|
||||
|
||||
# For Compressed Tensors we look for `"format": "nvfp4-pack-quantized"`
|
||||
# in the quantization config
|
||||
quant_config = self.model_arch_config.quantization_config
|
||||
return (
|
||||
self.quantization == "compressed-tensors"
|
||||
and quant_config is not None
|
||||
|
||||
Reference in New Issue
Block a user