-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[core] support tensor-valued _extra_state values in from_pretrained
#38155
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
[core] support tensor-valued _extra_state values in from_pretrained
#38155
Conversation
TransformerEngine uses the pytorch get/set_extra_state API to store FP8 layer config information as bytes Tensor in the _extra_state entry in the state dict. With recent changes to from_pretrained, this functionality has broken and loading a model that uses this API doesn't appear to work. This PR fixes the save/load pretrained functions for extra state entries that use a pytorch tensor, and adds a (currently x-failing) test for a dictionary extra state. Signed-off-by: Peter St. John <pstjohn@nvidia.com>
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the |
from_pretrained
from_pretrained
from_pretrained
@Cyrilvallez, gentle ping for review. Thanks! The test failure seemed like a timeout issue, let me know if you want me to try running this again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually looks like a nice feature!
I am just curious, don't we need to also call set_extra_state
somewhere?
Also is this bound by any version of torch?
Thanks for the review! No, torch will internally call
I haven't done a full bisection, but I think this is more of a bug fix than a new feature. IIUC when to/from pretrained leveraged more of PyTorch's state_dict machinery this would have been supported out of the box. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, that works for me! Thanks! Merging 🤗
What does this PR do?
TransformerEngine uses the pytorch get/set_extra_state API to store FP8 layer config information as a Tensor in the
_extra_state
entry in the state dict. With recent changes to from_pretrained, this functionality has broken and loading a model that uses this API doesn't appear to work. This PR fixes the save/load pretrained functions for extra state entries that use a pytorch tensor, and adds a (currently x-failing) test for a dictionary extra state.Fixes #38154
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
RFR @Cyrilvallez, @ArthurZucker.