-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Register buffer init callbacks in llama #32428
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
base: main
Are you sure you want to change the base?
Conversation
|
Hi @kwen2501, thanks for opening this PR! cc'ing @muellerzr as this likely overlaps with accelerate's handling of weights loading and @ArthurZucker re Llama |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
muellerzr
left a comment
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.
Thanks, nice job finding this fix. cc @SunMarc
ArthurZucker
left a comment
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.
Thanks! I remember this is required for some specific usage with torch that we talked about! Let's iterate 🤗
| # Create buffer init callbacks by extending the one from `LlamaModel`, | ||
| # i.e. appending a prefix to all buffer FQNs. | ||
| for key, val in self.model.buf_init_callbacks.items(): | ||
| new_key = ".".join(["model", key]) | ||
| self.buf_init_callbacks[new_key] = val |
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.
IMO this should go in the LlamaPreTrainedModel at best!
| self.original_inv_freq = self.inv_freq | ||
|
|
||
| # Save buffer init callback | ||
| LlamaModel.buf_init_callbacks.setdefault("rotary_emb.inv_freq", init_inv_freq) |
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.
can this not be called in the LlamaModel directly, it's a bit weird for us to register something like this at the class level
What does this PR do?
Non-persistent buffers is not saved in state dict.
In the case of meta init, while loading state dict from checkpoint can fill in parameters and persistent buffers, we need a way to initialize non-persistent buffers.
This PR does so by registering a buffer's init function against the buffer's FQN, and attaching such a callback dict to the model.
For how the init callbacks can be used, please refer to the
init_buffersutility in this PR:pytorch/PiPPy#1135
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.