Raise a clear error for an invalid quantization mode in nn layers#3914
Open
ayaangazali wants to merge 1 commit into
Open
Raise a clear error for an invalid quantization mode in nn layers#3914ayaangazali 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
mx.quantizevalidates itsmodeargument and gives a clear message, but thennquantized layers hit a bare dict lookup first, so a typo'd mode surfaces as a rawKeyErrorwith no hint about what is wrong or which modes exist:Same
KeyErrorforQuantizedEmbedding,QQLinear,from_linear,from_embedding, andnn.quantize(model, mode=...), since all of them call_defaults_for_modebefore anything reachesmx.quantize.This adds the missing check in
_defaults_for_modeso those paths raise aValueErrorthat names the valid modes instead. Added the cases totest_quantize; they fail on main withKeyError: 'xyz'and pass with the change.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes(test_nn.py 69/69 and test_quantized.py 32/32 pass locally on CPU)
heads up on process: i'm a freshman contributor and i use Claude Code to help me hunt for things like this, but i reproduced every one of those
KeyErrorpaths myself, checked that the valid modes list matchesmode_defaults, and confirmed the new test actually fails on main before opening this. if you'd rather word the error differently or put the check somewhere else, happy to change it.