Repository navigation
update(rocm): #1809 matrix rows, paged-attention skips, scan fix - #2059
Merged
Merged
Conversation
…orts them The 34 mlxcel-core tests that launch the paged-attention kernels (v1 decode, v2 partial, merge) failed on ROCm with the launcher's refusal, because those kernels have no HIP port yet. That kept make verify-test-rocm red for a missing port rather than for a wrong number. Add per-kernel support predicates that read each kernel's own KernelPorts table through has_kernel_port (paged_attention_decode_available, paged_attention_v2_partial_available, paged_attention_merge_states_available), bridged to Rust as paged_attention_kernels_available and paged_attention_merge_available. The three production gates that used the backend-wide custom_kernels_available for these kernels (the batched paged decode in cache/paged.rs, MLA split-KV in mla/mod.rs, and paged_decode_backend in layers.rs) now ask the table predicate, so they agree with the dispatch. Metal and CUDA answer true as before. The tests skip through one helper, test_support::kernel_ports, which returns early only when the backend is ROCm and the table predicate is false, prints the skip with the issue number to the process stderr so it shows in the gate log, and stops skipping on its own once a .rocm entry lands.
…cate test_fused_paged_decode_gqa_and_batched and test_fused_paged_decode_native_vs_fallback_matrix gated on metal_is_available() or cuda_is_available(), which check_kernel_port_dispatch.py rule 4 exempted only because paged_attention.cpp exported no support predicate. The predicate now exists, so both tests ask paged_attention_kernels_available(), skip visibly on ROCm through the shared helper, and ffi_tests.rs leaves BACKEND_ENUMERATION_TODO. This is plan item 5 of #1814, which needed nothing but the predicate. The Makefile note on the verify-rocm order no longer cites the paged-attention tests as a known failure.
The ROCm overlay's get_2d_grid_dims(shape, strides, divisor) was an older local copy that dropped a dimension from the divisor only when it divided the divisor whole and never divided the grid by the remainder. Scan::eval_gpu sizes the strided_scan grid with it, so a scan along a non-last axis could launch many times the blocks it needed, each extra block reading and writing past the end of the array. For [1, 48, 24, 24] along axis 2 it returned 576 blocks instead of 48. That shape is the SSD segsum of a 48-head Mamba2 layer over a 24-token chunk. The #1809 correctness matrix hit it as a GPU memory fault in strided_scan: the width-8 trace of granite-4.0-h-tiny-4bit and the width-8 and width-256 traces of NVIDIA-Nemotron-3-Nano-30B-A3B-4bit ended in HSA_STATUS_ERROR_MEMORY_FAULT. The overload now delegates to get_2d_grid_dims_common(shape, strides, divisor), as the CUDA backend and the non-divisor overload beside it do. tests/rocm_strided_scan.rs compares GPU cumsum with the CPU stream exactly on small integers stored as f32, in all four reverse/inclusive combinations; with the old header the [64, 96, 32, 32] case faults in strided_scan on gfx1151. Recorded as LOCAL_FIXES.md item 22.
Teacher-forced traces on gfx1151 at c5fe9a1 for Qwen2.5-7B-Instruct-4bit, gemma-3-4b-it-4bit (including a width-8 shape with 1536 tokens of context, past its 1024-token sliding window), granite-4.0-h-tiny-4bit, NVIDIA-Nemotron-3-Nano-30B-A3B-4bit and Qwen2.5-VL-3B-Instruct-4bit, with METADATA, RUNS and SHA256SUMS. There is no Metal reference for these rows yet; the README gives the exact commands a Metal host runs to produce one and the pairings that are not like-for-like.
Adds docs/benchmark_results/rocm-correctness-gfx1151-2026-09-30.md: the five new rows (ROCm side, Metal side pending, with the commands a Metal host runs), generation checks for each checkpoint including two image prompts, the strided-scan defect the SSM rows found, the Nemotron-H use_fused guard measured before and after #2029, the test-gate change, and the ROCm overlay fork commit stated explicitly. The 2026-09-12 run and docs/installation.md point to it.
…de gate Review follow-ups on the #1809 gate change. - Bridge paged_attention_decode_available (v1) and paged_attention_v2_available (partial and merge) next to the all-kernels and merge-only predicates, and have each skipped test name the kernels it launches (require_paged_decode_port, require_paged_v2_port, require_paged_merge_port, or require_paged_attention_port for the batched decode, which may take either path). A kernel ported on its own now runs its tests again instead of leaving them skipped under a message that had become false. paged_decode_backend asks the v1 predicate. - run_sparse_decode had no port check: on ROCm every layer of every step built its inputs, had the launch refused and reported a rejected plan. It now returns NotServable after its shape and sparsity declines when the v2 kernels have no port, so those declines still report on every backend. - The two ffi_tests paged-decode tests return early for a build with no GPU backend by asking the backend kind, not the predicate, so a wrongly false predicate on Metal or CUDA fails them instead of passing. - tests/rocm_strided_scan.rs generated only zeros; the inputs are now the integers -3 to 3, and the module doc says the grid defect is caught by the fault it causes, since the in-bounds result is unaffected.
Adds the bilingual technical report, describes the per-kernel predicates and the sparse decode gate in the 2026-09-30 matrix document, and corrects the trace METADATA on granite's MoE path and on what the later commits change.
This was referenced Sep 30, 2026
Closed
inureyes
added a commit
that referenced
this pull request
Sep 30, 2026
…2076) Closes #2075 Part of #1801. Each `.hip` file in the ROCm overlay is compiled by its own `add_custom_command`, which listed only the `.hip` source as a dependency. A warm build therefore never recompiled a `hip_objs/*.o` after a header-only change, and a reused tree (the only merge gate while hosted CI is down) could link kernels built against an old header. ## Change - `mlx/backend/rocm/CMakeLists.txt`: under `CMAKE_VERSION >= 3.20` (DEPFILE with the Makefile generators, which `build.rs` gets from `cmake::Config` by default), each command adds `-MD -MF <obj>.d` to `hipcc` and passes `DEPFILE <obj>.d`, with `CMP0116` set to `NEW`. Below 3.20, every object depends on a `GLOB_RECURSE ... CONFIGURE_DEPENDS` list of every header under `mlx/` (rebuilds all on any header change; wider than the issue's backend-only glob because HIP sources also include MLX headers such as `mlx/primitives.h`). MLX's top-level `CMakeLists.txt` requires 3.25, which already implies `CMP0116` NEW, so that branch is not reachable today. - `LOCAL_FIXES.md` item 26 (fork-side build glue, upstreaming candidate for #1813); the stale sentence in item 25 about per-source dependencies now points to it. - `docs/installation.md` (ROCm, Build): incremental builds track headers, `touch` alone rebuilds nothing, and how to force a clean HIP rebuild. ## Dependency chain An overlay edit changes a file under `patches-rocm/`, which `build.rs` watches (`rerun-if-changed`), so Cargo reruns the build script. CMake reconfigures, and `configure_file(... COPYONLY)` rewrites the copy under `_deps/mlx-src` only when its content differs. `hipcc` reads those copies (the `.hip` file's directory and `-I${PROJECT_SOURCE_DIR}` = `_deps/mlx-src`), so every depfile names the copies by absolute path (checked: 0 of 41 depfiles mention `patches-rocm`), and make compares the copy's mtime against the object. A bare `touch` of an overlay header rebuilds nothing, by design. The depfile comes from the host compilation, so it also lists ROCm and system headers (updating them rebuilds everything) but not device-only includes (rocWMMA in `flash_attention_wmma.hip`); the docs say so. ## Verification On gfx1151, CMake 3.31.6, Unix Makefiles, warm `test-fast` tree, rebuilding with `cargo test --profile test-fast --features rocm --test rocm_strided_scan --no-run` and listing `hip_objs/*.o` newer than a marker: | Change | Before | After | |---|---|---| | No change | 0 | 0 | | Comment appended to `kernel_utils.hpp` | 0 of 41 (copy was rewritten) | 39: every object whose depfile names it (all but `event.o`, `quantized/qmv_tiled_kernel.o`) | | Revert of that edit | 0 | the same 39 | | Comment appended to `reduce/reduce.hpp`, then reverted | not run | 7 each time: `reduce.o`, `reduce/{all,col,init,row}_reduce.o`, `layer_norm.o`, `rms_norm.o` | - Both includer sets also match an independent walk of the `#include` graph over the build-tree sources, not just the depfiles. - The first build after picking up this change recompiles all 41 objects once (the command line changed), so existing warm trees heal themselves. - Ninja: not available for the full mlxcel build here. I checked the same pattern (configure_file copy, depfile, CMP0116 NEW) with Ninja 1.13 and Unix Makefiles on a two-file probe project: an edit recompiles only the includer, touch and no-change rebuild nothing, and the depfile names the build-tree copy. - Forced clean rebuild as documented: deleting `hip_objs/` without a touch rebuilt nothing (build script skipped); after touching the overlay `CMakeLists.txt`, 41 objects and 41 depfiles were rebuilt. On that fresh HIP build, `--test rocm_strided_scan` (3 passed) and `--test rocm_slice_update_reduce` (8 passed), both with `--test-threads=1`, confirm the header-only `get_2d_grid_dims` fix from #2059 holds. - After the review follow-up commit (comment and fallback glob only), a rebuild reconfigured and recompiled no HIP object. - `make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-fmt` and `cargo test --test dead_doc_pointers` pass. - `make verify-rocm`: left to the orchestrator's central run. Not verified: Metal and CUDA (not available on this host). The change is confined to the ROCm overlay, which Metal and CUDA builds never copy.
inureyes
added a commit
that referenced
this pull request
Sep 30, 2026
Part of #1809 Brings in the Apple M5 Max Metal traces for the five checkpoints PR #2059 traced on ROCm (commit 9830bd6 from `data/issue-1809-metal-traces`, cherry-picked with its authorship) and completes every row of `docs/benchmark_results/rocm-correctness-gfx1151-2026-09-30.md` against them, Metal as the reference, with the 2026-09-12 criterion (zero mismatches on positions decided at `--decided 2.0`). It also adds two `w1ctx512` rows that cover Metal's fused SSM update kernel (commits d2043c9 and c570666 from the same branch for the Metal half, plus new ROCm traces). ## Result | Pair | Decided mismatches | Verdict | |---|---|---| | qwen2.5-7b-instruct w1 / w8 / w256 | 0/19, 0/274, 0/204 | pass | | gemma-3-4b-it w1 / w8 / w256 / w8ctx1536 | 0/2, 0/320, 0/204, 0/189 | pass | | granite-4.0-h-tiny w1 / w8 / w256 | 0/112, 0/260, 0/208 | pass | | nemotron-3-nano-30b-a3b w1 | 0/0 | inconclusive (no decided position) | | nemotron-3-nano-30b-a3b w8 / w256 | 0/287, 0/216 | pass | | qwen2.5-vl-3b-instruct w1 / w8 / w256 | 0/49, 0/198, 0/154 | pass | | granite-4.0-h-tiny w1ctx512 | 0/60 | pass | | nemotron-3-nano-30b-a3b w1ctx512 | 0/71 | pass | No pair fails. Over the first sixteen pairs top-1 disagrees at 155 of 6720 positions, 0 of 2696 decided; the largest reference gap at a disagreement is 1.250 (Nemotron-H w256, rank 2). The doc also has the logit delta percentiles, perplexity deltas, a 0.5/1.0/2.0 threshold sweep and the rank distribution. ## The w1ctx512 rows The earlier caveat "w1: Metal runs the fused SSM update kernel, ROCm runs the SSD graph" was wrong. The fused step needs `seq_len == 1`, `ssm_kernel_available()` and an existing `ssm_state`, and `logit_trace` builds fresh caches per chunk, so w1 without prefill runs the graph on both backends: w1 is graph against graph. `w1ctx512` (`1 128 8 512`, `MLXCEL_TRACE_START_TOKEN=512`) prefills 512 tokens before each single-token forward, so Metal runs `ssm_update_kernel` (inside `fused_mamba2_forward` for Nemotron-H) and ROCm runs the SSD graph with state. - Both halves are at 3c9edea (`metal_m5_3c9edea0/`, `rocm_gfx1151_3c9edea0/`), a later commit than the other sixteen pairs. The ROCm binary (sha256 `00686315...`) was built on this branch at 8e65051, which differs from 3c9edea only in data and docs. The Metal d112826 w1ctx512 traces have byte-identical data rows. - granite: top-1 4/128, 0/60 decided, largest gap 0.125, perplexity 7.090 Metal vs 7.234 ROCm (+2.0%, about 1 standard error per position). nemotron: 7/128, 0/71, largest gap 0.250, 7.489 vs 7.489. Both are zero at 0.5 and 1.0 too. - The doc lists the ROCm fixes merged between the two commits and where they sit relative to this path (#2070, #2076, #2079, #2071). Apple has no runtime switch to force the graph path, so fused vs graph could not be A/B tested on Metal. ## Not like-for-like (stated in the doc) - The reference is an M5 (generation 17, NAX kernels for multi-token matmul and prefill attention), not the M1 Ultra of the first run, so the two runs' bounds are against different Metal arithmetic. - Nemotron-H compares Metal `fused_moe_forward` with ROCm `forward_nonfused` at every width. - The VLM rows trace the language model only. ## Findings for follow-up - `src/models/nemotron_h.rs` prints five loader lines to stdout, so every Nemotron-H trace (both backends) makes `compare_logit_traces.py` raise `ValueError`. Those pairs were compared on copies filtered with `grep -v '^\[NemotronH\] '`; committed traces are unchanged. The `# device` header line of newer traces is read as metadata and needs no filter. - granite w1 perplexity is +4.345% over 128 no-context positions (about 2.5 standard errors per position) with every top-1 in agreement. ## Verification On the gfx1151 host: `sha256sum -c SHA256SUMS` in all three new or updated trace directories; `cargo build --release --features rocm --example logit_trace` at 8e65051 and the two w1ctx512 ROCm traces (exit 0, 128 data rows, no NaN), each started with no other process in `/sys/class/kfd/kfd/proc`; all 18 comparisons run; `make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-rocm-overlay verify-fmt verify-binary-assets` pass; `cargo test --features rocm --test dead_doc_pointers` pass (2 tests). Not verified: Metal and CUDA are not available on this host. The Metal traces were produced on the M5 Max and are taken on their METADATA.txt, RUNS.txt and checksums. No code on the Metal or CUDA paths changes.
33 of 37 tasks
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
Part of #1809 (the ROCm correctness matrix and the
verify-test-rocmgate). This PR takes the gate from 37 failures to 3, adds the five missing matrix rows on the ROCm side, and fixes a ROCm backend defect those rows found. The issue stays open: the Metal side of the new rows needs a Metal host, and the three remaining gate failures belong to other work.Changes
paged_attention.cpp,paged_attention_v2.cppandpaged_attention_v2_merge.cppeach export a*_available()that reads the kernel's ownKernelPortstable throughhas_kernel_port, bridged to Rust aspaged_attention_kernels_available()(all three),paged_attention_decode_available()(v1),paged_attention_v2_available()(partial and merge) andpaged_attention_merge_available(). The production paths in front of these kernels ask them instead of the backend-widecustom_kernels_available(): batched paged decode (cache/paged.rs, all three), MLA split-KV (mla/mod.rs, merge),paged_decode_backend(layers.rs, v1), andrun_sparse_decode(paged_v2/sparse.rs, v2), which had no port check at all and on ROCm reported a refused launch as a rejected plan on every layer of every step; it now returnsNotServableafter its shape and sparsity declines. On Metal and CUDA every predicate answers true, so those paths do not change.src/lib/mlxcel-core/src/test_support/kernel_ports.rsholds the only skip. Each test names the kernels it needs (require_paged_decode_port!,require_paged_v2_port!,require_paged_merge_port!, orrequire_paged_attention_port!for the batched decode) and returns early only when the backend is ROCm and that predicate is false, printingskipping <module>:<line>: ROCm has no <kernels> kernel port yet (lablup/mlxcel#1814) ...straight to stderr (not througheprintln!, which libtest swallows for a passing test). When perf(rocm): allocator footprint and ROCm ports of mlxcel fused kernels #1814 fills a.rocmentry the matching predicates turn true and those tests run again with no edit, even if the kernels are ported one at a time. On Metal or CUDA a false predicate would be a defect, so nothing skips there.ffi_tests.rspaged-decode tests that returned early unlessmetal_is_available() || cuda_is_available()now skip through the same macro, plus an early return for a build with no GPU backend (by backend kind, so a wrongly false predicate on Metal or CUDA fails them), andffi_tests.rsleavesBACKEND_ENUMERATION_TODOinscripts/ci/check_kernel_port_dispatch.py(it now reports 1 awaiting a predicate,grouped_gemm_numeric_tests.rs).get_2d_grid_dims(shape, strides, divisor)inpatches-rocm/mlx/backend/rocm/kernel_utils.hppwas an older local body that reduced the divisor only by dimensions dividing it whole; for[1, 48, 24, 24]along axis 2 (the SSDsegsumof a 48-head Mamba2 layer over a 24-token chunk) it launched 576 blocks for 48, and the extra blocks read and wrote past the array. The new SSM-hybrid rows hit it asHSA_STATUS_ERROR_MEMORY_FAULTinstrided_scan(granite w8, Nemotron-H w8 and w256). It now delegates toget_2d_grid_dims_common, as the CUDA backend does.LOCAL_FIXES.mditem 22;tests/rocm_strided_scan.rscompares GPU and CPUcumsumexactly, and its[64, 96, 32, 32]case faults with the old header (checked on gfx1151).benchmarks/logit_traces/rocm_gfx1151_c5fe9a16/:Qwen2.5-7B-Instruct-4bit,gemma-3-4b-it-4bit(plus a width-8 shape with 1536 tokens of context, past its 1024-token window),granite-4.0-h-tiny-4bit,NVIDIA-Nemotron-3-Nano-30B-A3B-4bitandQwen2.5-VL-3B-Instruct-4bit, at w1, w8 and w256, with METADATA, RUNS, SHA256SUMS and a README holding the exact Metal commands. All sixteen traces complete with no NaN.TECHNICAL_REPORTS/2059-rocm-correctness-rows-paged-skips-scan-grid-20260930.{en,ko}.md, anddocs/benchmark_results/rocm-correctness-gfx1151-2026-09-30.mdrecords the rows, per-model generation checks (text for all five, an image prompt for the two VLM checkpoints), the scan defect, the Nemotron-H guard result, the gate change, and the overlay fork commit (75915908) stated explicitly. The 2026-09-12 run,docs/installation.mdand the Makefile note onverify-rocmpoint to or reflect it.Metal side of the new rows: pending
No Metal host is reachable from the ROCm host and no committed Metal trace exists for these checkpoints, so no row here has a cross-backend number. A Metal host completes each row with (at the merge commit of this PR, checkpoint revisions from
METADATA.txt):Nemotron-H
use_fusedguard (from #2029)Built at
680eb064(d8d34e2b^, before the guard) and run on gfx1151: the default path generates, becausefused_moe_forwardreached a custom kernel only on its opt-inMLXCEL_FUSED_MOE_RELU2branch; withMLXCEL_FUSED_MOE_RELU2=1it aborts withterminate called ... [metal_kernel] No Metal back-end.(exit 134). At4595b06f, with the guard, both generate. The guard is a confirmed fix for the opt-in path and defensive for the default one.Verification
All on gfx1151 (Radeon 8060S, ROCm 10.0.0 packages, HIP 7.15.26333).
make verify-rocmon the final head9e6147d8(onorigin/main4595b06f, which had not moved), withMLXCEL_ROCM_SMOKE_MODEL=models/mlx/Qwen3-0.6B-4bit. Versions, kernel dtype keys, kernel port dispatch, llama-compat, fmt, workspace clippy--features rocm -D warningsand the ROCm smoke (32 tokens) passed.verify-test-rocm: 11736 passed, 3 failed, 377 ignored, with 36skipping ... lablup/mlxcel#1814lines. The 3 failures are exactly the baseline items this PR does not own: bf16layers::tests::prefill_dense_gemm_matches_qmm_bytes_where_eligible(-p mlxcel-core --lib, 1831 passed / 1 failed), and from feat(nemotron_voicechat): load VoiceChat and run offline duplex inference #2037models::gemma3_backbone::gemma3_backbone_tests::gelu_approx_matches_mlx_nn_bit_for_bit(-p mlxcel --lib, 8723 / 1) andtests::family_order_is_exhaustive(-p mlxcel --bin mlxcel, 248 / 1). No new failure, no abort. Baseline on4595b06fwas 37 failures; the 34 paged-attention ones are gone.tests/rocm_strided_scan.rs: 3 passed (inside the gate too). With the oldkernel_utils.hppthe[64, 96, 32, 32]case faults instrided_scan.paged_v2 mla:: cache::paged ffi_tests::test_fused_paged): 266 passed, 0 failed, 36 skip lines.RUNS.txt). Before the scan fix, granite w8 and Nemotron-H w8 and w256 faulted.-t 0: all five checkpoints produce coherent text; both VLMs describetests/fixtures/test_image_shapes.pngcorrectly.eb37113d.Not verified
patches-rocm/, which Metal and CUDA builds never copy.