Skip to content

perf(bench): ROCm support in the benchmark harness and a gfx1151 baseline - #2056

Merged
inureyes merged 7 commits into
mainfrom
feature/issue-1810-rocm-bench-harness
Sep 29, 2026
Merged

inureyes merged 7 commits into
mainfrom
feature/issue-1810-rocm-bench-harness

Conversation

@inureyes

@inureyes inureyes commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Closes #1810

On an AMD host scripts/bench_decode.sh wrote ROCm results as metal_<cpu name>, budgeted memory against the host's 31 GiB instead of the GPU's 96 GiB carve-out, and scripts/compare_bench_csv.py only knew the m5max and m1ultra hosts, so its superseded-baseline warning was off for every other host.

Harness

  • bench_decode.sh: on Linux when nvidia-smi finds no GPU, a one-token mlxcel generate probe on the smallest checkpoint in MODELS_DIR (the named model only when the store has none, about 4 s) reads the [mlxcel] custom kernel backend:, HIP architecture gfx... and GPU: ... (Amd), N GiB device memory. lines; rocminfo (under the run timeout) and sysfs are the fallback when the probe run fails, and a missing ROCm version file or hipconfig yields an empty field rather than ending the script. ROCm runs are written as benchmarks/rocm_strixhalo-gfx1151_<date>.csv (amd-<gfx> for other targets), the hardware string carries the gfx target, ROCm release and device memory, and the 85% memory guard uses device memory. ROCm rows gain two trailing columns, mlx_rocm_overlay_commit (from patches-rocm/UPSTREAM) and hip_version; mlx_commit stays the upstream pin. Detection now runs after argument parsing because the probe needs a model. On macOS and on hosts where nvidia-smi works, no probe runs and the output is unchanged.
  • bench_mlxlm.py: tags a ROCm host with the same names (and, like bench_decode.sh, defers to nvidia-smi), budgets against device memory, and appends the MLX source-build version to baseline_version on ROCm only.
  • compare_bench_csv.py: runtime and host come from the <runtime>_<host>_ filename for any host and runtime.
  • tests/test_bench_rocm_detection.py: probe_runtime against a stub mlxcel (probe model choice, parsed fields, non-ROCm backend, rocminfo fallback), probe parsers, rocminfo parsing, missing version tools, hardware tags (new and existing), backend and memory selection, the Python harness producing the same tag, and the compare scan on a ROCm host. Checked that the tag and compare tests fail on the pre-change scripts.

Baseline

docs/benchmark_results/rocm-baseline-gfx1151-2026-09-30.md with both CSVs: five checkpoints, pp512/tg128, mlxcel against mlx-lm on the same host and day. Decode ratio 1.27x (Qwen3-0.6B), 1.08x (Llama-3.1-8B), 1.05x (Qwen3-30B-A3B), 1.00x (gpt-oss-20b); Mixtral decode varies from about 8 to 11 tok/s run to run in both runtimes, so no ratio is claimed for it. Both sweeps ran under a guard that waited for no other GPU process and no compiler on the host and rejected any sweep a 1 s monitor saw overlapped; five were rejected and rerun (another unit was testing on the same GPU). The mlx-lm side is a source build of the spike tree (same fork commit on the same MLX pin), not byte-identical to mlxcel's overlay; the page lists the differences.

Verification

On the gfx1151 host (ROCm 10.0.0, HIP 7.15.26333), release binaries built with --features rocm from 784e35b7:

  • python3 -m unittest tests/test_bench_rocm_detection.py tests/test_bench_decode_oom_classifier.py: 35 tests pass.
  • make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-fmt: pass. python3 scripts/insert_apache_header.py --check: pass.
  • cargo test --release --features rocm --test dead_doc_pointers: 2 passed.
  • End to end: MODELS_DIR=models/mlx ./scripts/bench_decode.sh all --cooldown 30 --big-cooldown 30 detected rocm, strixhalo-gfx1151, ROCm 10.0.0 / HIP 7.15.26333 and a 96 GiB device budget, and measured all five models with none skipped; bench_mlxlm.py all wrote the matching pylm_strixhalo-gfx1151 file; compare_bench_csv.py --reference paired all five.

After the review fixes, a single-model run on gfx1151 still reported rocm, strixhalo-gfx1151 and the 96 GiB budget, and a run whose probe checkpoint could not load took device memory from sysfs. Those runs shared the GPU and their numbers are not published.

