Repository navigation
Conversation
…rnel A ModelOpt NVFP4 Gemma 3 checkpoint carries a per-tensor scale (weight_scale_2, loaded as QuantizedWeight::global_scale) on every projection. The fused Gemma MLP kernel has no argument for it, so the three projections ran unscaled and the model generated noise without an error. fused_mlp_quantized_weights now declines a projection with a global scale and the MLP runs projection by projection, where UnifiedLinear::forward applies the scale.
…used-mlp-global-scale
compiled_swiglu_mlp (SmolLM3, StableLM, Exaone4, Jamba) hands its three quantized projections to compiled_moe_expert_forward, which has no argument for a ModelOpt per-tensor global_scale and takes one layout for all three. It had the same silent bug as the Gemma MLP: a ModelOpt NVFP4 checkpoint would run unscaled, and a mixed-bit checkpoint would throw at the first forward. It now goes through fused_mlp_quantized_weights and returns None in both cases, so the callers take their per-projection forwards. Unscaled, same-layout projections keep the fused kernel. Adds a_compiled_swiglu_mlp_declines_a_projection_with_a_tensor_scale; it fails with the guard removed. The Used-by notes now name the real callers. Refs lablup#3142, lablup#3143
Hardening reviewReviewed against #3142. The guard in Same bug found elsewhere and fixed here (0f5e669): Noted, not changed: Llama3's opt-in fused causal prefill (env-gated) reads Also merged Validation (Mac Studio M3 Ultra, Metal):
|
Summary
A ModelOpt NVFP4 Gemma 3 checkpoint generated noise: the fused Gemma MLP kernel has no argument for the per-tensor scale (
QuantizedWeight::global_scale) such a checkpoint carries on every projection, so the MLP ran unscaled.fused_mlp_quantized_weightsnow declines a projection with a global scale, and the MLP runs projection by projection, whereUnifiedLinear::forwardapplies it.Related issues
Closes #3142.
Type of change
fix— bug fixCause
MLP::forwardinsrc/models/gemma3.rs(alsogemma.rs,gemma2.rs) callscompiled_gelu_approx_mlp_forwardwheneverfused_mlp_quantized_weights(mlxcel-corelayers.rs) returns the three planes. That function filters layouts that differ between the projections (#2999), but notglobal_scale. ModelOpt NVFP4 stores the second-level scaleweight_scale_2per tensor; the loader keeps it asglobal_scaleandUnifiedLinear::forwardmultiplies it in after the matmul. The fused kernel takes only weight, block scales and biases, so all three projections ran without it and the error compounds through every layer.Change
fused_mlp_quantized_weightsreturnsNonewhen any of the three projections has aglobal_scale, beside the existing layout check. The callers already fall back to their per-projection forward onNone. The doc comment says why.Before / after
GB10 (sm_121, CUDA 13.0), release builds of
fab141b1a(main, the base of this branch) and of this PR,generate -n 64 --temp 0,MLXCEL_SDPA_DETERMINISTIC=1.mainiromu/Gemma3-1B-tools-NVFP4@ec7bf1aee6d4Chor démontréne-secầnन्न اقدامات FA…ParisThe question also былоaj trés EK EK DHOT …4了 then possible... } 有ાર很了 প্যাকে…The sea is a vast and powerful body of water teeming with life and mystery.APMIC/ACE-gemma-3-4b-it-nvfp4@d8d6d7db9203The three given non-zero twinnings have to be worked in a. …Paris2. Set all the information a truly 2 sh, if 2.00, …4The sea of V's end, beginning to take, In the I.e. SoCCo …The sea is a big, blue ocean that has waves and salty water, and it's where many people and animals like to play and swim.Gemma checkpoints without a global scale take the fused path as before and answer the first prompt (200 tokens) byte for byte as on
main: gemma-3-270m-it-4bit, gemma-3-270m-it-8bit, gemma-3-1b-it-DQ (mixed bits), gemma-3-4b-it-4bit, gemma-2-2b-it-4bit.Test plan
Run on this PR's commit (one commit on
fab141b1a, tree1b4acdf4ef84) on a DGX Spark (GB10).cargo fmt --all -- --checkcargo clippy --workspace --all-targets --features cuda -- -D warningscargo build --release --features cudaa_fused_mlp_takes_no_projection_with_a_tensor_scale(mlxcel-core: a scale on any one of the three projections declines the fused path, none takes it),a_gemma3_mlp_preserves_each_projection_global_scale(MLP::forwardagainst the three projections run separately, five scale combinations) anda_disk_loaded_gemma3_mlp_preserves_modelopt_tensor_scales(the same throughload_text_weightsfrom ModelOpt triplets on disk): pass. The two MLP tests skip where the backend has no native NVFP4 kernelcargo test --profile test-fast --features cuda --lib -- models::gemma models::sanitize modelopt nvfp4: 316 passedfused_mlp_quantized_weights: all three new tests failmake verify-test-cuda, on this commit together with two unrelated branches of mine (Qwen3.5 MoE loader, test-onlypaged_detachfixture): 15917 passed, 1 failed, 498 ignored. The one failure was a test of the Qwen3.5 branch (its reference, since fixed) and does not touch this change; the three tests above pass in that runci.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
gemma3::ModelArgs::group_size()still falls back to 64 for a ModelOpt config, so these checkpoints log onequantized layout does not match declared metadatawarning per linear (104 for the 1B, 136 for the 4B). Since fix(quant): load ModelOpt W4A16_NVFP4 checkpoints in families without a ModelOpt group size #3026 the mode comes from the shapes, so the planes load as NVFP4 and the answers above are right; giving Gemma the ModelOpt group-size accessor Qwen3 has would silence them, and is left out of this one-cause PR.fused_mlp_quantized_weights, so they get the same guard; I found no ModelOpt export of either to run.Checklist
docs/: not needed (no option or documented behaviour changes)// Used by: ...comments: unchanged callers (Gemma 1, 2, 3 MLPs)