Skip to content

docs: consolidate benchmark evidence by release - #2949

Merged
inureyes merged 2 commits into
mainfrom
update/consolidate-benchmark-results
Nov 10, 2026
Merged

inureyes merged 2 commits into
mainfrom
update/consolidate-benchmark-results

Conversation

@inureyes

@inureyes inureyes commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Reduce tracked benchmark artifacts from 2,015 files (14.4 MB) to 70 files (1.04 MB), consolidating 142 investigations into 12 version archives while retaining final reports and minimal measurement data.
  • Preserve negative decisions, explicit validation gaps, and immutable links to historical evidence; version grouping denotes the first containing release, not necessarily the measured binary version.
  • Repair documentation references, relocate the live hostgate dependency into scripts, and reject raw logs and retired binary archives to prevent renewed accumulation.

Test plan

  • Passed 74 Python benchmark tests after integration with current main; also passed raw-log and CSV-schema checks, binary-asset checks and regression tests, shell syntax checks, cargo fmt, and Clippy locally.
  • Verified preserved data byte-for-byte, JSONL-to-CSV round trips, and new links and archive anchors. No inference behavior changed; real-model benchmarks were not rerun.

Risk

  • Old experiment paths are replaced by release summaries or immutable historical links. Existing untracked benchmark CSVs remain untouched; Git history is not rewritten.

Reduce benchmark_results from 2,015 files to 70 while retaining final reports, measurement rows and essential correctness evidence. Summarize 142 investigations in 12 release archives, preserving negative results and immutable links to full provenance without rewriting history.

Migrate incoming references, move the live host gate into scripts, and keep future captures out of the result tree. Convert final Qwen measurement streams to CSV without changing their values.

Validation: 70 Python benchmark tests, retention/CSV/binary guard suites, formatting, Clippy and link/evidence checks pass. Existing native C++ compiler warnings remain; no inference behavior changed.
@inureyes inureyes added status:review Under review type:docs Documentation improvements or additions priority:low Low priority area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) labels Nov 10, 2026
Preserve the current decode-rate accounting guidance alongside the consolidated benchmark retention policy. Add the bilingual cleanup report for PR #2949.

Validation after integration: 74 benchmark Python tests, raw-log and CSV schema checks, binary asset checks, formatting, and staged whitespace checks passed.
@inureyes

Copy link
Copy Markdown
Member Author

Merge is deferred because the WebUI installed-artifact job failed its host-quiet precheck twice, before performance measurement. Run 42848368741 observed mean runnable tasks of 19.5 and 16.6 against a threshold of 5 after each 600-second wait. The remaining executed checks passed; local integration validation passed 74 benchmark tests and the data, binary, and formatting guards. Retry the failed job when the shared runner is quiet; no gate was bypassed.

@inureyes inureyes added status:blocked Blocked by dependencies or other issues and removed status:review Under review labels Nov 10, 2026
@inureyes
inureyes merged commit 261080b into main Nov 10, 2026
61 of 63 checks passed
@inureyes
inureyes deleted the update/consolidate-benchmark-results branch November 10, 2026 17:31
@inureyes inureyes added status:done Completed and removed status:blocked Blocked by dependencies or other issues labels Nov 10, 2026
inureyes pushed a commit that referenced this pull request Nov 15, 2026
…2970)

## Summary

The cascade-attention docs and doc comments still described the feature as unmeasured and said the default stays off "until a benchmark file exists". The benchmark exists: the M1 Ultra layer-level run of 2026-08-03 found cascade decode slower than the flat launch in all eight measurements (0.356x to 0.784x, contexts 2048/8192, batches 4/8). After #2949 consolidated the benchmark results, it is recorded at `docs/benchmark_results/versions/v0.5.0.md#cascade-attention-m1ultra-2026-08-03`.

This PR updates the prose to "measured and rejected":

- `docs/cascade-attention.md`: the status line now states the measured result and links the archive section; "Measuring it" no longer tells readers to create a file that already exists, and the stale `docs/benchmark_results/cascade-attention-<hw>-<date>.md` path is replaced with the retention rules in `benchmarks.md`.
- `docs/environment-variables.md`: the `MLXCEL_CASCADE_ATTENTION` row no longer says the benefit "has not been measured".
- `src/lib/mlxcel-core/src/paged_v2/cascade.rs`: module doc section "Thresholds are unmeasured" becomes "Measured and rejected: default off"; the `DEFAULT_CASCADE_ENABLED` doc says to flip it only after a recorded run finds a winning configuration.

