Repository navigation
[HIP] [Perf] Pipeline CSR segments in unsplit OPUS sparse prefill - #6831
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
bc750cf to
cd38b45
Compare
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
@iraj465 Thanks for this! Prefetching the next tile across the joined prefix/extend stream, and folding the max and sum reductions into the P exchange, is a nice way to cut the exposed latency and barriers. Two requests:
|
Stream prefix and extend CSR tiles through the current gfx950 OPUS kernel. Keep the functional diff and add ten focused unsplit tests while preserving the current precision matrix and relocated headers. Signed-off-by: Saptarshi Majumder <[email protected]>
cd38b45 to
9450a2f
Compare
|
Thanks for the detailed review. Updated in
Python syntax, Black, Ruff and diff checks pass. The unsplit kernel body is retained from the previously measured revision, apart from formatting. Completed MI350X work on At current head The earlier Python 3.12 wheel attempt failed before compilation: DockerHub returned The current-head ATOM GPT-OSS-120B accuracy job has also completed successfully. Its three-shot GSM8K flexible-extract exact-match score is 0.9014404852, above the configured 0.87 threshold, using TP1 and FP8 KV cache. The log records installation of editable AITER at The ATOM DeepSeek-R1-0528 accuracy job attached to this PR head also completed its accuracy and result-check steps successfully. The uploaded three-shot GSM8K table reports 0.9477 flexible-extract exact match. As with the GPT-OSS result, this does not establish changed sparse-kernel dispatch, the 42-case matrix or performance. Two local exact-head attempts stopped before test collection. AITER core built and loaded in the first, then Triton HIPUtils initialization hit read-only The third local attempt has now completed on current head |
Summary
Pipeline the unsplit sparse-MLA prefill kernel on gfx950 for BF16/FP16 and H≤32. It traverses prefix and extend CSR tiles as one stream, prefetches the next KV tile, and reduces the softmax denominator after the final tile.
At the previously measured revision
cd38b45d, MI350X BF16 complete calls improved 1.101–1.162× in eager mode and 1.083–1.208× per graph-replayed call. For default dispatch at N1024/H32, eager latency fell 293.484 → 252.512 µs. The current head9450a2fde1d4783d32f8b84b39b79e303944bfa9has now passed its full 42-case GPU correctness suite, including 10 focused additions to the 32 baseline cases; it has not been re-benchmarked.Motivation
The unsplit kernel can share traversal and normalization work across prefix and extend segments. Combining their tile loops enables prefetching across the segment boundary and defers repeated denominator reductions. The rewrite preserves CSR masking, optional sinks and empty-row behavior.
Changes
gfx950/mla_v4_prefill_a16w16_16mx1_16nx4.hppand enlarge its probability buffer in the traits header.gfx950/header placement and renamed shared-argument include.Performance (if applicable)
These are the retained measurements of
cd38b45d21b6eb428ea5c51c5d333f83d6ab1bc8against269675dead7aa919c9c5eae09cb42e83a35c6567. This review update is based on5eccc0c7bd79e5fa4c53376946d692575b6a17ed; it removes formatting and redundant tests, and preserves the upstream header relocation and shared-argument include. The updated head has not been re-benchmarked.MI350X, gfx950, 256 CUs; PyTorch 2.11.0+rocm7.2, HIP 7.2.26015. BF16; N={64,128,1024}, H={16,32}, head dimension 512, prefix pool 4096, extend pool 1024, top-k 1024, causal extend indices, optional sink present, scale 1/√512, seed 42. Timed entry:
mla_sparse_prefill(..., backend="opus").All rows above execute the changed unsplit kernel and improved in each of four balanced process pairs. Default dispatch benefits at N1024 in this grid. N64/128 improvements above require explicit split1; automatic dispatch there selects unchanged split kernels. This PR does not retune that choice.
Latencies are arithmetic means of four process means; speedups are geometric means of the four paired upstream/PR ratios. Eager events include Python submission gaps. Graph timing divides a 16-call replay by 16 and excludes repeated Python wrapper work and allocation. Neither is a serving measurement.
Reproduction recipe: exact benchmark helpers and pinned build/run instructions (packaging not re-run on GPU).
Complete benchmark grid, controls and paired measurements
Baseline:
269675dead7aa919c9c5eae09cb42e83a35c6567; candidate:cd38b45d21b6eb428ea5c51c5d333f83d6ab1bc8. Image:lmsysorg/sglang@sha256:3a78acc9d6c191f1a12c7c67631657580f06af3af562c9ee6d88282a71ec5e96;GPU_ARCHS=gfx950,ENABLE_CK=0; no CU masks.Four fresh process pairs ran upstream/PR, PR/upstream, PR/upstream, upstream/PR. Each process recorded 101 eager samples and 101 graph replays per row. Initial synchronized warmup was ≥0.5 s; later rows, capture and replay each used ≥0.05 s and at least five calls. JIT compilation, inputs, reference computation and artifact writes were outside timing. All samples were retained without filtering or control correction.
Eager complete-call measurements:
Graph replay, per complete call:
Automatic N64/128 controls selected 6/3/3/2 splits. Their small deviations are not implementation gains or a universal noise bound. At N128/H32, the PR's explicit split1 measured 33.531261 µs graph / 55.856802 µs eager, compared with 38.753409 / 67.417817 µs for automatic split2; the default caller still uses split2.
In the table, B is upstream and C is this PR. Upstream-first order uses cycles 1 and 4; PR-first order uses cycles 2 and 3. Values below are upstream/PR regardless of execution order. Median GM is the geometric mean of four ratios of within-process medians; it does not replace the primary mean estimator.
Substituting within-process medians preserves the direction in every changed pair. At N1024 the graph median-based GMs are 1.092857–1.128166× versus mean-based GMs 1.083174–1.113817×, so the magnitude depends on the estimator. Captured-call correctness checks cover the final (16th) output before and after timed replay.
Static compiler output reports unsplit VGPR 203→250 (BF16), 202→250 (FP16), SGPR 43→62, LDS 70,144→72,192 bytes and zero reported private allocation/spills. Split machine code and descriptors are identical. Achieved occupancy, bandwidth and traffic were not measured, and the complete gain is not attributed to one individual change.
The available host observations do not establish continuous GPU isolation. The original monitoring-status flags remain false; they are separate from the passing numerical checks and do not establish interference. Other historical revisions are excluded from these performance tables.
Benchmark helper:
CSR_6831_NATIVE_BENCH_03.py, SHA256cb79f58383b98a8c12c87841c35d50ace946b4a2ff556d1f96c0e0d3e32b6315. Result SHA256:552545840e025af5ab947cf2016746b4baece1618ed9e1efd3890bf7c5437b3a. All 19,392 separately recorded timing rows match the retained raw arrays; source and native-module hashes were checked before and after execution.Testing
Current review update:
git diff --check.num_kv_splits=1in each case.rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0. These are OPUS primitive/header and device tests; they do not invokeop_tests/test_mla_sparse_prefill.py.9450a2f, TP1 and FP8 KV cache. This is hosted integration accuracy; it does not establish execution of the changed sparse-prefill path or replace its 42-case matrix.9450a2fde1d4783d32f8b84b39b79e303944bfa9completed on 2026-11-05: 42 collected, 42 passed, zero skips, errors or failures inop_tests/test_mla_sparse_prefill.py, on one visible gfx950 GPU. The 42 JUnit cases match the 42 collected test IDs. The run builtmodule_aiter_coreandmodule_mla_prefill_opusin an initially empty private native JIT directory, verified source and native-module integrity before/after testing, and exited successfully. The source snapshot covers 8,168 files and is unchanged. This is correctness evidence for the current suite; the earlier timing table remains tied tocd38b45d.Two separate local attempts stopped before collection. The first built and loaded
module_aiter_core, then Triton HIPUtils initialization tried to create/root/.tritonon the read-only container root. With a private Triton cache, the second passed that initialization but the C++ interface import tried to create/root/.aiteron the same read-only root. These retained runner cache-path failures produced no sparse-prefill test result and are not observed kernel numerical failures. The third attempt used a privateHOME,AITER_JIT_DIRandTRITON_CACHE_DIR, withAITER_ROOT_DIRabsent, and completed the 42-case suite successfully.Current-head native qualification details
Source:
9450a2fde1d4783d32f8b84b39b79e303944bfa9; image:lmsysorg/sglang@sha256:3a78acc9d6c191f1a12c7c67631657580f06af3af562c9ee6d88282a71ec5e96. The isolated source mount was read-only. The run usedHOME=/results/home,AITER_JIT_DIR=/results/aiter_jitandTRITON_CACHE_DIR=/results/triton-cache;AITER_ROOT_DIRwas unset. The native cache started empty.After fresh module compilation, the actual suite commands were:
Result:
PASSED_42_OF_42; 42 collected, 42 matching JUnit cases passed, zero skips/errors/failures. The container ran 2026-11-05 03:13:50–03:15:10 UTC and exited 0. Qualification-result SHA256:425e9c57d34730dbb5470b4ccd58c0acdabbd6e27725e825fdfc2a6bcaf6836a; JUnit SHA256:8adc682b13bf1b6166ff48e485b24c1a270218c641fa1eb40daade81b8754a9f. No timing or serving performance was measured in this qualification.Prior measured revision
cd38b45d21b6eb428ea5c51c5d333f83d6ab1bc8:Tests retain
rtol=atol=0.01and error ratio ≤0.01. The new unsplit cases also check finite output. The current matrix retains BF16, FP8 and NVFP4 coverage; the new cases specifically exercise the modified BF16/FP16 OPUS path. Other GPUs, FP16 performance and serving performance remain unverified.Documentation
Dependencies
Breaking Changes
None. Reduction order and buffering change, with the existing numerical reference and tolerances retained.
PR Self-Review
Reviewed revision
9450a2fde1d4783d32f8b84b39b79e303944bfa9Behavior and intent
Join prefix/extend CSR tile traversal, stage upcoming KV tiles and defer denominator reduction in the gfx950 H≤32 unsplit kernel. The measured BF16 cases improve while split kernels and automatic split selection remain unchanged.
Validation and unverified scope
The updated head passes Python syntax, Black, Ruff, diff hygiene, and comparison with the measured kernel body, accounting for main’s shared-header include relocation. It retains 10 previously tested additions and the current 32-case matrix. Current-head OPUS primitive/device CI, repository dependency, Black and Ruff checks pass. The OPUS job does not run the 42-case sparse-prefill matrix. Hosted ATOM GPT-OSS GSM8K flexible-extract accuracy also passed (0.9014404852 against 0.87) with current-head AITER; this does not attribute execution to the modified sparse kernel. The current head now also passes the full 42-case local native GPU suite on gfx950 with fresh native compilation and unchanged source/module checks. The subsequent current-head hosted run passed both wheel jobs, all eight MI35X standard-test shards, Standard Test Results and the Aiter Test Gate; its earlier DockerHub HTTP 429 failure remains historical. The earlier 142-case and balanced timing results remain bound to cd38b45. Other GPUs, FP16 performance, serving performance, roofline efficiency and continuous isolation remain unverified.
PR-specific question
The existing dispatcher selects this gfx950 A16W16 kernel for supported BF16/FP16 inputs, head dimension 512 and H≤32. Only resolved split count one enters the changed body; higher counts use unchanged code. Wrapper eligibility is not widened. The 10 new cases force split1. The unchanged baseline matrix retains automatic dispatch, partial heads, CSR transitions/tails and empty pools.
Changed op tests
op_tests/test_mla_sparse_prefill.pyadds exactly 10 cases: extend-only and prefix-only inputs in BF16/FP16 (4), mixed segments without a sink in BF16/FP16 (2), extremely negative BF16 logits with no sink or a lower sink (2), and one-key scale-one BF16/FP16 inputs (2). They all force split1 and use the existing FP32 reference and tolerances. The redundant split-K, auto-dispatch, tail, head and empty-pool expansions have been removed.