-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Simplify keep_in_fp32_modules logic #36722
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
Conversation
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the |
|
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. |
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.
Nice! One thing that is missing: a check to enforce at init time, like the TP plan, that the layers actually exist in the model?
I think for Blip2 and T5 there might be weirdness, but at least show a warning !
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.
Also some documentation is missing + maybe deprecate nion re pattern no?
|
I just modified blip2 so that no model in the library can have the flag set to a non-existing layer (😮💨), so I don't think we actually need a check at init time - IMO it would clutter the code for something that would never happen. It can add it to be super super safe though! |
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.
LGTM, IMO from_pretrained should be checking the layer names to make sure typos are avoided for example
ba157c2 to
4db38b0
Compare
* better regex everywhere * fix * Update test_modeling_instructblip.py * BC with explanations this time otherwise it makes no sense at all * Update test_modeling_instructblip.py * style * CIs * update _keep_in_fp32_modules in blip2 * Update modeling_utils.py * Update modeling_utils.py * style * CIs * add check * trigger CIs * Update modeling_utils.py * trigger CIs
What does this PR do?
As per the title. It's easier to use a regex from the beginning compared to start with a list, then switch to regex near the end of the loading logic.
Also, make sure that only full layer names can be matched with the regex. Otherwise some old and bad layer names such as
woin T5 could be match against layers such asword_embedding, which containswo.Also, use the flag only when loading in fp16 or using a quantizer expecting it, as
_keep_in_fp32_moduleswas introduced only to avoid issues when casting bf16 -> fp16. See #20287 for details. That is, the layers should not always be kept in fp32, despite the name of the flag... I added a detailed comment about that because it is not clear at all otherwise