Repository navigation
[FlyDSL] [gfx950] Add explicit page strides and 64-bit rebase for FP4 MQA logits - #5518
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
95fe436 to
563488a
Compare
…MQA logits Teach pa_mqa_logits_fp4 decode/prefill to honor caller-provided K/scale/block-table page strides and rebase each physical cache page in 64-bit address space before building buffer descriptors. Fixes wrong logits when shared KV pools place pages beyond the 4 GiB range of buffer-instruction byte offsets (reproduced at 4.6 GiB in DeepSeek V4 BLHNC layouts). Assisted-by: OpenAI API coding assistant Signed-off-by: LiuYinfeng01 <[email protected]>
Signed-off-by: LiuYinfeng01 <[email protected]>
563488a to
0030d05
Compare
|
Advisory review (static + hand-run; not a merge gate). Validation/Perf ran no GPU stage — reasons are on their lines below. Findings tagged Extends the gfx950 FlyDSL paged MXFP4 MQA scorers (decode + ragged prefill) to take the KV-cache, scale and block-table page strides from the real tensors and to rebase each physical page in 64-bit before the within-page buffer loads, so shared BLHNC pools whose pages sit beyond the 4 GiB range of a buffer instruction's byte offset address correctly. Review (advisory):
📝 [verified] CI invokes the new test with no flags, so the default run covers eager mode only — every record in the green gfx950 CI log reads "mode": "eager", "sensitivity_checked": false; the CUDAGraph capture/replay and the page-map / scale-permutation mutation checks (the parts guarding the production CUDA-graph decode path) ran only in the author's local --graph --sensitivity invocation. Reviewer should ask for those flags in the standard CI invocation, or for the local JSON logs to be attached to the PR. |
Exit successfully on non-gfx950 runners and enable graph replay plus page-map/scale sensitivity checks in the default CI invocation. Signed-off-by: LiuYinfeng01 <[email protected]>
Select a graph-stable CTA count from host-known batch and context buckets tuned on MI355X, while preserving explicit caller overrides. Cover the 8K/32K/64K/128K schedule table and MTP divisibility constraints. Signed-off-by: LiuYinfeng01 <[email protected]>
25129cc to
7109ff1
Compare
Signed-off-by: LiuYinfeng01 <[email protected]>
7109ff1 to
7db41be
Compare
|
No activity for 15 days, so this is now labelled |
|
please give a full test results for perf before/after this PR |
Guard decode and prefill compute with CTA-uniform effective window bounds. Skip Q/K loads and matrix instructions for padded or fully masked slots without changing scheduling, valid logits, or graph-stable metadata. Cover precomputed speculative schedule refresh in eager and graph replay. Assisted-by: OpenAI Signed-off-by: Liuyinfeng01 <[email protected]>
Resolve the shared schedule relocation without losing tuned CTA selection or preallocated-buffer validation. Preserve upstream ragged row-group and packed-output dispatch together with 64/128-page varctx support and empty CTA compute guards. Keep the public schedule imports used by vLLM. Assisted-by: OpenAI Signed-off-by: Liuyinfeng01 <[email protected]>
Resolve FlyDSL API cleanup conflicts while preserving explicit page strides, 64-bit rebasing and 64/128-row scale layouts. Keep cached launchers compatible with strided and multi-GiB cache storage using fixed-size no-copy views. Validated on gfx950 with FlyDSL 0.4.1: 40 addressing/path/execution comparisons, focused decode/prefill and schedule checks, FP4 writer checks, Black and Ruff. Signed-off-by: Liuyinfeng01 <[email protected]>
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
Replace the fixed block_k=256 restriction with the packed-scale geometry contract: block_k=64*num_warps, 64/128-row pages, and whole-page chunks. Preserve the default 256/4 configuration while restoring OPUS 64/1 cross-check compatibility. Mask non-writer lanes and negative prefill window offsets before buffer stores to prevent offset wraparound at unaligned window starts. Extend existing shared-pool and canonical prefill regressions without weakening tolerances. Validated on MI355X with FlyDSL 0.4.1: 36 OPUS corner rows, 20 zero-mismatch FlyDSL comparisons, 8 NaN propagation checks, 88 shared-pool comparisons, and focused decode/prefill/MTP schedule cases. Black 26.3.0 and Ruff 0.16.0 pass. Full hosted CI and new performance measurements were not rerun. Signed-off-by: Liuyinfeng01 <[email protected]>
c56d8af to
eae452f
Compare
… MQA logits (ROCm#5518) [FlyDSL][gfx950] Add explicit page strides and 64-bit rebase for FP4 MQA logits Honor caller-provided K, scale, and block-table page strides in FP4 MQA decode and prefill. Rebase each physical cache page using 64-bit addressing to support shared KV pools with page offsets beyond 4 GiB. Support 64/128-token pages and compatible block_k/num_warps configurations. Tune persistent CTA scheduling, skip empty compute windows, and fix masked prefill stores. Add shared-pool addressing and graph-replay regressions. Signed-off-by: Liuyinfeng01 <[email protected]>
KV cache layout: ATOM vs vLLM
The diagrams below apply only to the DeepSeek V4 FP4 indexer path covered by this PR. The exact ordering within a block, other cache regions, and padding depend on the allocation.
Here, page stride is the distance between the starts of the same data region in adjacent physical pages. It is not necessarily the size of that region's own page payload. This PR makes the reader use the actual stride and handle large offsets by rebasing the page pointer in 64 bits; it does not rearrange or copy the entire KV pool.
For example, locate the K data of physical page 2 relative to the start of this layer's K0. Assume each K page contains 4096 bytes, while the shared block stride is 16384 bytes (an illustrative value, not a fixed value of the actual configuration):
2 × 4096 = 8192.2 × 16384 = 32768.Both results are byte offsets relative to the start of this layer's K0. The page ID is the same, but the old kernel multiplies it by the wrong stride and therefore reads from the wrong location.
Worked example: page table, stride, preshuffle and 64-bit rebase
The following walks through one read. All row, page, and byte indices are zero-based. All address values are byte offsets relative to the start of this layer's K0, not absolute GPU addresses. The example uses 64-row pages and D=128: each K row contains 64 packed FP4 bytes, so a page contains 4096 K bytes and 256 scale bytes. We continue to assume a shared block stride of 16384 bytes for illustration.
1. Writer and reader must agree on the in-page format
Preshuffle describes the byte order within a page; page stride describes the distance between pages. These are separate properties. The default vLLM #60834 Triton MXFP4 path also uses a shuffled format: vLLM obtains it from AITER's
cache_format()and passesshuffle=layoutto the writer. The optional FlyDSL path in vLLM #56834 writes K/scales directly in FlyDSL's in-page format. Different preshuffle formats are not automatically interchangeable, and this does not require an extra copy to rearrange the data after writing it.Code references: format propagation in the default Triton path and in-page offsets in the writer paired with FlyDSL.
For example, locate packed byte 19 of K row 5 within a page (a packed byte index, not FP4 element 19):
5 * 64 + 19 = 339.1 * 64 * 16 + 5 * 16 + 3 = 1107.If the writer stores this byte at offset 1107, the reader must retrieve it from offset 1107. Reading offset 339 as though the data were row-major would still be wrong even with the correct page ID and page stride. Scales also have a matching in-page order. This 64-row page format is an existing FlyDSL contract, not a new layout invented by #5518.
2. Block table selects the physical page; stride locates its start
Suppose a request's logical pages 0, 1, and 2 map to physical pages
[2, 7, 1]. To read row 5 of that request:Likewise, physical page 7 starts at
7 * 16384 = 114688, and physical page 1 starts at1 * 16384 = 16384. The table selects the page, the stride locates its start, and the preshuffle format locates the data within that page.kv_cache.stride(0)is tensor metadata describing the distance between the starts of adjacent physical pages. It is not calculated from the current request's page table and is not necessarily equal to the page payload size. The K/scale tensors here are uint8, so their element strides are also byte strides. More generally, the byte stride istensor.stride(0) * tensor.element_size().The page table itself also has a row stride. For example, each request may have 3 valid page IDs but reserve 5 int32 slots per row:
Logical page 0 of request 1 must be read from
table[1 * 5 + 0], nottable[1 * 3 + 0]; the latter points into request 0's padding. Here,block_tables.stride(0) == 5is measured in int32 elements, equivalent to 20 bytes, not 5 bytes.The actual reader uses
bt_bt[pid_b * _stride_bt + safe_bi]in_load_phys. The runtime wrapper passeskv_cache.stride(0),kv_scale.stride(0), andblock_tables.stride(0). See the #5518 reader.3. Int64 is an integer width, not a 64-row page or FP64 data
Int64means computing integers using 64 binary bits. It does not mean a 64-row page or 64 bytes, and it does not convert FP4 K data to FP64. Page stride determines the multiplier; integer width determines whether the resulting large value can be represented. Both must be correct.To illustrate the same formula, suppose the page table returns physical page 281250:
This example page ID and stride reproduce the original failing offset of 4,608,000,000 bytes recorded in the PR; they do not imply that the original run used page ID 281250. Simply truncating the value to its low 32 bits would leave
313,032,704. That is an arithmetic illustration of overflow: the actual kernel may instead return zeros through out-of-bounds masking or encounter a memory-access fault, so it must not be assumed to always read this truncated address. Signed 32-bit intermediate calculations can fail earlier, at the 2 GiB boundary.Changing only the multiplication to 64 bits is insufficient because the buffer load's relative byte offset still has a 32-bit range. #5518 first computes and moves the buffer base in 64 bits, then reads using a small in-page offset:
The mathematical target remains
K0 + 4,608,001,107, but the new method no longer puts the entire large offset into the buffer instruction's 32-bit relative offset. The code converts the physical page ID tofx.Int64before computingbyte_offset=phys_shared * fx.Int64(_stride_kv_block)and passing it to_i32_buffer. Converting to 64 bits after a 32-bit multiplication has already overflowed would be too late.The _i32_buffer implementation moves the pointer before creating the buffer descriptor. Its
byte_offset // fx.Int64(4)is only a unit conversion: the pointer advances in 4-byte int32 words, so moving 4,608,000,000 bytes means advancing 1,152,000,000 words. It does not shrink the address or lose precision.Scales are rebased separately using their own start pointer and stride. The vLLM scale view's start pointer already includes the 4096-byte offset past the K region in this layer's page. This process only computes addresses; it does not move K/scales or change the shared pool's block-major arrangement.
Summary
Extend the existing gfx950 FlyDSL paged MXFP4 MQA scorers with shared-pool page strides and 64-bit physical-page rebasing. This changes addressing, not FP4 arithmetic or the default dense layout. Consumer: vllm-project/vllm#57517.
The public runtime wrappers read
kv_cache.stride(0),kv_scale.stride(0), andblock_tables.stride(0); optional stride arguments belong to the build/compile APIs. Cache strides are bytes for uint8 tensors; table stride is int32 elements._i32_buffer(..., byte_offset=...)rebases the descriptor before page-local loads.The scorers now also accept 128-row pages while retaining the 256-token compute chunk. Scale writers/readers use four equal token groups instead of a hard-coded 16-row group, preserving the existing 64-row ABI and correctly packing the two 64-token warp regions of a 128-row page. Both 64- and 128-row decode and prefill cases match the exact FP4-dequant reference at cosine 1.000000. The default decode and prefill correctness sweeps now include 128-row page cases.
The original offset is 4,608,000,000 bytes = 4.608 GB = 4.292 GiB, not 4.6 GiB. #4609 migrated existing scorers to the fx API; it did not first introduce FP4 scoring.
PR Self-Review
Reviewed revision
f6f8f20
Behavior and intent
This revision extends the existing gfx950 FP4 paged MQA decode and prefill scorers to shared-pool caches. Runtime wrappers derive K/scale page strides and block-table row strides from the tensors; physical-page offsets are computed in 64 bits and rebase the buffer descriptor before page-local loads. The existing contiguous-page assumptions and 32-bit physical-page byte offsets cannot address separated layers in a shared pool, including the original 4,608,000,000-byte offset. This is an addressing change, not a change to FP4 arithmetic or the 64-row dense ABI.
The explicit path also supports 128-row pages with a 256-token compute chunk. The writer and readers interleave four equal token groups, rather than assuming every group contains 16 tokens. The decode CTA default uses host-known row/context buckets with an explicit override; no device-to-host synchronization is introduced. Existing row-group dispatch is retained.
The merge with main preserves upstream compiled-launch caching and the prefill row-plan specialization fix. Cache arguments use fixed one-element no-copy views: ordinary flattening rejects page gaps, while a full-span view can overflow the cached launcher's signed-32-bit tensor-dimension marshalling above 2 GiB. These views retain the data pointer and storage offset; the kernel constructs its own buffer resources using explicit strides and 64-bit rebasing, not the view extent.
Validation and unverified scope
Current-revision checks ran on physical GPU 0 of an AMD Instinct MI355X/gfx950, Torch
2.13.0+rocm10.0.0, Triton3.8.0+git669b31ac, FlyDSL0.4.1. The tested source tree exactly matches this merge commit. Disposable containers used read-only candidate source, isolated caches andAITER_TRITON_ONLY=1; existing services and their dependencies were not changed. The base image wassha256:cf6db5a2006b361b8e658d29580de2a11baaacd85e909657b4fee8b362d8eccf.Primary command, from the repository root in that environment:
Result: 40 layout/path/execution comparisons passed, not 40 independent model tests. This covers decode/prefill, dense/strided layouts, eager/graph replay, both sides of 2 GiB and 4 GiB, the original 4.608 GB offset, signed random inputs/nonuniform scales, shuffled pages/padded tables, nonzero storage offsets, tail/empty windows, output guards and deliberate page-map/scale mutations. The original constant-logit case is retained. The independent FP4-dequant checks use unchanged
rtol=2e-4,atol=2e-3; dense/strided payload equivalence is checked separately.Focused existing cases also passed: three decode cases including 64/128-row pages and an MTP/head variation; five prefill cases including 128 heads, ragged/nonzero windows and 128-row pages; four precomputed-decode-schedule cases for
next_n=1,2,4,5in eager/graph mode; and host CTA-selector assertions. Representative commands:Two additional 64-row FP4 compression-writer smoke cases, decode and prefill, passed the existing FP4-dequant check with bit-exact E8M0 scales. Black
26.3.0, CI-pinned Ruff0.16.0 --no-cache, Python syntax checks andgit diff --check HEAD^2 HEADpassed for the PR slice. Logs and structured results are retained locally underoutputs/pr5518-conflict-fix-20261030/; local artifact paths are not public download links.Unverified scope: no clean package/wheel build, full-model quality or serving validation, non-gfx950 numerical execution, or new performance measurement was performed for this merge. The performance tables below are historical measurements under their stated earlier revisions/stacks, not current-head reruns. The existing compression writer reference hardcodes the 64-row scale layout, so independent 128-row writer validation is not claimed; 128-row readers did pass independent FP4-dequant references. Hosted CI must be checked separately; local success does not establish hosted CI success or overall review readiness.
PR-specific question
The path-specific question asks what each changed op test would fail on before this PR and why an existing canonical test is insufficient. The pre-existing decode/prefill suites generated dense 64-row pages with small physical offsets. Passing them does not exercise shared-pool page gaps, padded block-table rows, layer/storage offsets, descriptor rebasing across 2/4 GiB, or 128-row scale grouping. The added decode/prefill cases extend those canonical suites instead of replacing their references or weakening tolerances. The separate shared-pool file compares identical payload bytes under different storage layouts and adds adversarial offsets, graph replay and mutation sensitivity that those small dense cases cannot provide.
The previously recorded negative control against upstream scorer files
246efe9105baproduced a GPU memory-access fault on the small strided case; this historical negative control was not rerun in a shared service. During the current merge validation, ordinary flattening was reproduced to reject page gaps, and full-span cached-launch arguments failed at the 2 GiB case with a signed-32-bit marshalling error. The final fixed-size views passed the same complete regression without tolerance changes. Benchmark reporting additions are evidence-generation helpers, not a claim that every added line is a before-PR correctness failure.Changed op tests
op_tests/test_flydsl_pa_mqa_logits_fp4.py: extends the existing canonical decode suite with page-size-aware scale packing, a default 128-row-page correctness case, and exact host CTA-bucket/MTP-divisibility assertions. The old rectangular path rejects 128-row pages and its hard-coded scale assumptions cannot cover the new layout. Existing dense 64-row numerical cases do not check these boundaries or the new host-only selector contract. This file remains the decode owner; it is not duplicated by the shared-pool adversarial suite.op_tests/test_flydsl_pa_mqa_logits_fp4_prefill.py: extends the existing canonical prefill suite and its reference cache writer to four equal scale groups, adds a 128-row-page case, and retains ragged/nonzero-window checks. The old path rejects 128-row pages, and the old 16-token grouping is insufficient for their scale layout. The FP8 gather/scorer comparison, paired FP4/FP8/BF16 cosine reporting and repeated-shape benchmark helpers serve this prefill measurement protocol; they are not independent correctness regressions. Reusing these quantization/reference helpers avoids a second competing prefill oracle in the new suite.op_tests/test_flydsl_pa_mqa_logits_fp4_strided_pages.py: adds storage-layout and large-address regression coverage absent from both dense canonical suites: same-byte dense/shared-pool comparisons, independent FP4-dequant outputs, 2/4 GiB boundaries and original 4.608 GB offset, nonzero Q/K/scale/output offsets, padded page-table rows, shuffled mappings, output canaries, eager/graph replay and deliberate wrong-map/scale detection. It also checks precomputed decode schedules with changed empty/short MTP windows. Existing dense tests neither allocate these address ranges nor vary these storage strides, so they cannot detect the original dense-page assumption or the new cached-launch flattening/marshalling failures. It reuses canonical prefill helpers rather than replacing their math reference.FP8 -> FP4 indexer micro-benchmark
This is the primary performance comparison for the scorer: the previous paged
FP8 indexer pipeline gathers paged K/scales into contiguous buffers and then
runs FP8 MQA logits; the FP4 path reads the paged cache directly in one kernel.
Both operate on the same synthetic indexer shape and exclude model GEMMs,
attention, scheduler and CPU/server overhead.
MI355X/gfx950, H=64, D=128, page=64. These results were measured inside the
Sep-10 ROCm 10 nightly (
sha256:72e90adf360c...), with Torch2.12.0+rocm10.0.0and Triton3.8.0+git4cff872c.rocm10.0.0. The FP8 arm uses the exact merged #5603 source(
a84bd368); the FP4 arm adds only this PR's three runtime scorer files. Eachshape uses five independent processes, with 10 warmups and 50 timed iterations
per process; medians are shown. FP8 total includes paged gather and FP8 logits;
FP4 is the single direct-paged scorer.
Across this exact-stack sweep, FP4 is 1.21x–1.75x faster than FP8
gather+score. FP4-vs-FP8 is computed directly from both output vectors over the
same valid windows. Every shape also reports
cos=1.000000against the exactFP4-dequant reference, separating kernel correctness from the expected
quantization difference.
The existing op-test calls the FP8 reference pipeline
ATOM cp_gather+fp8_logits; that test name and implementation remain unchanged.Decode uses H=64, D=128, page=64 and the new graph-stable auto-CTA schedule.
The search covered 16–4096 CTAs at 8K/32K/64K/128K; each final row is the
median of five independent processes with 20 warmups and 100 timed iterations.
FP4 and FP8 are measured in the same process on identical inputs.
At 8K, the tuned grid removes the fixed-512 low-batch penalty: B1–B16 are
within 3% of FP8 and B64 is 1.42x faster. At 128K, B1/B2 are at parity and
B4–B64 are 1.68x–2.93x faster; B64 drops from 70.44 us with 512 CTAs to
56.53 us with the tuned grid. The selection uses only host-known row and
maximum-context buckets, so it adds no device-to-host synchronization and is
stable under graph replay. Explicit
parallel_unit_numremains an override.Correctness / regression
Local MI355X, gfx950, GPU 7. Four-commit branch: functional kernel commit
d6807379, consolidated test/benchmark commit0030d058, CI coverage fix063f3eb5, and auto-CTA tuning commit6ab04df3; all are authored by LiuYinfeng01. Torch2.12.0+git6bbd260, HIP7.2.53211; original validation used image Triton3.7.1; the complete correctness suite and standard shape sweep were rerun with the upstream CI Triton3.8.0+amd.rocm7.2.0.git111ff227pin. The strided-page test now enables graph replay and page-map/scale sensitivity checks by default, while non-gfx950 runners print[skip]and exit 0. No NVIDIA validation is implied.-infmasks retained[skip]and exits 0Negative control: running the new small strided case against upstream scorer files from
246efe9105baproduced a GPU memory-access fault (exit 134). The patched source passes the same test. Do not run this negative control in a shared serving process.Appendix: stride/rebase performance non-regression
Following the same-change isolation used in #5285: only the three scorer files differ between baseline
246efe9105baand patched source; same dependencies, GPU and test. Three alternating process-level repetitions, 20 warmups, 100 timed iterations each; table reports the median of the three event-time averages. Dense K/scales and tables are genuinely contiguous and valid on both versions.Scope: public scorer API including internal schedule and output reset, CUDA graph replay; not kernel-only and not vLLM. Rows=32, requests=3, context upper bound=8192 with ragged/empty windows, H=64, D=128, page=64.
Observed ranges overlap (prefill before 36.277–36.635, after 36.070–36.681 us; decode before 37.628–37.764, after 37.197–37.856 us). This auxiliary check only shows that shared-pool addressing did not materially regress the already-existing FP4 scorer; it is not the FP8 -> FP4 speedup table above.
# Run against each source revision, interleaving baseline/patched runs. python op_tests/test_flydsl_pa_mqa_logits_fp4_strided_pages.py \ --case small --layout dense --rows 32 --context 8192 \ --graph --benchmark --iters 100 --warmup 20 --json-output dense-results.jsonArtifacts retained locally under
results/local-kernel-validation/:aiter-address-full.json,aiter-before-after.json,aiter-main-repeat*.json,aiter-patched-repeat*.json. Black and Ruff pass on changed files.AI assistance
AI assistance was used at the author's request. Human review remains required before marking ready.
Signed-off-by: LiuYinfeng01 [email protected]