From 638d6e97575c49f7e0aa128ae1e775892c92bb1c Mon Sep 17 00:00:00 2001 From: Nikhil Kulkarni Date: Thu, 23 Jul 2026 05:25:14 -0700 Subject: [PATCH] =?UTF-8?q?[Bugfix][CI/Build]=20Fix=20Plamo2=20HF=20runner?= =?UTF-8?q?=20crash=20on=20transformers=20v5=20(=5Ftied=5Fweights=5Fkeys?= =?UTF-8?q?=20list=E2=86=92dict)=20(#44239)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikhil Kulkarni Co-authored-by: Claude Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> --- tests/conftest.py | 30 ++++++++++++++++++++++++++++++ tests/models/registry.py | 7 ------- 2 files changed, 30 insertions(+), 7 deletions(-) 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",