[chore] harden checkpoint quantization metadata parsing (#36922)
This commit is contained in:
@@ -14,6 +14,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
from sglang.srt.configs.device_config import DeviceConfig
|
||||
from sglang.srt.configs.load_config import LoadConfig
|
||||
@@ -657,7 +658,7 @@ class TestModelOptFp4LoaderSelection(CustomTestCase):
|
||||
quantization="modelopt_fp4",
|
||||
is_draft_model=True,
|
||||
is_draft_quantization_explicit=is_explicit,
|
||||
hf_config=SimpleNamespace(
|
||||
hf_config=PretrainedConfig(
|
||||
quantization_config={
|
||||
"quant_algo": "NVFP4",
|
||||
"group_size": 16,
|
||||
@@ -757,7 +758,7 @@ class TestModelOptMixedPrecisionConfig(CustomTestCase):
|
||||
with self.subTest(inline_config=inline_config):
|
||||
model_config = SimpleNamespace(
|
||||
quantization="modelopt_mixed",
|
||||
hf_config=SimpleNamespace(
|
||||
hf_config=PretrainedConfig(
|
||||
quantization_config=inline_config,
|
||||
),
|
||||
model_path=model_path,
|
||||
@@ -787,7 +788,7 @@ class TestModelOptMixedPrecisionConfig(CustomTestCase):
|
||||
}
|
||||
model_config = SimpleNamespace(
|
||||
quantization="modelopt_mixed",
|
||||
hf_config=SimpleNamespace(
|
||||
hf_config=PretrainedConfig(
|
||||
quantization_config={
|
||||
"quant_method": "modelopt_mixed",
|
||||
"quant_algo": "MIXED_PRECISION",
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
from sglang.srt.layers.modelopt_utils import canonicalize_modelopt_quant_algo
|
||||
from sglang.srt.layers.quantization.base_config import QuantizationConfig
|
||||
from sglang.srt.model_loader.checkpoint_quantization import (
|
||||
@@ -14,19 +16,6 @@ from sglang.test.test_utils import CustomTestCase
|
||||
register_cpu_ci(est_time=5, suite="base-a-test-cpu")
|
||||
|
||||
|
||||
class _ConfigObject:
|
||||
def __init__(self, **values):
|
||||
self.__dict__.update(values)
|
||||
|
||||
|
||||
class _QuantConfigObject:
|
||||
def __init__(self, values):
|
||||
self._values = values
|
||||
|
||||
def to_dict(self):
|
||||
return self._values
|
||||
|
||||
|
||||
class TestResolveCheckpointQuantSpec(CustomTestCase):
|
||||
def test_modelopt_quant_algo_canonicalization(self):
|
||||
cases = {
|
||||
@@ -75,9 +64,9 @@ class TestResolveCheckpointQuantSpec(CustomTestCase):
|
||||
),
|
||||
)
|
||||
|
||||
def test_text_config_fallback_supports_config_objects(self):
|
||||
config = _ConfigObject(
|
||||
text_config=_ConfigObject(
|
||||
def test_text_config_fallback_supports_pretrained_configs(self):
|
||||
config = PretrainedConfig(
|
||||
text_config=PretrainedConfig(
|
||||
quantization_config={"quant_method": "gptq", "bits": 4}
|
||||
),
|
||||
compression_config={"quant_method": "compressed-tensors"},
|
||||
@@ -90,7 +79,7 @@ class TestResolveCheckpointQuantSpec(CustomTestCase):
|
||||
self.assertEqual(spec.source, "text_config.quantization_config")
|
||||
|
||||
def test_compression_config_fallback(self):
|
||||
config = _ConfigObject(
|
||||
config = PretrainedConfig(
|
||||
compression_config={"quant_method": "compressed-tensors"}
|
||||
)
|
||||
|
||||
@@ -114,18 +103,6 @@ class TestResolveCheckpointQuantSpec(CustomTestCase):
|
||||
self.assertIsNone(spec.declared_method)
|
||||
self.assertEqual(spec.config["quant_algo"], "FP8")
|
||||
|
||||
def test_quant_config_object_is_converted(self):
|
||||
config = _ConfigObject(
|
||||
quantization_config=_QuantConfigObject(
|
||||
{"quant_method": "bitsandbytes", "load_in_4bit": True}
|
||||
)
|
||||
)
|
||||
|
||||
spec = resolve_checkpoint_quant_spec(config)
|
||||
|
||||
self.assertIsNotNone(spec)
|
||||
self.assertEqual(spec.config["load_in_4bit"], True)
|
||||
|
||||
def test_lookup_priority_matches_srt_loader(self):
|
||||
config = {
|
||||
"quantization_config": {},
|
||||
|
||||
Reference in New Issue
Block a user