What is kept as-is on purpose: the thresholds (16 shared pages, 2 members) are still reasoned rather than tuned, and no serving-level run is recorded. Both are stated explicitly instead of being dropped.

## Risk

Documentation and comments only. `DEFAULT_CASCADE_ENABLED` is still `false`; no code path, constant or environment-variable behaviour changes.

## Test plan

- `rustfmt --edition 2024 --check src/lib/mlxcel-core/src/paged_v2/cascade.rs`: clean.
- Checked that the new link targets exist on `upstream/main`: the `cascade-attention-m1ultra-2026-08-03` anchor in `docs/benchmark_results/versions/v0.5.0.md` and the `## Result retention and release consolidation` heading in `docs/benchmarks.md`.
- Grepped `docs/`, `src/lib/mlxcel-core/src/paged_v2/`, `examples/` and `tests/` for the remaining "not measured / unmeasured / until a benchmark exists" cascade wording; the only other hits are unrelated ("unmeasured warmup steps").
- `cargo check` was not run: the change touches doc comments only, and local builds of this checkout are not feasible in my environment (build scripts get killed), so compilation is left to CI.

Closes #1676
inureyes pushed a commit that referenced this pull request Nov 15, 2026
#2962)

## Summary

Re-measures the CUDA fused decode-MoE bound (`FUSED_MOE_MAX_DFF_CUDA = 8192`) on a DGX Spark GB10 at `28d884a5` (MLX pin `9f806b36`) with interleaved fused / gather / null arms, as #2540 asks. The bound stays at 8192; the constant and its unit tests are unchanged. The record also corrects what the earlier sweeps rested on.

## Related issues

Closes #2540

## Type of change

- [ ] `feat` — new user-visible feature
- [ ] `fix` — bug fix
- [x] `perf` — performance improvement (include before/after numbers in the PR body)
- [ ] `refactor` — internal restructuring without behavior change
- [ ] `chore` — build, CI, dependencies, release infrastructure
- [x] `docs` — documentation only
- [ ] `test` — tests only

No runtime behavior changes: this is a measurement, its record, and the comments and docs that cite it.

## Findings

Full record: `docs/benchmark_results/fused-moe-dff-crossover-gb10-2026-11-11.md`. 384 measured runs, one process each, no discarded or failed run.

| Dff | model | fused over gather, as specified (n = 5) | full 100-token window (n = 7) | pinned to fast cores (n = 7) | verdict |
|---|---|---|---|---|---|
| 768 | qwen3-30b-a3b | +28.4% | +34.7% | +31.4% | win |
| 1792 | lfm2-8b-a1b | +2.6% | -0.9% | -2.4% | tie |
| 6400 | phi-3.5-moe | +0.2% | +1.3% | +2.4% | tie |
| 8192 | llama-4-scout-17b | -0.2% | -0.1% | not run | not a fused-path point |
| 14336 | mixtral-8x7b | -2.0% | -2.3% | -1.8% | loss |

