[Bugfix][CI/Build] Fix Plamo2 HF runner crash on transformers v5 (_tied_weights_keys list→dict) (#44239)
Signed-off-by: Nikhil Kulkarni <nikhilkulkarni1755@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Nikhil Kulkarni committed
Jul 23, 2026 at 05:25 UTC
638d6e97575c49f7e0aa128ae1e775892c92bb1c
2 files changed
+30
-7
tests/conftest.py
+30
@@ -349,6 +349,20 @@ _T = TypeVar("_T", nn.Module, torch.Tensor, BatchEncoding, BatchFeature, dict)
349
_R = TypeVar("_R")
350
351
352
+def _fix_v4_tied_weights_keys(model_cls: type) -> None:
353
+ """Convert a v4 list-format _tied_weights_keys to the transformers v5 dict form."""
354
+ tied = getattr(model_cls, "_tied_weights_keys", None)
355
+ if not isinstance(tied, list) or not tied:
356
+ return
357
+ result = {
358
+ k: "model.embed_tokens.weight"
359
+ for k in tied
360
+ if "lm_head" in k and k.endswith(".weight")
361
+ }
362
+ if result:
363
+ setattr(model_cls, "_tied_weights_keys", result)
364
+
365
+
366
class HfRunner:
367
def get_default_device(self):
368
from vllm.platforms import current_platform
@@ -474,6 +488,22 @@ class HfRunner:
488
trust_remote_code=trust_remote_code,
489
)
490
else:
491
+ if trust_remote_code and hasattr(self.config, "auto_map"):
492
+ cls_ref = self.config.auto_map.get(auto_cls.__name__)
493
+ if cls_ref is not None:
494
+ from vllm.transformers_utils.dynamic_module import (
495
+ try_get_class_from_dynamic_module,
496
+ )
497
+
498
+ model_cls = try_get_class_from_dynamic_module(
499
+ cls_ref,
500
+ model_name,
501
+ trust_remote_code=trust_remote_code,
502
+ warn_on_fail=False,
503
+ )
504
+ if model_cls is not None:
505
+ _fix_v4_tied_weights_keys(model_cls)
506
+
507
model = cast(
508
nn.Module,
509
auto_cls.from_pretrained(
tests/models/registry.py
-7
@@ -487,13 +487,6 @@ _TEXT_GENERATION_EXAMPLE_MODELS = {
487
"Plamo2ForCausalLM": _HfExamplesInfo(
488
"pfnet/plamo-2-1b",
489
trust_remote_code=True,
490
- max_transformers_version="4.57",
491
- transformers_version_reason={
492
- "hf": (
493
- "Custom model code uses `_tied_weight_keys: list[str]` but "
494
- "Transformers v5 now expects `_tied_weight_keys: dict[str, str]`"
495
- )
496
- },
490
),
491
"Plamo3ForCausalLM": _HfExamplesInfo(
492
"pfnet/plamo-3-nict-2b-base",