Validate freeze and unfreeze keys against the whole model when recursing - #3966
Open
ayaangazali wants to merge 1 commit into
Open
Validate freeze and unfreeze keys against the whole model when recursing#3966ayaangazali wants to merge 1 commit into
ayaangazali wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
freezeandunfreezedocumentkeys="bias"as a whole model operation ("freeze all biases by callingmodule.freeze(keys="bias")", andunfreeze's example isnn.Transformer()thenmodel.unfreeze(keys="bias")). But withstrict=Truethey validate the keys separately inside every visited submodule, so the first submodule without a bias aborts the whole call. That makes the two documented features unusable together on any model with mixed layers, including the bundledTransformer:It happens because
MultiHeadAttention's projections default tobias=Falsewhile the MLPLinearlayers default tobias=True, so the traversal hits a module with nobiasand raises even though six of them exist.When recursing, this now checks the keys once against the whole model and only raises if a key is present nowhere. Behavior that stays the same:
KeyError, including when it is one entry in a listrecurse=Falsestill validates against just that modulestrict=Falseand the no-keys case are untouchedChecklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes(the new test fails on main with the
KeyErrorand passes here;test_nn.pyis green)If you would rather read
strictas per module and keep the current behavior, then the docstrings are what need changing instead, and I am glad to flip this into a docs only PR.about me: freshman contributor, and i do use Claude Code while hunting for these, but i traced this one to the bias=False projections in MultiHeadAttention myself and checked the recurse and strict combinations by hand before writing it up. tell me if the whole model reading is not the one you intended.