Repository navigation
fix(loading): repack NVFP4 exports on the Gemma 4 Unified route - #3188
Merged
Merged
Conversation
load_gemma4_unified did not repack an NVFP4 export's quantized linears, as load_gemma4_vlm does for Gemma 4. A compressed-tensors (llm-compressor) export of gemma-4-12B failed with Weight not found, and a ModelOpt one reached the linear loaders as packed bytes. The unified weight sanitizer now ends with the shared NVFP4 repack, which is a no-op for a checkpoint without such triplets.
This was referenced Nov 20, 2026
Member
Hardening reviewReviewed against #3187 and the PR body. No code changes pushed. Findings
Security / performance: no new input surface. The repack is the existing shared routine, and the extra pass over the key map is O(keys) once per load. Validation (Apple Silicon, Metal)
|
12 of 19 tasks
inureyes
added a commit
to Jaeyeong-CHOI/mlxcel
that referenced
this pull request
Nov 22, 2026
The Used by list missed the Qwen2.5-VL, Gemma 3 VLM and Gemma 4 Unified loaders that call it directly. Refs lablup#3188
inureyes
added a commit
that referenced
this pull request
Nov 22, 2026
…ute (#3192) * fix(loading): repack NVFP4 exports on the Gemma 4 Unified route load_gemma4_unified did not repack an NVFP4 export's quantized linears, as load_gemma4_vlm does for Gemma 4. A compressed-tensors (llm-compressor) export of gemma-4-12B failed with Weight not found, and a ModelOpt one reached the linear loaders as packed bytes. The unified weight sanitizer now ends with the shared NVFP4 repack, which is a no-op for a checkpoint without such triplets. * fix(loading): map module-layout vision keys on the Gemma 4 Unified route The ModelOpt NVFP4 exports of Gemma 4 12B keep the vision embedder's layers under embed_vision. and its projection under embed_vision.multimodal_embedder., where google/gemma-4-12B-it has vision_embedder.* and embed_vision.embedding_projection. The unified key normalization now maps that layout onto the one the loader reads, so such a checkpoint no longer stops at Weight not found: vision_embedder.patch_ln1.weight. * docs: list every caller of sanitize_modelopt_nvfp4_weights The Used by list missed the Qwen2.5-VL, Gemma 3 VLM and Gemma 4 Unified loaders that call it directly. Refs #3188 --------- Co-authored-by: Jeongkyu Shin <[email protected]>
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
load_gemma4_unifieddid not repack an NVFP4 export's quantized linears, soRedHatAI/gemma-4-12B-it-NVFP4failed withWeight not found. The unified weight sanitizer now ends with the shared NVFP4 repack, asload_gemma4_vlmdoes for the other Gemma 4 checkpoints. It is a no-op for a checkpoint without such triplets.Related issues
Closes #3187.
Type of change
fix— bug fixCause
resolve_and_sanitize_gemma4_unified_weights(src/loading/vlm_gemma_unified.rs) resolved the per-expert scale flags and normalized the keys. It did not callsanitize_modelopt_nvfp4_weights, which the Gemma 4 VLM route reaches throughsanitize_gemma4_nvfp4_weights. A compressed-tensors linear stayed asweight_packed/weight_scale/weight_global_scale, so the text model found noweight; a ModelOpt linear stayed as auint8weightwith its two scales.Change
resolve_and_sanitize_gemma4_unified_weightscallsmodels::sanitize_modelopt_nvfp4_weightsafter the key sanitizer. It runs on the sanitized key names, and it is keyed on the tensors (aweight_scale_2, or aweight_packedwith aweight_global_scale), so a checkpoint without them comes out as before. The doc comment says so.gemma4::ModelArgs, as on the other Gemma 4 route.Before / after
GB10 (sm_121, CUDA 13.0), release builds of
363a0ba6b(main, the base of this branch) and of this PR's tree,generate -n 200 --temp 0,MLXCEL_SDPA_DETERMINISTIC=1. The image is a 448 x 448 red square with a blue square in the middle.main, all four promptsRedHatAI/gemma-4-12B-it-NVFP4@8965ad1c9(compressed-tensors)Error: Failed to load Gemma4 Unified text model: Weight not found: language_model.model.layers.0.self_attn.q_proj.weight, exit 1Paris/4/The vast, restless sea stretches toward the horizon, carrying the secrets of a thousand sunken worlds beneath its rhythmic waves./The two main colors in this image are red and blue.coolthor/gemma-4-12B-it-NVFP4A16@f706714c2(compressed-tensors, weights only)Paris/4/The vast, rhythmic pulse of the ocean carries the secrets of a thousand sunken civilizations beneath its restless surface./The two main colors in this image are red and blue.r0b0tlab/gemma-4-12B-it-nvfp4@9c12a471a(ModelOpt)Error: … Unsupported packed weight: language_model.model.layers.0.self_attn.q_proj.weight is uint8 with …weight_scale, exit 1Error: Failed to load Gemma4 Unified vision embedder: Weight not found: vision_embedder.patch_ln1.weightThe third row is a second gap this PR does not close: that export uses another key layout for the vision embedder (see the issue). Its language model now gets through the repack (328 groups), which is all this PR claims for ModelOpt; the ModelOpt half is otherwise covered by the unit test.
Checkpoints that load today answer byte for byte as on
main: mlx-community/gemma-4-12B-it-4bit @73bcf0909(the unified route, text and image), axteam/gemma-4-E2B-it-NVFP4 (text and image), and the first prompt on gemma-3-4b-it-4bit, mgoin/Qwen3-0.6B-NVFP4, iromu/Gemma3-1B-tools-NVFP4 and nvidia/Qwen2.5-VL-7B-Instruct-NVFP4.Test plan
Run on this PR's commit (one commit on
363a0ba6b, treeb8835fff3ba9) on a DGX Spark (GB10).cargo fmt --all -- --checkcargo clippy --workspace --all-targets --features cuda -- -D warningscargo build --release --features cudasrc/loading/vlm_gemma_unified_tests.rs):unified_nvfp4_export_is_repacked_for_both_producers(a ModelOpt and a compressed-tensors checkpoint are repacked under the sanitized keys, to byte-identical weight maps; the float text and vision-embedder tensors are routed as before) andunified_checkpoint_without_nvfp4_triplets_is_left_as_sanitized(a float tensor, and auint8plane with only aweight_scale, come out byte for byte as the key sanitizer alone leaves them): passcargo test --profile test-fast --features cuda --lib -- loading::vlm gemma4 unified modelopt nvfp4 compressed: 638 passedmake verify-test-cuda(cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1): 16089 passed, 5 failed, 500 ignored. The five are the ones that fail on unmodified363a0ba6bon this host: fourmla::turbo_latenttests (fix(cuda): reductions with a differing output dtype return garbage (sum over bool, any/all over non-bool) #3184, fixed by fix(cuda): write reductions through the output dtype #3185) andcommands::serve::tests::serve_preflight_kv_mode_on_deepseek_v2_follows_the_absorption_decision. This PR touches none of that codeci.ymljobs a fork PR does not get, by hand:clippy(cargo clippy -p mlxcel --lib --tests -- -D warnings, default features); license headers, env-var docs, kernel dtype keys, kernel port dispatch, cross-repo refsxla-compile: not run (no IREE on this host); no XLA file is touchedcargo deny check: not applicable (no manifest or lockfile change)Notes for reviewers
sanitize_gemma4_nvfp4_weightson the other Gemma 4 route, the repack is keyed on the tensors, not onquantization_config.language_model.model.*names and its ownmodel.language_model.remap has nothing to do.Checklist
docs/: not needed (no option or documented behaviour changes)// Used by: ...comments: the caller of the changed function is unchanged