Preserve revision pins in secondary artifact loaders (#51446)

Signed-off-by: Clinton Thomas <1033162+KernelClint@users.noreply.github.com>
Co-authored-by: Lucas Bourtoule <35483370+dhalf@users.noreply.github.com>
This commit is contained in:
Clinton Thomas
2026-08-11 04:33:10 +00:00
committed by GitHub
co-authored by Lucas Bourtoule
parent adc1200597
commit 90fd4a333f
11 changed files with 226 additions and 13 deletions
+27
View File
@@ -7,6 +7,7 @@ from copy import copy
from pathlib import Path
from types import SimpleNamespace
from typing import cast
from unittest.mock import Mock
import pytest
from transformers import PretrainedConfig
@@ -138,6 +139,32 @@ def test_head_size_falls_back_when_head_dim_is_zero():
assert convertor.get_head_size() == 128
def test_qk_rope_head_dim_recovery_uses_model_revision(monkeypatch: pytest.MonkeyPatch):
hf_config = PretrainedConfig(
model_type="deepseek_v2",
qk_rope_head_dim=128,
qk_nope_head_dim=128,
)
hf_config.name_or_path = "org/model"
get_hf_file_to_dict = Mock(return_value={"qk_rope_head_dim": 64})
monkeypatch.setattr(
"vllm.transformers_utils.repo_utils.get_hf_file_to_dict",
get_hf_file_to_dict,
)
convertor = ModelArchConfigConvertorBase(
hf_config,
hf_config,
revision="pinned-revision",
)
assert convertor._get_qk_rope_head_dim() == 64
get_hf_file_to_dict.assert_called_once_with(
"config.json", "org/model", "pinned-revision"
)
@pytest.mark.parametrize(
"attribute",
[
+40
View File
@@ -0,0 +1,40 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from types import SimpleNamespace
from unittest.mock import Mock
import pytest
import torch
from vllm.config.vllm import VllmConfig
pytestmark = [pytest.mark.cpu_test, pytest.mark.skip_global_cleanup]
def test_quantization_config_forwards_model_revision(monkeypatch: pytest.MonkeyPatch):
quant_config = Mock()
quant_config.get_min_capability.return_value = 0
quant_config.get_supported_act_dtypes.return_value = [torch.float32]
model_config = SimpleNamespace(
quantization="auto_gptq",
model="repo/model",
hf_config=object(),
dtype=torch.float32,
revision="pinned-revision",
)
monkeypatch.setattr(
"vllm.model_executor.model_loader.weight_utils.get_quant_config",
lambda model_config, load_config: quant_config,
)
monkeypatch.setattr(
"vllm.platforms.current_platform.get_device_capability", lambda: None
)
VllmConfig._get_quantization_config(model_config, SimpleNamespace())
quant_config.maybe_update_config.assert_called_once_with(
"repo/model",
hf_config=model_config.hf_config,
revision="pinned-revision",
)
+51
View File
@@ -0,0 +1,51 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import contextlib
import io
from types import SimpleNamespace
from unittest.mock import Mock
import pytest
import torch
from vllm.model_executor.model_loader import tensorizer
pytestmark = [pytest.mark.cpu_test, pytest.mark.skip_global_cleanup]
def test_serialize_vllm_model_forwards_model_revision(
monkeypatch: pytest.MonkeyPatch,
):
@contextlib.contextmanager
def fake_open_stream(*args, **kwargs):
yield io.BytesIO()
snapshot_download = Mock()
monkeypatch.setattr(tensorizer, "open_stream", fake_open_stream)
monkeypatch.setattr(tensorizer, "TensorSerializer", Mock())
monkeypatch.setattr(
tensorizer,
"hf_api",
lambda: SimpleNamespace(snapshot_download=snapshot_download),
)
model = torch.nn.Module()
tensorizer_config = SimpleNamespace(
_construct_tensorizer_args=lambda: SimpleNamespace(
tensorizer_uri="/tmp/model.tensors",
tensorizer_dir="/tmp/out",
stream_kwargs={},
),
encryption_keyfile=None,
_is_sharded=False,
serialization_kwargs=None,
)
model_config = SimpleNamespace(
served_model_name="repo/model",
revision="pinned-revision",
)
tensorizer.serialize_vllm_model(model, tensorizer_config, model_config)
assert snapshot_download.call_args.args == ("repo/model",)
assert snapshot_download.call_args.kwargs["revision"] == "pinned-revision"
+47
View File
@@ -6,7 +6,15 @@ only get the `eos_token_id` from the tokenizer as defined by
`BaseRenderer.get_eos_token_id`.
"""
from types import SimpleNamespace
from typing import cast
from unittest.mock import patch
from transformers import PretrainedConfig
from vllm.config.model import ModelConfig
from vllm.tokenizers import get_tokenizer
from vllm.transformers_utils import config as config_module
from vllm.transformers_utils.config import try_get_generation_config
@@ -30,3 +38,42 @@ def test_get_blip2_eos_token():
generation_config = try_get_generation_config(model_name, trust_remote_code=False)
assert generation_config is not None
assert generation_config.eos_token_id == 50118
def test_model_config_generation_fallback_forwards_code_revision():
model_config = cast(
ModelConfig,
SimpleNamespace(
generation_config="auto",
hf_config_path=None,
model="org/model",
trust_remote_code=True,
revision="model-pin",
code_revision="code-pin",
config_format="auto",
hf_token=None,
),
)
with (
patch.object(
config_module.GenerationConfig,
"from_pretrained",
side_effect=OSError,
),
patch.object(
config_module,
"get_config",
return_value=PretrainedConfig(),
) as get_config,
):
ModelConfig.try_get_generation_config(model_config)
get_config.assert_called_once_with(
"org/model",
trust_remote_code=True,
revision="model-pin",
code_revision="code-pin",
config_format="auto",
token=None,
)