Skip to content

docs: record Metal NVFP4 native benchmark (#694) - #702

Merged
inureyes merged 2 commits into
mainfrom
update/issue-694-nvfp4-metal-benchmark
Jul 9, 2026
Merged

inureyes merged 2 commits into
mainfrom
update/issue-694-nvfp4-metal-benchmark

Conversation

@inureyes

@inureyes inureyes commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Record the issue perf(metal): evaluate native NVFP4 path after direct transcode #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

  • cargo build --release --bin mlxcel --bin mlxcel-bench-decode
  • cargo test --release nvfp4_
  • Affine fallback and MLXCEL_NVFP4_NATIVE_REPACK=1 mlxcel-bench-decode runs on short and 2048-token prompts
  • Affine fallback and native opt-in 40-token greedy continuation spot-check with mlxcel generate

Closes #694

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
@inureyes inureyes added type:performance Performance improvements priority:medium Medium priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers status:review Under review labels Jul 9, 2026
@inureyes

inureyes commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Record the issue #694 Apple Silicon native-NVFP4 A/B benchmark artifacts and keep Metal/non-CUDA on the affine fallback because the 2048-token prefill gate failed.

Findings Addressed

  • Stale GB10 runbook wording still described the Metal/non-CUDA decision as needing an M-series run after the M1 Ultra run had completed (HIGH) — fixed in docs/benchmark_results/nvfp4-direct-transcode-gb10-2026-07-08.md by updating the section to point at the completed decision and preserve it only as a future retest runbook.

Remaining Items

  • None.

Verification

  • PR remains docs/benchmark CSV only: benchmarks/metal_m1ultra_issue694_nvfp4_native_vs_affine_2026-07-09.csv, docs/benchmark_results/nvfp4-direct-transcode-gb10-2026-07-08.md, and docs/benchmark_results/nvfp4-native-metal-m1ultra-2026-07-09.md.
  • Issue perf(metal): evaluate native NVFP4 path after direct transcode #694 benchmark acceptance artifacts are present: short and 2048-token affine/native rows, cold-load wall time, load/run peak memory, prefill/decode throughput, commands, and 40-token greedy spot-check.
  • PR body contains Closes #694, and GitHub reports perf(metal): evaluate native NVFP4 path after direct transcode #694 in closingIssuesReferences.
  • Non-CUDA default intentionally remains unchanged; this PR has no code changes, and the docs record the 2048-token prefill regression from 124.58 tok/s to 115.61 tok/s (-7.2%) instead of the required +20% improvement.
  • Stale runbook claims checked; no remaining "not executed" / "criteria open" / "decision needs M-series" wording found.
  • No broad cargo tests run per review instruction. Ran focused git diff --check on the edited doc; GitHub cross-repo refs check is passing.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Jul 9, 2026
@inureyes
inureyes merged commit 80b4729 into main Jul 9, 2026
4 checks passed
@inureyes
inureyes deleted the update/issue-694-nvfp4-metal-benchmark branch July 9, 2026 00:38
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
@inureyes inureyes self-assigned this Aug 31, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:medium Medium priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(metal): evaluate native NVFP4 path after direct transcode

1 participant