diff --git a/tests/conftest.py b/tests/conftest.py index 05a81c75ea..47071167b5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -349,6 +349,20 @@ _T = TypeVar("_T", nn.Module, torch.Tensor, BatchEncoding, BatchFeature, dict) _R = TypeVar("_R") +def _fix_v4_tied_weights_keys(model_cls: type) -> None: + """Convert a v4 list-format _tied_weights_keys to the transformers v5 dict form.""" + tied = getattr(model_cls, "_tied_weights_keys", None) + if not isinstance(tied, list) or not tied: + return + result = { + k: "model.embed_tokens.weight" + for k in tied + if "lm_head" in k and k.endswith(".weight") + } + if result: + setattr(model_cls, "_tied_weights_keys", result) + + class HfRunner: def get_default_device(self): from vllm.platforms import current_platform @@ -474,6 +488,22 @@ class HfRunner: trust_remote_code=trust_remote_code, ) else: + if trust_remote_code and hasattr(self.config, "auto_map"): + cls_ref = self.config.auto_map.get(auto_cls.__name__) + if cls_ref is not None: + from vllm.transformers_utils.dynamic_module import ( + try_get_class_from_dynamic_module, + ) + + model_cls = try_get_class_from_dynamic_module( + cls_ref, + model_name, + trust_remote_code=trust_remote_code, + warn_on_fail=False, + ) + if model_cls is not None: + _fix_v4_tied_weights_keys(model_cls) + model = cast( nn.Module, auto_cls.from_pretrained( diff --git a/tests/models/registry.py b/tests/models/registry.py index fa23e14d96..d614659b1d 100644 --- a/tests/models/registry.py +++ b/tests/models/registry.py @@ -487,13 +487,6 @@ _TEXT_GENERATION_EXAMPLE_MODELS = { "Plamo2ForCausalLM": _HfExamplesInfo( "pfnet/plamo-2-1b", trust_remote_code=True, - max_transformers_version="4.57", - transformers_version_reason={ - "hf": ( - "Custom model code uses `_tied_weight_keys: list[str]` but " - "Transformers v5 now expects `_tied_weight_keys: dict[str, str]`" - ) - }, ), "Plamo3ForCausalLM": _HfExamplesInfo( "pfnet/plamo-3-nict-2b-base",