fix(pi05): restore tied embed tokens on load (#20)

Co-authored-by: shiki42 <shiki42@users.noreply.github.com>
这个提交包含在:
Shuyuan
2026-04-12 16:51:40 +08:00
提交者 GitHub
父节点 081d826f26
当前提交 ddb0738a76
共有 2 个文件被更改,包括 27 次插入 和 0 次删除

查看文件

@ -166,3 +166,22 @@ def test_config_creation():
except Exception as e:
print(f"Config creation failed: {e}")
raise
@pytest.mark.parametrize(
"lm_head_key",
[
"paligemma_with_expert.paligemma.lm_head.weight",
"model.paligemma_with_expert.paligemma.lm_head.weight",
],
)
def test_fix_pytorch_state_dict_keys_restores_tied_embed_tokens(lm_head_key: str):
policy = object.__new__(PI05Policy)
lm_head = torch.randn(8, 4)
fixed = PI05Policy._fix_pytorch_state_dict_keys(policy, {lm_head_key: lm_head}, model_config=None)
embed_tokens_key = "model.paligemma_with_expert.paligemma.model.language_model.embed_tokens.weight"
assert embed_tokens_key in fixed
assert torch.equal(fixed[embed_tokens_key], lm_head)
assert fixed[embed_tokens_key].data_ptr() != lm_head.data_ptr()