[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:
@@ -66,11 +66,19 @@ class TestAscendQuantConfig(TestBase):
|
|||||||
mock_is_available.return_value = True
|
mock_is_available.return_value = True
|
||||||
result = AscendQuantConfig.override_quantization_method(None, None)
|
result = AscendQuantConfig.override_quantization_method(None, None)
|
||||||
self.assertIsNone(result)
|
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
|
# Test when NPU is not available
|
||||||
mock_is_available.return_value = False
|
mock_is_available.return_value = False
|
||||||
result = AscendQuantConfig.override_quantization_method(None, None)
|
result = AscendQuantConfig.override_quantization_method(None, None)
|
||||||
self.assertIsNone(result)
|
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):
|
def test_get_quant_method_for_linear(self):
|
||||||
mock_config = MagicMock()
|
mock_config = MagicMock()
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class AscendQuantConfig(QuantizationConfig):
|
|||||||
user_quant) -> Optional[str]:
|
user_quant) -> Optional[str]:
|
||||||
if hf_quant_cfg is not None:
|
if hf_quant_cfg is not None:
|
||||||
quant_method = hf_quant_cfg.get("quant_method", 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 ASCEND_QUANTIZATION_METHOD
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user