1. **8192 is kept.** With the issue's primary harness the ratio crosses 1.0 at an interpolated Dff of 7318 (7148 without llama-4-scout), on the same side of 8192 as #626 (about 8000) and #712 (about 7672). The decision rule says keep.
2. **The 8192 row never measured the fused kernel.** Llama 4 has its own `SwitchGLU` in `src/models/llama4.rs` that calls `gather_qmm` and does not read `MLXCEL_FUSED_MOE` or `MLXCEL_FUSED_MOE_MAX_DFF`. On an empty kernel cache both llama-4-scout arms compiled the same seven modules and no `moe_gateup_kernel` / `moe_down_kernel`; the lfm2 control compiled six such files in the fused arm and none in the gather arm. `llama4.rs` is byte-identical at the commits of the #626 sweep and the #712 re-validation, so "break-even at 8192" there compared a path with itself. The issue adds llama-4-scout to get a point at 8192; that point cannot come from this checkpoint.
3. **The crossover is only bracketed.** The fused-path models give a tie at 6400 and a clear loss at 14336 (null floor 0.2% to 0.3%). The three passes interpolate to 7148, 9239 and 10668, because the 6400 median moves inside its own null floor.
4. **The earlier lfm2 advantage does not reproduce** (+12% in #626, +14.2% in #712, +6.6% on 2026-10-22): a tie in all three `bench-decode` passes and all four `generate` cells. In the `generate` cell that matches the 2026-10-22 record, three of four arms reproduce within 2% and the lfm2 `gather_qmm` arm moved from 102.25 to 109.02 tok/s.
5. **The qwen3-30b size discrepancy is not prompt length or decode length.** `generate` gives +23.5% to +29.9% across a 439-word / short prompt by 256 / 100 token grid, and `bench-decode` gives +28% to +35%. The outlier is the #626 figure (+0.4% on MLX pin `e9463bb`).

## What changed

- New record `docs/benchmark_results/fused-moe-dff-crossover-gb10-2026-11-11.md` and its rows under `docs/benchmark_results/data/fused-moe-dff-crossover-gb10-2026-11-11/runs.csv` (450 rows, warm-ups included and flagged).
- `scripts/bench_fused_moe_dff.py` (driver: rotating arms, quiet-host wait, JIT-notice discard) and `scripts/bench_fused_moe_dff_report.py` (the record's tables), plus the fixed 439-word prompt under `tests/fixtures/bench/`.
- `src/models/switch_layers.rs`: the provenance comment on `FUSED_MOE_MAX_DFF_CUDA` no longer says a re-validation is pending and states what 8192 does and does not rest on.
- `docs/environment-variables.md`: the `MLXCEL_FUSED_MOE_MAX_DFF` row cites the new record.
- `docs/benchmark_results/README.md`, `versions/v0.3.0.md`, `versions/v0.8.0.md`: index entry and "Related evidence / subsequent correction" lines.

Scope note: #2540 lists an addendum to `fused-moe-decode-kernel-design.md` and a corrected bullet in `fused-moe-jit-cache-gb10-2026-10-22.md`. Both files were consolidated into the release archives by #2949, and the last committed version of the 2026-10-22 record already carries the corrected wording, so this PR links the new record from the two archived sections instead.

## Test plan

Run on a DGX Spark GB10 (sm_121, driver 580.178.04, CUDA 13.0), release profile.

- [x] `cargo fmt --all -- --check`
- [ ] `cargo clippy --workspace --all-targets --features metal,accelerate -- -D warnings` (not run; Linux host, and the only Rust change is a doc comment)
- [ ] `cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1` (not run; see the issue's command below)
- [ ] `cargo deny check` (not run; no dependency change)
- [x] Validated with real checkpoints: `mlx-community/Qwen3-30B-A3B-4bit`, `LFM2-8B-A1B-4bit`, `Phi-3.5-MoE-instruct-4bit`, `Llama-4-Scout-17B-16E-Instruct-4bit`, `Mixtral-8x7B-Instruct-v0.1-4bit`, at the revisions listed in the record.
- [ ] If the change moves the numbers: not applicable, no dispatch or kernel change.

The issue's verification commands:

```sh
cargo build --release --features cuda --bin mlxcel-bench-decode --bin mlxcel
cargo test --release --features cuda --lib switch_layers -- --test-threads=1
cargo fmt --all -- --check
```

All three pass on the GB10 host. `switch_layers`: 58 passed, 0 failed, 1 ignored, including `fused_moe_max_dff_default_is_backend_aware_and_env_overrides` and `fused_moe_dff_above_cap_declines_and_at_cap_dispatches`.

Repository gates run locally: env-var docs, benchmark raw logs, benchmark CSV schema, binary assets, cross-repo refs, license headers.

The branch was rebased onto `6289fbe6` before opening. The three commits since `28d884a5` touch only XLA code and another row of the env-var table, and the MLX pin is unchanged. The measurement, `cargo fmt` and the unit tests above ran on the tree at `28d884a5`; the repository gates were re-run after the rebase.

## Notes for reviewers

- **Host and checkpoints differ from the earlier records.** This is `spark-d9e2`, not `spark-101`, and the checkpoints were downloaded from the public `mlx-community` repositories because `/home/inureyes/models` is not available to me. Only ratios are compared with earlier records, never absolute tok/s.
- **`gpu-lock`.** This host has no upstream `gpu-lock`; a user-local `flock(1)` shim with the same CLI shape serialized every run. It is not a CI runner and nothing else used the GPU; the driver's quiet-host wait never triggered.
- **The 439-word prompt is not the original.** The 2026-10-22 record never committed its prompt text, so the secondary harness uses its own fixed 439-word prompt, committed as a fixture. Three of the four comparable cells still reproduce that record within 2%.
- **Unexplained spread.** The null floor is 2.8% to 19% on the three fast models and 0.2% to 0.4% on the two slow ones. Pinning to the ten faster cores did not reduce it. The cause was not found, and it is why 1792 and 6400 are ties rather than small wins or losses.
- **Not measured.** A fused-path model at Dff 8192; which change sped up the lfm2 `gather_qmm` arm since 2026-10-22; Metal, ROCm, gemma4, qwen3_next and batched decode.
- **A possible follow-up, not in this PR.** If a real point between 6400 and 14336 matters, it needs a fused-path checkpoint of that width or a synthetic expert; and Llama 4 could be moved onto the shared `SwitchGLU`, which would make its 8192 row meaningful.

## Checklist

- [x] PR title uses a Conventional Commits prefix (`feat:`, `fix:`, etc.)
- [x] One logical change per PR (split unrelated changes)
- [x] Updated `docs/` if user-facing behavior or supported models changed
- [x] Updated `// Used by: ...` comments on any shared function I modified (see `docs/code-guidelines.md`) (no function modified)
- [x] No secrets, credentials, or `.env` files committed
inureyes pushed a commit that referenced this pull request Nov 15, 2026
…2967)

## Summary

Adds the CUDA port of the fused `gelu_tanh_f32` kernel that #2858 landed for Metal. On CUDA the f32 tanh GELU was a `compile_shapeless` region that MLX's CUDA compile backend splits into a cube module and a tail module (`TanhF32Compiled`, at least two launches per call) or the eager chain (`TanhF32`, about eleven); both are now one `cuda_kernel` launch. The body is written so that NVRTC cannot contract its multiply-add, and it returns the eager chain's bits on every lane measured, so nothing downstream moves and the bit-for-bit fold pin stays as it is.

## Related issues

Closes #2780.

## Type of change

- [x] `perf` — performance improvement (before/after numbers below)

## Design

- **The port** (`src/lib/mlxcelverse/kernels/gelu_tanh_f32.cpp`): a `GELU_TANH_F32_CUDA_SOURCE` body with the formula and op order of `gelu_tanh_approx`, a `GeluTanhF32KernelHolderCuda` (`std::call_once`, as `fused_norm.cpp`), and `.cuda` in `gelu_tanh_f32_ports()`. MLX's CUDA launcher rounds the grid up to whole blocks (`mlx/backend/cuda/custom_kernel.cpp:339-340` at the pin: `dim3 grid((gx + tx - 1) / tx, …)`), so the body returns on lanes at or past `x_shape[0]`, which it reads as a launch argument: the JIT cache key stays the dtype alone, one module and one PTX disk-cache entry per dtype, name `custom_kernel_mlxcel_fused_gelu_tanh_f32…`, far inside the NAME_MAX window from #2423.
- **No contraction.** Every multiply and add in the CUDA body is `__fmul_rn` / `__fadd_rn`, which NVRTC never merges into a fused multiply-add. A plain-operator body compiles `x + 0.044715 * x3` to one FFMA and then differs from the eager chain on about four f32 lanes in a thousand (see "Why the bits match").
- **Routing.** `TanhF32Compiled` takes the kernel wherever `fused_gelu_tanh_f32_available()` is true, as #2858 set up; that is now Metal and CUDA. `TanhF32` takes it where the port returns the eager helper's bits: a new predicate `fused_gelu_tanh_f32_matches_eager_bits()` reads a second `KernelPorts` table that lists the CUDA port only, so the question goes through `has_kernel_port` like every other port question and no backend is compared by hand (`make verify-kernel-port-dispatch` passes). On Metal, ROCm and the CPU device `TanhF32` is the eager helper, unchanged; #2858's decision for Metal stands, because the Metal body may contract.
- Checker pins: `scripts/ci/check_kernel_dtype_keys.py` `EXPECTED_IN_SCOPE` gains the file (it now launches a `cuda_kernel`), and its self-test's pinned launcher count goes 9 → 10.

## Acceptance criteria (issue #2780)

| # | Criterion | Status |
|---|---|---|
| 1 | `TanhF32` and `TanhF32Compiled` run as one kernel launch on CUDA, f32 inside, input dtype out; Metal/CPU unchanged | Met. Fresh PTX cache: each variant leaves one `custom_kernel_mlxcel_fused_gelu_tanh_f32_<dtype>` module with one kernel per dtype; before, `TanhF32Compiled` left a cube module plus a tail module per dtype and `TanhF32` left nothing (eager AOT chain). Metal and CPU-device dispatch untouched. |
| 2 | Erf path inspected and recorded; follow-up issue if it is more than one kernel | Inspected and recorded (record, "Erf arm considered"): `gelu_approx` is an eager six-op chain, about six launches per call. The follow-up issue this criterion asks for is drafted at the end of this description and is **not filed yet**. |
| 3 | Gemma 3 and Gemma 4 image prefill within the null floor of erf, GB10 not a CI runner, arms rotated, a null arm per arm, host gate before every arm | Met on both: the paired tanh - erf range overlaps every null range, with tanh at or below erf (Gemma 3 -20.4 ms, Gemma 4 -10.9 ms; null floor about 27 ms and 23 ms). Schedule of `engine_bench_rounds.py --null-every-arm --hostgate`, 8 rounds, a null arm for each arm. Recorded as a standalone file rather than a new section of `gelu-erf-vs-tanh-2026-10-23.md`, which #2949 retired into `versions/v0.8.0.md`. |
| 4 | `:87` becomes a tolerance test; `:197` stays bit-exact; new test on the sweep, the tower input and an empty input | Met in the stricter direction: `:87` did not need to relax. It is unchanged and passes through the kernel on CUDA. New: bit-identity test (sweep, block-boundary sizes, tower input, f32/bf16/f16), sweep tolerance test for ports that make no bit claim, CPU-device dispatch test. Empty input was already covered by `empty_input_takes_the_same_route_on_both_paths`, which now runs on CUDA. |
| 5 | `tests/cuda_custom_kernel_disk_cache.rs` runs the kernel in a second process with zero NVRTC compiles | Met. |
| 6 | StableHLO twins re-checked; greedy 32-token image replies unchanged on the five checkpoints | Greedy replies (32 tokens, pinned main vs this change): identical on all five (`gemma-3-4b-it-4bit`, `gemma-4-e2b-it-4bit`, `MiniCPM-V-4.6-bf16`, `paligemma2-3b-ft-docci-448-6bit`, `InternVL3-1B-4bit`) and on `Qwen3-VL-2B-Instruct-4bit`, a family on the plain `TanhF32` route. Twins: Molmo2, Gemma 3 SigLIP and Qwen3-VL were run against IREE on real checkpoints, on this change and on a clean `ce6855bc8`, and every per-stage number is identical between the two ("StableHLO twins" below). Molmo2 passes; the Gemma 3 gate fails and Qwen3-VL passes its gate with free-running drift outside tolerance, both exactly as on clean `main`. The twins of the other tanh-switched families were not run. |

## Why the bits match

A probe evaluated the eager helper, the compiled chain and the fused kernel on the same array and compared f32 bit patterns per lane: the tests' sweep, 14 element counts from 1 to 65537 on both sides of every block boundary, two 2-D shapes, the tower-shaped `[64, 4304]` input and a dense `[1024, 1024]` one, 1527340 lanes per dtype. No lane differs in f32, bf16 or f16, between any two of the three paths, and eleven special values (±0, subnormal, ±inf, NaN, …) agree as well.

The first draft of the port used plain operators, like the Metal string. `cuobjdump -sass` on its cached f32 module shows `FFMA R7, R7, 0.044715, R4`, and the same probe found 1171 of 275456 tower lanes and 2062 of 1048576 dense lanes one rounding step of tanh away from the eager chain (at most 2^-22 absolute; none on the 809-point sweep; none on bf16/f16). The compiled chain agreed with the eager chain bit for bit, because its multiply and add are in different modules. With `__fmul_rn` / `__fadd_rn` the same lines are `FMUL`, `FADD`, and every lane agrees.

The limit of the claim: the multiplies and adds agree by construction; `tanhf` agrees with the eager chain's `tanh` kernel on every lane measured, which is what one expects when the AOT kernels and NVRTC come from the same CUDA release (13.0 here) and is not guaranteed across releases. `fused_kernel_returns_the_eager_helper_bits_where_it_claims_to` is the test that would report it.

## Before / after

GB10 (sm_121, driver 580.178.04, CUDA 13.0, MLX 9f806b36), measured on `28d884a5` plus this patch, before the rebase. Full record: `docs/benchmark_results/fused-gelu-tanh-f32-cuda-gb10-2026-11-11.md`.

**Launches per call** (fresh PTX cache): `TanhF32Compiled` 2 or more (cube module + tail module) -> 1; `TanhF32` about 11 (eager, no JIT module) -> 1.

**Op level** (`examples/fused_gelu_tanh_microbench.rs`, bf16, four runs, µs per call as median (min..max)):

| Shape | eager | compiled | fused | fused / compiled | fused / eager |
|---|---|---|---|---|---|
| tower prefill `[64, 4304]` | 187.0 (118.1..216.9) | 84.1 (72.0..99.0) | 16.6 (14.8..17.8) | 0.19x (0.17..0.22) | 0.09x (0.08..0.14) |
| decode row `[1, 4304]` | 109.2 (94.0..114.2) | 30.6 (27.2..31.1) | 12.5 (10.8..13.2) | 0.41x (0.36..0.48) | 0.12x (0.11..0.12) |
| large prefill `[1024, 4096]` | 1571.2 (1557.7..1590.5) | 698.8 (657.6..707.3) | 184.4 (168.0..208.4) | 0.27x (0.24..0.29) | 0.12x (0.11..0.13) |

**Image prefill** (`generate --image … -n 8 --temp 0 --profile`, 8 rounds, every arm with its own null arm, order rotated each round, host gate before every run; ms, median (min..max); deltas paired per round):

| Family | erf | tanh (this PR) | compiled (main) | tanh - erf | tanh - compiled | Null arms: erf / tanh / compiled |
|---|---|---|---|---|---|---|
| Gemma 3 4B SigLIP (272 tokens) | 831.4 (824.8..847.4) | 810.9 (786.1..824.8) | 853.2 (838.6..868.8) | **-20.4 ms, -2.5 %** (-55.3..-4.9), negative in 8 of 8 | **-45.7 ms, -5.3 %** (-78.0..-17.4), negative in 8 of 8 | +0.3 (-23.0..+26.5) / -14.6 (-23.5..+27.2) / -2.7 (-26.1..+23.5) |
| Gemma 4 E2B vision GeGLU (278 tokens) | 608.5 (596.4..620.2) | 597.3 (586.7..610.1) | 615.4 (606.7..629.4) | **-10.9 ms, -1.8 %** (-24.7..+2.4), negative in 6 of 8 | **-20.4 ms, -3.3 %** (-41.8..-4.0), negative in 8 of 8 | -3.6 (-8.6..+13.3) / -0.4 (-11.3..+22.8) / +0.7 (-14.3..+11.6) |

The tanh arm is inside the null floor of erf on both families and below the compiled chain in all 16 paired rounds. compiled - erf, the residual the 2026-10-23 record left open, reads +1.8 % and +0.7 % here.

**The plain `TanhF32` route** (Qwen3-VL 2B vision blocks; pinned main = eager chain, this PR = the kernel; same schedule):

| Input (prompt tokens) | eager (main) | kernel (this PR) | kernel - eager | Null arms: eager / kernel |
|---|---|---|---|---|
| 448x448 fixture (210) | 320.0 (314.6..324.8) | 315.9 (310.9..320.9) | -1.8 ms, -0.6 % (-13.9..+4.0): unresolved | -4.0 (-12.7..+2.9) / -4.3 (-14.1..+2.6) |
| 1240x1754 page fixture (2159) | 699.2 (694.2..705.1) | 623.0 (616.9..632.7) | **-76.8 ms, -11.0 %** (-84.6..-61.9), negative in 8 of 8, outside both null ranges | +10.9 (-8.6..+19.5) / -0.1 (-18.4..+9.4) |

Two things about the host that the record spells out: its GPU clock is held to 300-2100 MHz by the operator's clock manager, and it serves an embedding model through ollama that wakes on other clients' requests and burns five to six cores for a minute or two. The second is outside the host gate's lists, so the driver waits for it to be idle and discards and reruns any run it overlapped (one attempt, on Gemma 4).

## Test plan

Run on this PR's code (`cbbd74fdc`, one commit on `ce6855bc8`; the second commit only edits the benchmark record) on a DGX Spark (GB10, sm_121, CUDA 13.0), unless a line says otherwise.

- [x] `cargo fmt --all -- --check`
- [x] `cargo clippy --workspace --all-targets --features cuda -- -D warnings` (the Linux spelling of the template's line). Passes with no Rust warning; the build script relays C++ compiler notes from MLX headers and from files this PR does not edit
- [x] `cargo build --release --features cuda`
- [x] `make verify-test-cuda` (`cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1`), the gate CONTRIBUTING.md names for this backend: 186 of 187 test binaries pass (15489 tests passed, 1 failed, 496 ignored). The one failure, `native_env_tests::the_cuda_cache_defaults_reach_mlx` (`MLX_CUDA_GRAPH_CACHE_SIZE` reads 400, expected 2000), is the same single failure on a clean `28d884a5` (`-p mlxcel-core --lib`: 2257 passed, 1 failed) and does not involve this change; see the notes
- [x] The issue's verification commands: `cargo test -p mlxcel-core --features cuda --release gelu_tests -- --test-threads=1`, 17 passed (the issue's `utils_gelu` filter matches no test on current `main`; the module is `utils::gelu_tests`); `cargo test --features cuda --release --test cuda_custom_kernel_disk_cache -- --test-threads=1`, 1 passed; `cargo test --features cuda --release --test cpu_device_custom_kernel_gates -- --test-threads=1`, 1 passed
- [x] `make verify-kernel-dtype-keys`, `make verify-kernel-port-dispatch` (with their self-tests), `make verify-env-var-docs`, `make verify-benchmark-raw-logs`, `make verify-python-tooling` (219 tests)
- [x] The self-hosted `ci.yml` jobs that a pull request opened from a fork does not get, run by hand: `clippy` (`cargo clippy -p mlxcel --lib --tests -- -D warnings`, default features); `cpu-link` (`cargo test -p mlxcel-core --profile test-fast --lib --no-run`, then `-- ptx_cache_dirs empty_mlxcel_cache_dir native_env`, 13 passed; on that no-accelerator build `gelu_tests` passes 16 of 16, the seventeenth being `#[cfg(feature = "cuda")]`); `cuda-blockfloat` (its build, its `cuobjdump` step, and `global_scale`, 7 passed); `xla-compile` (`cargo check --features cuda,xla-iree --all-targets` and `cargo check --no-default-features --features xla-diagnostics --all-targets`). `rocm-build` needs a ROCm host and was not run
- [x] StableHLO twins against real checkpoints, on this change and on a clean `ce6855bc8`: see "StableHLO twins" below
- [x] Validated with real checkpoints (all `mlx-community/`, revisions in the record): `gemma-3-4b-it-4bit`, `gemma-4-e2b-it-4bit`, `MiniCPM-V-4.6-bf16`, `paligemma2-3b-ft-docci-448-6bit`, `InternVL3-1B-4bit`, `Qwen3-VL-2B-Instruct-4bit`: greedy 32-token image replies identical between pinned main and this change on all six, and identical again from a release build of this PR's code
- [x] Traced per "Judging a change that moves the numbers": on CUDA this change does not move them. No lane of 1527340 per dtype differs from the eager chain or from the compiled chain it replaces, and the greedy replies above are identical
- [ ] `cargo deny check`: not run and not applicable: `ci.yml` runs its `deny` job only when `**/Cargo.toml`, `Cargo.lock` or `deny.toml` change, and none does here
- [ ] Metal: not built or run here. The Metal port and its routing are untouched; two of the new tests are backend-neutral and first run on Metal in the nightly `make verify` after merge

## StableHLO twins

The IREE toolchain comes from `scripts/iree/setup-cuda.sh` (IREE 3.12.0rc20260721). Each twin compares eager MLX on CUDA with the IREE lowering on `local-task`, built under `--profile test-fast --features xla-diagnostics,xla-reference-diagnostics`, once on this change and once on a clean `ce6855bc8`.

| Twin (tanh-GELU route) | Command, checkpoint | This change | Clean `ce6855bc8` |
|---|---|---|---|
| Molmo2 vision (`TanhF32`) | `cargo test --test molmo2_xla_vision_parity -- --include-ignored`, `Molmo2-8B-4bit` | passes (8 tests, the real-checkpoint gate among them): vision projection max abs 0.3047 at a magnitude of 8.06e4, rms 0.00167, no element over the limit | passes, all 25 stage lines identical |
| Gemma 3 SigLIP (`TanhF32Compiled`) | `cargo run --example xla_gemma3_reference_check`, `gemma-3-4b-it-4bit` | **fails**: first divergence at `siglip.hidden.block4.output`, max abs 0.1067 against `atol` 0.08 on 5 of 4718592 elements; `siglip.block0.mlp_activation` itself passes at max abs 4.8e-4 | fails the same way, all 34 stage lines identical |
| Qwen3-VL DeepStack (`TanhF32`) | `cargo run --example xla_qwen3_vl_deepstack_check`, `Qwen3-VL-2B-Instruct-4bit` | passes its gate (same-input operator controls clean, greedy top-1 exact, both negative controls detected); 42 of its 67 free-running stage comparisons are outside tolerance | passes, all 67 comparisons identical |

Every per-stage number is the same with and without this change, which is what an MLX side that is unchanged in bits predicts. The Gemma 3 gate's failure and the Qwen3-VL free-running drift are how `main` behaves on this host with these 4-bit checkpoints; I did not look into either further.

## Notes for reviewers

- **`TanhF32` is routed on CUDA only, and its pin is untouched.** #2858 left `TanhF32` eager on Metal because the kernel would break the bit-for-bit fold pin. The issue expected the pin to relax here for the same reason ("Fusion changes rounding (FMA contraction)"). It does not have to: with the contraction written out of the body the kernel is the eager chain's bits, so BERT (`src/models/bert.rs:292`), Qwen3-VL (`src/vision/encoders/qwen3_vl.rs:772`) and Molmo2 (`src/vision/encoders/molmo2.rs:94`) get one launch instead of about eleven and the pin still passes as written. What it buys depends on how many patches the tower sees: nothing resolvable on Qwen3-VL at 448x448, 11 % of the prefill on a page-sized image. If you would rather keep `TanhF32` eager on CUDA as well, it is the one arm in `GeluActivation::apply` and the second port table.
- **compute-sanitizer says nothing about the grid guard.** `memcheck` reports 0 errors on the probe and on the GELU test module, and also on a build with the guard removed, whose outputs are unchanged: MLX's allocator rounds a buffer to a power of two or to 16384-byte pages (`mlx/backend/cuda/allocator.cpp:176-182`), so lanes past `n` land in the buffer's own slack. The guard rests on the launcher code, not on the sanitizer.
- **The gate's one failure is on `main` already.** `native_env_tests::the_cuda_cache_defaults_reach_mlx` passes alone and fails once any test has touched the CUDA device earlier in the process, because `mlx::core::config::get` memoizes the first value it reads (`mlx/config.cpp`) and MLX's device has by then read `MLX_CUDA_GRAPH_CACHE_SIZE` with its own default of 400. One unrelated GPU test in front of it is enough, on a clean `28d884a5` as well. Not filed as an issue yet.
- **Not measured:** the StableHLO twins of the other tanh-switched families; Metal; ROCm; image-prefill timing for MiniCPM-V 4.6, PaliGemma, Molmo2 and BERT; a host whose NVRTC and build toolkit are different CUDA releases.
- The microbenchmark's two small shapes are launch-bound and move from run to run (the record has the four runs); read those rows as ranges. The large-shape row is stable.

## Checklist

- [x] PR title uses a Conventional Commits prefix
- [x] One logical change per PR
- [x] Updated `docs/` (`docs/benchmarks.md`, the benchmark index, the record)
- [x] Updated `// Used by: ...` comments on the shared functions I modified
- [x] No secrets, credentials, or `.env` files committed

<details>
<summary>Follow-up issue for the erf path (acceptance criterion 2): drafted, not filed yet</summary>

Title: `perf(cuda): the erf GELU (gelu_approx) runs as an eager six-kernel chain on the vision towers`

Found while closing #2780 (acceptance criterion 2). `GeluActivation::Erf` reaches `gelu_approx` in `src/lib/mlxcel-core/cpp/mlx_cxx_bridge.cpp`, which is an eager chain: `erf(divide(x, sqrt2))`, `add(one, …)`, `multiply(half, …)`, `multiply(x, …)`, `astype(…, x.dtype())`; the f32 scalar constants promote a bf16 input to f32 along the way. Each op is one AOT kernel, so the erf GELU is about six launches per call on CUDA (the same eager code runs on Metal). The `compile_shapeless` form `compiled_gelu_approx` exists but has no production caller.

Evidence: on GB10 (`28d884a5` plus the #2780 port), the Gemma 3 erf arm (`vision_config.hidden_act = "gelu"`) run against an empty `MLX_PTX_CACHE_DIR` leaves exactly the tanh arm's compiled modules minus the fused tanh kernel, i.e. nothing for the erf GELU, which is what an eager chain looks like in the JIT cache. In the same record's image-prefill rounds the erf arm sits above the single-kernel tanh arm on both families (Gemma 3 831.4 against 810.9 ms, paired -20.4 ms and negative in 8 of 8 rounds; Gemma 4 608.5 against 597.3 ms), inside the null floor in size but consistent in sign, which is what a six-launch chain against one launch would look like. Full record: `docs/benchmark_results/fused-gelu-tanh-f32-cuda-gb10-2026-11-11.md`.

Proposed: decide between (a) routing `Erf` to `compiled_gelu_approx` and checking whether MLX's CUDA compile backend splits that region as it did the tanh one, and (b) an erf port of the `gelu_tanh_f32` custom kernel (same launcher shape, `erff` in f32, store through `T`, and `__fmul_rn` / `__fadd_rn` / `__fdiv_rn` so it returns the eager chain's bits, as the tanh port does). Either way, measure with the erf-vs-tanh protocol (image prefill, a null arm per arm) before switching, because the families on `Erf` (InternViT, the Phi-4 SigLIP, …) are the ones that kept erf on purpose in #2423.

Out of scope for #2780, which only ports the tanh kernel.

</details>
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) priority:low Low priority status:done Completed type:docs Documentation improvements or additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant