Repository navigation
fix(gemma4): honor per-module MLP quant overrides - #690
Merged
Merged
Conversation
5 tasks
…a4-quant-overrides # Conflicts: # src/models/gemma4.rs
5 tasks done
inureyes
added a commit
that referenced
this pull request
Jul 8, 2026
## Summary PR #690 added Gemma 4 per-module MLP quantization overrides through a flattened `overrides` map on `QuantizationArgs`, but a malformed override value (a non-object value, a wrong-typed/negative/zero `group_size`, or an unsupported `bits` width) silently fell back to the root defaults with no indication anything was wrong, which is a debugging hazard for quantization frontier work. ## What changed - `QuantizationArgs::quant_params_for` in `src/models/gemma4.rs` now validates the override entry matched by the queried module `prefix` before applying it, reporting an actionable `tracing::warn!` naming the offending key for a non-object override value, a wrong-typed or negative `group_size`/`bits`, a zero group size, or an unsupported bit width (mlxcel only supports the affine `{2,3,4,5,6,8}` set), then falls back to the root defaults for that field exactly as before. - Added two small validation helpers, `validate_override_group_size` and `validate_override_bits`, that produce the actionable reason strings used in the warnings. - Metadata keys that legitimately live alongside per-module overrides in the same flattened map (`mode`, `quant_method`, `quant_algo`, `config_groups`) are untouched because they never coincide with a real module-prefix lookup, so they are never mistaken for malformed overrides. - Added a `quant_override_diagnostics_tests` module in `src/models/gemma4.rs` covering valid full and partial overrides, absent overrides, a non-object override value, string-typed and negative/zero/unsupported-width numeric fields, sibling metadata keys, and a typo'd prefix that simply never matches. ## Test plan - [x] `cargo check -p mlxcel --features cuda --lib` - [x] `cargo test -p mlxcel --features cuda --lib models::gemma4::quant` (24 tests, all pass, including the 11 new diagnostics tests and the pre-existing `quant_scheme_tests`) - [x] `cargo test -p mlxcel --features cuda --lib models::gemma4_tests` (9 pass, 8 ignored for serial MLX execution as before, including the existing `gemma4_root_quantization_preserves_per_module_overrides` regression test, confirming valid configs load unchanged) - [x] `cargo clippy -p mlxcel --features cuda --lib --tests` (no warnings touching `gemma4.rs`; the crate has one pre-existing unrelated `redundant_closure` warning in `src/models/sanitize.rs` that predates this change) - [x] `cargo fmt -p mlxcel -- --check` Closes #691
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
## Summary PR lablup#690 added Gemma 4 per-module MLP quantization overrides through a flattened `overrides` map on `QuantizationArgs`, but a malformed override value (a non-object value, a wrong-typed/negative/zero `group_size`, or an unsupported `bits` width) silently fell back to the root defaults with no indication anything was wrong, which is a debugging hazard for quantization frontier work. ## What changed - `QuantizationArgs::quant_params_for` in `src/models/gemma4.rs` now validates the override entry matched by the queried module `prefix` before applying it, reporting an actionable `tracing::warn!` naming the offending key for a non-object override value, a wrong-typed or negative `group_size`/`bits`, a zero group size, or an unsupported bit width (mlxcel only supports the affine `{2,3,4,5,6,8}` set), then falls back to the root defaults for that field exactly as before. - Added two small validation helpers, `validate_override_group_size` and `validate_override_bits`, that produce the actionable reason strings used in the warnings. - Metadata keys that legitimately live alongside per-module overrides in the same flattened map (`mode`, `quant_method`, `quant_algo`, `config_groups`) are untouched because they never coincide with a real module-prefix lookup, so they are never mistaken for malformed overrides. - Added a `quant_override_diagnostics_tests` module in `src/models/gemma4.rs` covering valid full and partial overrides, absent overrides, a non-object override value, string-typed and negative/zero/unsupported-width numeric fields, sibling metadata keys, and a typo'd prefix that simply never matches. ## Test plan - [x] `cargo check -p mlxcel --features cuda --lib` - [x] `cargo test -p mlxcel --features cuda --lib models::gemma4::quant` (24 tests, all pass, including the 11 new diagnostics tests and the pre-existing `quant_scheme_tests`) - [x] `cargo test -p mlxcel --features cuda --lib models::gemma4_tests` (9 pass, 8 ignored for serial MLX execution as before, including the existing `gemma4_root_quantization_preserves_per_module_overrides` regression test, confirming valid configs load unchanged) - [x] `cargo clippy -p mlxcel --features cuda --lib --tests` (no warnings touching `gemma4.rs`; the crate has one pre-existing unrelated `redundant_closure` warning in `src/models/sanitize.rs` that predates this change) - [x] `cargo fmt -p mlxcel -- --check` Closes lablup#691
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.
Summary
Honor Gemma 4 per-module quantization overrides so the #683 frontier variants generated by
scripts/requantize_mlp.pycan load with their declared MLP layouts instead of relying on ambiguous shape inference.What changed
config.quantizationper-module override entries when promoting them intoTextConfig, including DiffusionGemma's shared Gemma 4 text path.bitsandgroup_size, which fixes group_size=32 4-bit variants and mixed down-proj-8-bit variants.UnifiedLinear::forward()calls so each projection uses its own parameters.Frontier result
The C/D variants now load and run
examples/perplexity.rs. On the README 512-token single-chunk quality gate, uniform 4-bit remained the best of this set (mean_nll=8.18222), while shipped mixed was8.40327, down8 was8.45547, and gs32 was8.53010; the recorded data is inbenchmarks/cuda_gb10_gemma4_frontier_683_2026-07-08.csv.Test plan
Closes #683