Not verified: Metal and CUDA (not available on this host). The changes on those paths are the relocation of backend and hardware detection after argument parsing and the ${COMMIT_FIELDS} row substitution in bench_decode.sh; the unit tests pin the existing Apple, GB10 and V100 tags and the host-memory path, but no Metal or CUDA sweep was run. compare_bench_csv.py's superseded-baseline scan now also runs for cuda_* files, which it previously skipped.

@inureyes inureyes added type:performance Performance improvements priority:medium Medium priority area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) platform:linux Linux (CUDA / packaging) specific status:review Under review status:done Completed and removed status:review Under review labels Sep 29, 2026
On an AMD host bench_decode.sh wrote ROCm results as metal_<cpu name>, budgeted memory against the host's 31 GiB instead of the 96 GiB carve-out, and compare_bench_csv.py knew only the m5max and m1ultra hosts, so its superseded-baseline warning was off everywhere else.

- bench_decode.sh: on Linux without a working nvidia-smi, a one-token generate probe reads the kernel backend, gfx target, device name and device memory from the lines generate already prints (rocminfo and sysfs as fallback). ROCm runs are written as rocm_strixhalo-gfx1151_<date>.csv (amd-<gfx> elsewhere), the memory guard uses device memory, and ROCm rows gain mlx_rocm_overlay_commit and hip_version. Metal and CUDA output is unchanged.
- bench_mlxlm.py: tags a ROCm host the same way and budgets against its device memory.
- compare_bench_csv.py: runtime and host come from the <runtime>_<host>_ filename for any host.

tests/test_bench_rocm_detection.py covers the parsers, tags, budget and the compare scan without a GPU.

Refs #1810
Describe how bench_decode.sh identifies a ROCm host, the rocm_<hw> file name, the device-memory budget, the Python baseline setup, and the two ROCm-only CSV columns.

Refs #1810
First ROCm throughput baseline, pp512/tg128 on the Radeon 8060S host for five checkpoints, mlxcel and mlx-lm on the same day and host, written by the harness changes in this branch.

Both sweeps ran under a guard that waited for the GPU and host to be free of other GPU jobs and compilers and rejected any sweep a sampled foreign process overlapped; five were rejected and rerun. The page records the host, ROCm 10.0.0 / HIP 7.15.26333, the commits, the difference between mlxcel's overlay and the mlx-lm source build, and that Mixtral decode does not repeat run to run in either runtime.

Refs #1810
The version and sysfs helpers run inside command substitutions under set -euo pipefail, so a host without the ROCm version file, a failing hipconfig or rocminfo, or a zero VRAM figure ended bench_decode.sh with no message. They now return an empty field instead; a test covers the missing-tool case and fails on the previous helpers.

bench_mlxlm.py runs rocminfo once and, like bench_decode.sh, falls back to host memory in the hardware tag when the device reports none, so both harnesses still tag such a host identically. The benchmarks.md mlx-lm recipe now uses --big-cooldown 60, since that script replaces the cooldown after a big model where bench_decode.sh adds to it.

Refs #1810
The runtime probe runs before the SKIP:oom_estimate guard, so probing with the model named on the command line could load a checkpoint the guard would refuse, and load a large one twice. It now uses the smallest checkpoint in MODELS_DIR and falls back to the named model only when the store has none. The smallest-checkpoint scan also moved inside the probe, so macOS and NVIDIA hosts no longer pay for it.

rocminfo now runs under the same timeout wrapper as the model runs, since it can block on a wedged KFD driver. The ROCm device name and version fields have commas and quotes stripped before they reach unquoted CSV fields, and bench_mlxlm.py skips ROCm detection when nvidia-smi works, as bench_decode.sh does.

Checked on gfx1151: a single-model run still reports rocm, strixhalo-gfx1151 and the 96 GiB device budget, and a run whose probe checkpoint is unloadable takes device memory from sysfs.

Refs #1810
The ROCm probe orchestration in scripts/bench_decode.sh had tests only for its parsers and helpers. Add tests that run probe_runtime against a stub mlxcel and fake checkpoints: the probe loads the smallest checkpoint and reads gfx target, device name and device memory, a non-ROCm backend leaves ROCm undetected, and a failed probe falls back to rocminfo.

Validation:
- python3 -m unittest tests/test_bench_rocm_detection.py tests/test_bench_decode_oom_classifier.py: 35 tests OK

