Repository navigation
docs: record Metal NVFP4 native benchmark (#694) - #702
Merged
Merged
Conversation
Record the issue #694 Apple Silicon A/B for the ModelOpt Gemma 4 NVFP4 checkpoint on M1 Ultra. The native NVFP4 opt-in cuts cold-load time and improves decode, but misses the required 2048-token prefill gate, so the non-CUDA default remains the affine fallback. Validation: - cargo build --release --bin mlxcel --bin mlxcel-bench-decode - cargo test --release nvfp4_ - ./target/release/mlxcel-bench-decode A/B runs for affine fallback and MLXCEL_NVFP4_NATIVE_REPACK=1 on short and 2048-token prompts - ./target/release/mlxcel generate 40-token greedy parity spot-check for affine fallback and native opt-in Closes #694
Member
Author
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
|
This was referenced Jul 9, 2026
inureyes
added a commit
that referenced
this pull request
Jul 9, 2026
## Summary - Make direct ModelOpt-triplet to MLX native NVFP4 the default on Metal/non-CUDA, matching the CUDA default while keeping `MLXCEL_NVFP4_DENSE_REPACK=1` as the dense-affine rollback path. - Add a native-NVFP4 prefill-friendly Gemma 4 scaled MLP path: multi-token group_size=16/bits=4/mode=nvfp4 now uses a shape-specific compiled graph that folds the `weight_scale_2` sidecars and GeGLU activation without using the decode-oriented shapeless qmm graph. - Add a sidecar-aware quantized linear C++ helper so standalone native-NVFP4 `UnifiedLinear` projections can preserve `apply_global_scale` semantics through one C++ boundary, with `MLXCEL_DISABLE_FUSED_GLOBAL_SCALE` still restoring the op-at-a-time rollback. - Document the 512-16384 token M1 Ultra sweep and update the NVFP4 environment-variable semantics for the new native default. ## Validation scope Issue #705 follows the #694 / #702 native-vs-affine Metal comparison on the local `models/gemma-4-31b-it-nvfp4` ModelOpt NVFP4 checkpoint. The earlier issue wording that named Llama 4 Scout has been corrected in the issue body; this PR's full sweep uses the same local Gemma 4 ModelOpt NVFP4 validation target rather than a reduced-size substitute. ## Benchmark summary | Prompt tokens | Affine prefill tok/s | Native prefill tok/s | Native prefill gap | Native decode speedup | Peak memory delta | Load speedup | |---:|---:|---:|---:|---:|---:|---:| | 512 | 123.38 | 118.49 | -4.0% | 2.67x | -3.27 GB | 2.70x | | 1024 | 126.71 | 117.46 | -7.3% | 2.68x | -4.44 GB | 2.68x | | 2048 | 126.50 | 117.12 | -7.4% | 2.65x | -7.66 GB | 2.67x | | 4096 | 118.07 | 112.88 | -4.4% | 2.75x | -10.15 GB | 2.66x | | 8192 | 116.88 | 111.39 | -4.7% | 2.64x | -10.61 GB | 2.72x | | 16384 | 115.86 | 108.10 | -6.7% | 2.51x | -12.32 GB | 2.71x | The prefill gap is reduced on the mid-length cases that previously showed the largest regression, but it is not eliminated; native remains about 4-7% slower than affine for prefill on this M1 Ultra run. The default switch is based on the overall trade-off requested in #705: native load is about 2.7x faster, decode is 2.5-2.75x faster, and peak memory is 3.3-12.3 GB lower across the sweep. The dense-affine rollback remains available for prefill-sensitive A/B runs. ## Activation-path follow-up Because native prefill still trails affine, this PR also rechecked the #701 path choice on the current Metal/MLX 0.32.1 baseline. At 2048 prompt tokens, the default shape-specific scaled MLP measured 116.10 tok/s, the op-at-a-time sidecar path with compiled GeGLU activation (`MLXCEL_DISABLE_FUSED_GLOBAL_SCALE=1`) measured 116.11 tok/s, and the C++ eager fold (`MLXCEL_COMPILED_QGELU_MLP=0`) measured 113.35 tok/s. At 8192 prompt tokens, the same paths measured 110.66, 109.99, and 108.10 tok/s respectively. This does not support switching native prefill back to the compiled-activation fallback; the #701 eager-fold warning still holds on this Metal baseline. ## Test plan - [x] `cargo test --release -p mlxcel-core quantized_linear_forward_global_scale_matches_manual_sidecar_path -- --nocapture` - [x] `cargo test --release -p mlxcel-core compiled_qgelu_mlp_global_scale -- --nocapture` - [x] `cargo test --release -p mlxcel gemma4::quant_scheme_tests::dense_mlp_scaled_fused_path_eligible -- --nocapture` - [x] `cargo test --release -p mlxcel sanitize::tests::nvfp4_repack_strategy_matrix -- --nocapture` - [x] `cargo test --release -p mlxcel load_and_sanitize_weights_repacks_nvfp4_gemma4_checkpoint -- --nocapture` - [x] `cargo test --release -p mlxcel load_and_sanitize_weights_dense_repack_env_keeps_non_cuda_affine_rollback -- --nocapture` - [x] `cargo build --release --bin mlxcel-bench-decode` - [x] `git diff --check` - [x] `python3 scripts/ci/check_cross_repo_refs.py` - [x] `mlxcel-bench-decode` native-default vs `MLXCEL_NVFP4_DENSE_REPACK=1` sweep at 512, 1024, 2048, 4096, 8192, and 16384 prompt tokens - [x] `mlxcel-bench-decode` native default vs `MLXCEL_DISABLE_FUSED_GLOBAL_SCALE=1` vs `MLXCEL_COMPILED_QGELU_MLP=0` at 2048 and 8192 prompt tokens Closes #705
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
## Summary - Record the issue lablup#694 Apple Silicon native-NVFP4 A/B for the local `gemma-4-31b-it-nvfp4` ModelOpt checkpoint on Mac Studio M1 Ultra. - Keep the Metal/non-CUDA default on the affine fallback because the native opt-in regressed 2048-token prefill by 7.2% instead of meeting the required 20% improvement gate. - Update the earlier GB10 direct-transcode note so its Apple Silicon runbook points at the completed M1 Ultra result. ## Test plan - [x] `cargo build --release --bin mlxcel --bin mlxcel-bench-decode` - [x] `cargo test --release nvfp4_` - [x] Affine fallback and `MLXCEL_NVFP4_NATIVE_REPACK=1` `mlxcel-bench-decode` runs on short and 2048-token prompts - [x] Affine fallback and native opt-in 40-token greedy continuation spot-check with `mlxcel generate` Closes lablup#694
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
## Summary - Make direct ModelOpt-triplet to MLX native NVFP4 the default on Metal/non-CUDA, matching the CUDA default while keeping `MLXCEL_NVFP4_DENSE_REPACK=1` as the dense-affine rollback path. - Add a native-NVFP4 prefill-friendly Gemma 4 scaled MLP path: multi-token group_size=16/bits=4/mode=nvfp4 now uses a shape-specific compiled graph that folds the `weight_scale_2` sidecars and GeGLU activation without using the decode-oriented shapeless qmm graph. - Add a sidecar-aware quantized linear C++ helper so standalone native-NVFP4 `UnifiedLinear` projections can preserve `apply_global_scale` semantics through one C++ boundary, with `MLXCEL_DISABLE_FUSED_GLOBAL_SCALE` still restoring the op-at-a-time rollback. - Document the 512-16384 token M1 Ultra sweep and update the NVFP4 environment-variable semantics for the new native default. ## Validation scope Issue lablup#705 follows the lablup#694 / lablup#702 native-vs-affine Metal comparison on the local `models/gemma-4-31b-it-nvfp4` ModelOpt NVFP4 checkpoint. The earlier issue wording that named Llama 4 Scout has been corrected in the issue body; this PR's full sweep uses the same local Gemma 4 ModelOpt NVFP4 validation target rather than a reduced-size substitute. ## Benchmark summary | Prompt tokens | Affine prefill tok/s | Native prefill tok/s | Native prefill gap | Native decode speedup | Peak memory delta | Load speedup | |---:|---:|---:|---:|---:|---:|---:| | 512 | 123.38 | 118.49 | -4.0% | 2.67x | -3.27 GB | 2.70x | | 1024 | 126.71 | 117.46 | -7.3% | 2.68x | -4.44 GB | 2.68x | | 2048 | 126.50 | 117.12 | -7.4% | 2.65x | -7.66 GB | 2.67x | | 4096 | 118.07 | 112.88 | -4.4% | 2.75x | -10.15 GB | 2.66x | | 8192 | 116.88 | 111.39 | -4.7% | 2.64x | -10.61 GB | 2.72x | | 16384 | 115.86 | 108.10 | -6.7% | 2.51x | -12.32 GB | 2.71x | The prefill gap is reduced on the mid-length cases that previously showed the largest regression, but it is not eliminated; native remains about 4-7% slower than affine for prefill on this M1 Ultra run. The default switch is based on the overall trade-off requested in lablup#705: native load is about 2.7x faster, decode is 2.5-2.75x faster, and peak memory is 3.3-12.3 GB lower across the sweep. The dense-affine rollback remains available for prefill-sensitive A/B runs. ## Activation-path follow-up Because native prefill still trails affine, this PR also rechecked the lablup#701 path choice on the current Metal/MLX 0.32.1 baseline. At 2048 prompt tokens, the default shape-specific scaled MLP measured 116.10 tok/s, the op-at-a-time sidecar path with compiled GeGLU activation (`MLXCEL_DISABLE_FUSED_GLOBAL_SCALE=1`) measured 116.11 tok/s, and the C++ eager fold (`MLXCEL_COMPILED_QGELU_MLP=0`) measured 113.35 tok/s. At 8192 prompt tokens, the same paths measured 110.66, 109.99, and 108.10 tok/s respectively. This does not support switching native prefill back to the compiled-activation fallback; the lablup#701 eager-fold warning still holds on this Metal baseline. ## Test plan - [x] `cargo test --release -p mlxcel-core quantized_linear_forward_global_scale_matches_manual_sidecar_path -- --nocapture` - [x] `cargo test --release -p mlxcel-core compiled_qgelu_mlp_global_scale -- --nocapture` - [x] `cargo test --release -p mlxcel gemma4::quant_scheme_tests::dense_mlp_scaled_fused_path_eligible -- --nocapture` - [x] `cargo test --release -p mlxcel sanitize::tests::nvfp4_repack_strategy_matrix -- --nocapture` - [x] `cargo test --release -p mlxcel load_and_sanitize_weights_repacks_nvfp4_gemma4_checkpoint -- --nocapture` - [x] `cargo test --release -p mlxcel load_and_sanitize_weights_dense_repack_env_keeps_non_cuda_affine_rollback -- --nocapture` - [x] `cargo build --release --bin mlxcel-bench-decode` - [x] `git diff --check` - [x] `python3 scripts/ci/check_cross_repo_refs.py` - [x] `mlxcel-bench-decode` native-default vs `MLXCEL_NVFP4_DENSE_REPACK=1` sweep at 512, 1024, 2048, 4096, 8192, and 16384 prompt tokens - [x] `mlxcel-bench-decode` native default vs `MLXCEL_DISABLE_FUSED_GLOBAL_SCALE=1` vs `MLXCEL_COMPILED_QGELU_MLP=0` at 2048 and 8192 prompt tokens Closes lablup#705
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
gemma-4-31b-it-nvfp4ModelOpt checkpoint on Mac Studio M1 Ultra.Test plan
cargo build --release --bin mlxcel --bin mlxcel-bench-decodecargo test --release nvfp4_MLXCEL_NVFP4_NATIVE_REPACK=1mlxcel-bench-decoderuns on short and 2048-token promptsmlxcel generateCloses #694