[Bugfix][Model] Validate DefaultModelLoader / LoadConfig and fail with clear errors (#45196)
Signed-off-by: Ting Sun <suntcrick@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from vllm.config import ModelConfig
|
||||
from vllm.config.load import LoadConfig
|
||||
from vllm.model_executor.model_loader import get_model_loader, register_model_loader
|
||||
from vllm.model_executor.model_loader.base_loader import BaseModelLoader
|
||||
from vllm.model_executor.model_loader.default_loader import DefaultModelLoader
|
||||
|
||||
|
||||
@register_model_loader("custom_load_format")
|
||||
@@ -33,3 +34,57 @@ def test_invalid_model_loader():
|
||||
@register_model_loader("invalid_load_format")
|
||||
class InValidModelLoader:
|
||||
pass
|
||||
|
||||
|
||||
def test_default_loader_rejects_zero_num_threads():
|
||||
# num_threads=0 used to fail late in ThreadPoolExecutor ("max_workers must be > 0").
|
||||
with pytest.raises(ValueError, match="num_threads"):
|
||||
DefaultModelLoader(
|
||||
LoadConfig(
|
||||
model_loader_extra_config={
|
||||
"enable_multithread_load": True,
|
||||
"num_threads": 0,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_default_loader_rejects_multithread_with_non_lazy_strategy():
|
||||
# The multi-thread loader ignores safetensors_load_strategy; reject the
|
||||
# combination instead of silently dropping the requested strategy.
|
||||
with pytest.raises(ValueError, match="does not support"):
|
||||
DefaultModelLoader(
|
||||
LoadConfig(
|
||||
safetensors_load_strategy="torchao",
|
||||
model_loader_extra_config={"enable_multithread_load": True},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_default_loader_explicit_safetensors_does_not_misread_pt(tmp_path):
|
||||
# Explicit safetensors must not fall back to a .pt and open it as safetensors.
|
||||
(tmp_path / "model.pt").write_bytes(b"\x00\x00\x00\x00")
|
||||
loader = DefaultModelLoader(LoadConfig(load_format="safetensors"))
|
||||
with pytest.raises(RuntimeError, match="Cannot find any model weights"):
|
||||
loader._prepare_weights(
|
||||
str(tmp_path),
|
||||
None,
|
||||
None,
|
||||
fall_back_to_pt=True,
|
||||
allow_patterns_overrides=None,
|
||||
)
|
||||
|
||||
|
||||
def test_default_loader_hf_still_falls_back_to_pt(tmp_path):
|
||||
# Control: load_format="hf" still picks up .pt weights via fallback.
|
||||
(tmp_path / "model.pt").write_bytes(b"\x00\x00\x00\x00")
|
||||
loader = DefaultModelLoader(LoadConfig(load_format="hf"))
|
||||
_, files, use_safetensors = loader._prepare_weights(
|
||||
str(tmp_path),
|
||||
None,
|
||||
None,
|
||||
fall_back_to_pt=True,
|
||||
allow_patterns_overrides=None,
|
||||
)
|
||||
assert use_safetensors is False
|
||||
assert any(f.endswith("model.pt") for f in files)
|
||||
|
||||
@@ -1557,3 +1557,14 @@ def test_ir_op_priority_ctx():
|
||||
# context restored even after exception
|
||||
assert ir.ops.rms_norm.get_priority() == ["vllm_c", "native"]
|
||||
assert ir.ops.fused_add_rms_norm.get_priority() == ["native"]
|
||||
|
||||
|
||||
def test_load_config_rejects_invalid_safetensors_load_strategy():
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
LoadConfig(safetensors_load_strategy="not_a_real_strategy")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bad_load_format", [None, 123])
|
||||
def test_load_config_rejects_non_string_load_format(bad_load_format):
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
LoadConfig(load_format=bad_load_format)
|
||||
|
||||
Reference in New Issue
Block a user