[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>
This commit is contained in:
co-authored by
Claude
Harry Mellor
parent
1ad84fea86
commit
638d6e9757
@@ -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(
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user