Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back support for stage.remap_qualname() #934

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Conversation

kwen2501
Copy link
Contributor

Description

stage.remap_qualname(key) maps a stage's parameter name (key) back to the original model's parameter name.

This now works:

    # Stage module's state dict
    sd = stage.submod.state_dict()
    remapped_keys = [stage.remap_qualname(k) for k in sd.keys()]

    # Original model's state dict
    old_keys = mod.state_dict().keys()

    # Confirm they match
    assert all(rk in old_keys for rk in remapped_keys)

print(f"Rank {args.rank} remapped keys: {remapped_keys}")
# Confirm remapped keys are consistent with original model
old_keys = mod.state_dict().keys()
assert all(rk in old_keys for rk in remapped_keys)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wouldn't this evaluate to be True if remapped_keys was a subset of old_keys.

Maybe a better check would be sorted(remapped_keys) == sorted(list(old_keys))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remapped_keys is always a subset of old_keys, because remapped_keys are only keys of a stage, while old_keys contains keys of the full original model.

@kwen2501 kwen2501 merged commit e51c8b9 into main Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants