镜像自地址
https://github.com/MINT-SJTU/Evo-RL.git
已同步 2026-11-20 18:17:06 +00:00
fix(pi05): restore tied embed tokens on load (#20)
Co-authored-by: shiki42 <shiki42@users.noreply.github.com>
这个提交包含在:
@ -1097,6 +1097,14 @@ class PI05Policy(PreTrainedPolicy):
|
|||||||
# Some checkpoints might have this, but current model expects different structure
|
# Some checkpoints might have this, but current model expects different structure
|
||||||
logging.warning(f"Vision embedding key might need handling: {key}")
|
logging.warning(f"Vision embedding key might need handling: {key}")
|
||||||
|
|
||||||
|
if (
|
||||||
|
key == "model.paligemma_with_expert.paligemma.lm_head.weight"
|
||||||
|
or key == "paligemma_with_expert.paligemma.lm_head.weight"
|
||||||
|
):
|
||||||
|
fixed_state_dict[
|
||||||
|
"model.paligemma_with_expert.paligemma.model.language_model.embed_tokens.weight"
|
||||||
|
] = value.clone()
|
||||||
|
|
||||||
fixed_state_dict[new_key] = value
|
fixed_state_dict[new_key] = value
|
||||||
|
|
||||||
return fixed_state_dict
|
return fixed_state_dict
|
||||||
|
|||||||
@ -166,3 +166,22 @@ def test_config_creation():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Config creation failed: {e}")
|
print(f"Config creation failed: {e}")
|
||||||
raise
|
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()
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户