Update modelopt quantization config parsing (#13919)
Signed-off-by: Zhiyu Cheng <zhiyuc@nvidia.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user