From 7e262b6496b7efb66c7b50f4f96da04881e6f8e8 Mon Sep 17 00:00:00 2001 From: Zhiyu Date: Wed, 11 Feb 2026 19:08:29 -0800 Subject: [PATCH] Update modelopt quantization config parsing (#13919) Signed-off-by: Zhiyu Cheng --- python/sglang/srt/configs/model_config.py | 17 +++++++++++++++++ python/sglang/srt/model_loader/weight_utils.py | 2 ++ 2 files changed, 19 insertions(+) diff --git a/python/sglang/srt/configs/model_config.py b/python/sglang/srt/configs/model_config.py index 60adccb0d..998defbaf 100644 --- a/python/sglang/srt/configs/model_config.py +++ b/python/sglang/srt/configs/model_config.py @@ -626,6 +626,17 @@ class ModelConfig: # adapted from https://github.com/vllm-project/vllm/blob/v0.6.4.post1/vllm/config.py def _parse_quant_hf_config(self): quant_cfg = getattr(self.hf_config, "quantization_config", None) + if quant_cfg is not None and not isinstance(quant_cfg, dict): + quant_cfg = quant_cfg.to_dict() + if quant_cfg is not None: + # Identify modelopt quantization + if "quant_method" not in quant_cfg: + parsed_cfg = self._parse_modelopt_quant_config( + {"quantization": quant_cfg} + ) + if parsed_cfg: + quant_cfg.update(parsed_cfg) + if quant_cfg is None: # compressed-tensors uses a "compression_config" key quant_cfg = getattr(self.hf_config, "compression_config", None) @@ -736,6 +747,12 @@ class ModelConfig: def _is_already_quantized(self) -> bool: """Check if the model is already quantized based on config files.""" + # Check for quantization in hf_config (config.json) + if getattr(self.hf_config, "quantization_config", None) or getattr( + self.hf_config, "compression_config", None + ): + return True + # Check for HuggingFace quantization config from sglang.srt.utils import has_hf_quant_config diff --git a/python/sglang/srt/model_loader/weight_utils.py b/python/sglang/srt/model_loader/weight_utils.py index e4371a3b6..17055e1c7 100644 --- a/python/sglang/srt/model_loader/weight_utils.py +++ b/python/sglang/srt/model_loader/weight_utils.py @@ -197,6 +197,8 @@ def get_quant_config( # compressed-tensors uses a compressions_config hf_quant_config = getattr(model_config.hf_config, "compression_config", None) if hf_quant_config is not None: + if not isinstance(hf_quant_config, dict): + hf_quant_config = hf_quant_config.to_dict() hf_quant_config["packed_modules_mapping"] = packed_modules_mapping return quant_cls.from_config(hf_quant_config)