[bugfix] fix quant method validation bug (#4831)

### What this PR does / why we need it?
When `hf_quant_cfg` is not None and `hf_quant_cfg.quant_method == ""`,
func `override_quantization_method` will return None and raise
ValidationError.

### Does this PR introduce _any_ user-facing change?

### How was this patch tested?

- vLLM version: v0.12.0
- vLLM main:
ad32e3e19c

Signed-off-by: zzzzwwjj <1183291235@qq.com>
This commit is contained in:
zzzzwwjj
2025-12-09 23:42:01 +08:00
committed by GitHub
parent 863a5a5a17
commit f404c9af7f
2 changed files with 9 additions and 1 deletions

View File

@@ -66,11 +66,19 @@ class TestAscendQuantConfig(TestBase):
mock_is_available.return_value = True
result = AscendQuantConfig.override_quantization_method(None, None)
self.assertIsNone(result)
hf_quant_cfg = {"quant_method": ""}
result = AscendQuantConfig.override_quantization_method(
hf_quant_cfg, None)
self.assertEqual(result, "ascend")
# Test when NPU is not available
mock_is_available.return_value = False
result = AscendQuantConfig.override_quantization_method(None, None)
self.assertIsNone(result)
hf_quant_cfg = {"quant_method": ""}
result = AscendQuantConfig.override_quantization_method(
hf_quant_cfg, None)
self.assertIsNone(result)
def test_get_quant_method_for_linear(self):
mock_config = MagicMock()

View File

@@ -96,7 +96,7 @@ class AscendQuantConfig(QuantizationConfig):
user_quant) -> Optional[str]:
if hf_quant_cfg is not None:
quant_method = hf_quant_cfg.get("quant_method", None)
if quant_method is None and torch.npu.is_available():
if not quant_method and torch.npu.is_available():
return ASCEND_QUANTIZATION_METHOD
return None