Refs #1810
@inureyes
inureyes force-pushed the feature/issue-1810-rocm-bench-harness branch from a23c575 to d909b97 Compare September 29, 2026 20:35
@inureyes
inureyes merged commit dfc5986 into main Sep 29, 2026
24 of 25 checks passed
@inureyes
inureyes deleted the feature/issue-1810-rocm-bench-harness branch September 29, 2026 20:51
inureyes added a commit that referenced this pull request Sep 29, 2026
…te (#2057)

Closes #1808

## Audit result

The issue's title is stale: nothing it describes still fails on current main (dfc5986). Reproduced on gfx1151 under `timeout`:

- mxfp4 `quantized_matmul` at 256x512, M = 1: no hang. It finishes and matches `x @ dequantize(w).T` in f32 on the CPU (relative error 1.8e-7 for f32, 2.8e-3 for bf16).
- GPU mxfp4 `quantize` at 4096x4096: no "invalid configuration argument". It launches in about 80 ms and matches the CPU quantizer bit for bit.
- mxfp4 `gather_qmm`: matches a per-expert dequantized reference, sorted and unsorted (1.6e-6 f32, 2.6e-3 bf16).

The fixes are PR #1818's overlay items 8, 10 and 11 in `patches-rocm/LOCAL_FIXES.md`. Native mxfp4 is correct, so the capability table's `Native` entry for ROCm stays and the affine 4-bit fallback (plan step 4) is not needed. No overlay change here.

## Changes

- `tests/rocm_mxfp4_quant.rs`: the committed version of those checks. It also pins the table entry. Each numeric test fails with its fix reverted: item 8 gives NaN, item 10 a GPU memory fault (reported as an error since #1804), item 11 the original launch error.
- Load log: quantized layer loaders now go through `validate_quantization_mode_for_running_backend`. On a backend that also converts or refuses modes (ROCm), the first layer of each natively run block-float mode prints `Quantization mode mxfp4: running on native ROCm kernels, no load-time conversion ...`. This is the native counterpart of the NVFP4 repack line. On Metal, CUDA and CPU every mode is native, so no line prints and their output does not change.
- `docs/installation.md`: states the log line and the test. The stale 3.6 tok/s gpt-oss figure now reads 8.07 tok/s, as measured in the #2056 baseline.

The four mxfp4 `ffi_tests::compiled_qgelu_mlp_global_scale_*` cases, two of which the old NVFP4 abort hid, all pass on ROCm now.

## Verification (gfx1151)

- `cargo test --profile test-fast --features rocm --test rocm_mxfp4_quant -- --test-threads=1`: 4 passed, 26 s.
- `mlxcel generate -m models/mlx/gpt-oss-20b-MXFP4-Q4 --temp 0`: coherent answer ("The capital of France is Paris.") and the native-route line appears once. Qwen3-0.6B-4bit (affine) prints no line.
- mlxcel-core `ffi_tests::compiled_qgelu_mlp_global_scale` (5 passed). `layers::tests`: the new test passes, and the only failure is the known bf16 `prefill_dense_gemm_matches_qmm_bytes_where_eligible` baseline. Root lib `models::{switch_layers,gpt_oss,kimi_linear}`: 40 passed. `dead_doc_pointers` passed.
- clippy `-D warnings` on mlxcel-core (lib, tests) and mlxcel (lib, new test), plus `make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-fmt`: all clean.

Not verified: Metal and CUDA (not available on this host). The loader call sites this touches are shared with them, but there `native_quantization_route_line` returns `None` (covered by a unit test for every backend), so their behavior is unchanged by construction.
inureyes added a commit that referenced this pull request Sep 30, 2026
ROCm had end-to-end tok/s only, so the #1814 kernel ports had no measured order. This adds what a per-kernel decode profile needs, as reusable tooling rather than a one-off:

- scripts/rocm_gpu_guard.sh: the idle-GPU guard the #2056 baseline described, as a script (90 s with /sys/class/kfd/kfd/proc empty and no compiler, a 1 Hz monitor that ignores the command's own GPU processes, rerun on contention, every sample logged).
- mlxcel-bench-decode: --temperature and --top-p (default greedy, unchanged), and MLXCEL_BENCH_PHASE_MARKS=1, which prints the warmup, measured, decode-start and end times on CLOCK_MONOTONIC and CLOCK_BOOTTIME so a trace can be cut to the measured decode by timestamp.
- scripts/rocm_decode_profile.sh runs a plain and a rocprofv3 --kernel-trace --hip-graph-trace --stats run per model under the guard; scripts/rocm_decode_profile.py cuts the decode window, reports GPU time and host gap per token, profiler cost, top kernels, and attributes dispatches to mlxcel ops and #1814 port units by dispatch order, with which ports mlxcel actually reaches per model.
- tests/test_rocm_decode_profile.py covers the guard against a fake KFD directory and the cut and attribution rules on synthetic steps; docs/benchmarks.md documents the harness.

Refs #2061
inureyes added a commit that referenced this pull request Sep 30, 2026
#2086)

Measures where ROCm decode time goes per kernel on gfx1151 and ranks the port issues split from #1814 by it; settles MLX's ROCm `gather_mm`.

## What changed

- `docs/benchmark_results/rocm-decode-profile-gfx1151-2026-09-30.md`: decode GPU time and host gap per token, top kernels, share per port unit for Llama-3.1-8B, Qwen3-30B-A3B, granite-4.0-h-tiny and Nemotron-3-Nano (greedy, plus temperature and top-p runs), the attribution method, and the ranked order. Raw rocprofv3 stats CSVs, per-kernel decode tables, summaries and the guard log are under `benchmarks/rocm_profiles/gfx1151_929c80ab/`.
- Harness: `scripts/rocm_gpu_guard.sh` (the #2056 idle-GPU guard as a script), `scripts/rocm_decode_profile.sh` / `.py` (profile, decode cut, attribution, report), `mlxcel-bench-decode --temperature/--top-p` and `MLXCEL_BENCH_PHASE_MARKS=1`; documented in `docs/benchmarks.md`.
- `grouped_gemm_numeric_tests.rs` gates read `gpu_backend_available()`; the file left `BACKEND_ENUMERATION_TODO`.

Result: implied order #2067, #2065, #2064, #2068, #2063 (items 7, 5, 4, 8, 3). Every measured run passed the guard (90 s idle, 1 Hz monitor); one attempt was rejected by the guard, one rerun by hand. Profiler cost scales with dispatch count: within noise on Llama, 5% on Qwen3, 20 to 23% on the hybrids, so the doc reports shares.

## Verification (gfx1151)

- [x] `cargo test --release --features rocm -p mlxcel-core --lib grouped_gemm_numeric_tests -- --test-threads=1 --nocapture`: 3 passed; each also run by exact name under rocprofv3, trace shows `gather_batched_gemm_kernel` and a hipBLASLt GEMM; all three fail with a wrong-expert reference
- [x] `python3 scripts/ci/check_kernel_port_dispatch.py`: `0 awaiting a predicate`; `make verify-kernel-port-dispatch` passes
- [x] `make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-fmt`: pass
- [x] `cargo clippy -p mlxcel --features rocm --bin mlxcel-bench-decode -- -D warnings` and `cargo clippy -p mlxcel-core --features rocm --lib --tests -- -D warnings`: clean (narrow scope instead of `make verify-clippy-rocm`, which is workspace-wide)
- [x] `cargo test --features rocm --test dead_doc_pointers`: pass
- [x] `python3 -m unittest tests/test_rocm_decode_profile.py`: 17 passed; `bash -n` on all three scripts (shellcheck is not installed on this host)

## Changes during review

- The report now states that per-token figures divide by the 128 generated tokens while the decode window holds 127 forward passes (the first token comes from prefill), gives exact per-step SSD dispatch counts (47 granite, 50 Nemotron), and widens the #2063 opt-in ceiling to 0.83 to 0.89%.
- Script hardening from the security review: `rocm_decode_profile.sh` scrubs local paths from `guard.log` in an EXIT trap with a literal replacement; `rocm_gpu_guard.sh` parses the parent PID after the last `)`, avoids glob expansion, validates its integer options, and stops the command and monitor on INT/TERM; `Dispatch` in `rocm_decode_profile.py` is slotted. `rocm_decode_profile.py report` output on the committed data is byte-identical before and after.

Not verified: Metal and CUDA (not available here). The `gather_mm` gate change means the three tests still run there, unchanged. `cargo test --test dead_doc_pointers` without `--features rocm` fails to link on this host (`copy_gpu_inplace` undefined from `kv_inplace_write.cpp`), unrelated to this change.

Closes #2061
@inureyes inureyes added this to the 0.8 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) platform:linux Linux (CUDA / packaging) specific 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(bench): ROCm support in the benchmark harness and a published gfx1151 baseline

1 participant