Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
With NVFP4 sparse K/V on gfx1250 and the MXFP4 checkpoint's native group-32 A8 o_proj, every sparse layer (57) stored the paged attention's BF16 output and o_proj quantized it again (native_quant_linear -> quantize_fp8_kernel: 2.4 us a layer at decode, 7.2 us at prefill). ATOM_MINIMAX_M3_PA_MXFP8_OUT=1 (default off, for A/B) asks aiter's paged decode for that MXFP8 input instead: Attention.forward_mxfp8 allocates E4M3 rows and E8M0 scales [tokens, heads * head_dim / 32] and runs the new custom op unified_attention_with_output_quant_base, which hands them through the sparse impl to pa_decode (an E8M0 output_scale selects the MXFP8 output); o_proj takes them as (x, x_scale). The attention keeps the BF16 call's split: aiter writes the MXFP8 output in every output mode, so the bytes equal the BF16-only attention quantized by quantize_fp8, bit for bit. The path applies when the flag is on, the arch is gfx1250 (construction), the layer's K/V are NVFP4 and o_proj is native group-32 A8 (forward: both are known only after load). Otherwise the BF16 path is unchanged. Dummy-run rows get FP8 zeros and E8M0 1.0 scales (fill_unit_scale). Needs aiter with ROCm/aiter#8289 + ROCm/aiter#8365. Tests: test_nvfp4_attention_mxfp8_output_is_bf16_then_quantize_fp8 (gfx1250: 8 / 37 / 64 / 512 / 2048 rows, bytes and scales equal BF16-only attention + quantize_fp8); tests/test_minimax_m3_pa_mxfp8_out.py (CPU): the model hands (FP8, E8M0) to o_proj only under the flag with NVFP4 K/V and a native A8 o_proj, the attention passes the MXFP8 output with the BF16 split, fill_unit_scale. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e NVFP4 index cache aiter.ops.flydsl.index_score_prefill.index_score_prefill_nvfp4: the MiniMax-M3 prefill indexer's block scores on gfx1250. The index cache is the NVFP4 one: e2m1 payload [pages, 128, 64] plus an E4M3 scale per 16 values [pages, 128, 8], each with its own page stride. score[h, r, blk] is the max, over the block's keys at or before row r's position, of e4m3(clamp(q)) . dequant(K), times sm_scale * log2(e). It is written exactly where and how the Triton prefill scorer writes it. Every dot is the 128-deep scaled WMMA (ROCm#8289's _wmma_scale16). Pages arrive by tensor DMA into an LDS ring (`ring` pages in flight), and operands are read from LDS 16 B at a time. A CTA scores block_q rows (`waves` waves). With lds_scores, each row's chunk of at most CHUNK_MAX blocks goes out in one coalesced store. index_score_prefill_nvfp4_supported() accepts gfx1250 and the cache shapes above only. MI455X, MiniMax-M3.1 TP4 rank, 14336 new tokens on 99968 cached: 97 us against 172 us for the Triton scorer (score + select + emit 141 vs 216 us), the scores bit for bit the Triton scorer's. Short prefills (300 rows) are 2-4 us slower, so callers use it from about 2048 rows. op_tests/test_flydsl_index_score_prefill_nvfp4.py checks it against an FP32 torch reference (about 2e-3 relative: the WMMA's internal sum is not FP32-exact), for ragged batches, chunked prefixes and two CTA shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b30e295 to
f95c298
Compare
DRAFT — evaluation pausedPR Self-ReviewRevision This pull request is a draft, so readiness evaluation is paused and no verdict applies. Evaluation resumes when it is marked ready for review and the required CI completes. |
…e NVFP4 index cache aiter.ops.flydsl.index_score_prefill.index_score_prefill_nvfp4: the MiniMax-M3 prefill indexer's block scores on gfx1250. The index cache is the NVFP4 one: e2m1 payload [pages, 128, 64] plus an E4M3 scale per 16 values [pages, 128, 8], each with its own page stride. score[h, r, blk] is the max, over the block's keys at or before row r's position, of e4m3(clamp(q)) . dequant(K), times sm_scale * log2(e). It is written exactly where and how the Triton prefill scorer writes it. Every dot is the 128-deep scaled WMMA (ROCm#8289's _wmma_scale16). Pages arrive by tensor DMA into an LDS ring (`ring` pages in flight), and operands are read from LDS 16 B at a time. A CTA scores block_q rows (`waves` waves). With lds_scores, each row's chunk of at most CHUNK_MAX blocks goes out in one coalesced store. index_score_prefill_nvfp4_supported() accepts gfx1250 and the cache shapes above only. MI455X, MiniMax-M3.1 TP4 rank, 14336 new tokens on 99968 cached: 97 us against 172 us for the Triton scorer (score + select + emit 141 vs 216 us), the scores bit for bit the Triton scorer's. Short prefills (300 rows) are 2-4 us slower, so callers use it from about 2048 rows. op_tests/test_flydsl_index_score_prefill_nvfp4.py checks it against an FP32 torch reference (about 2e-3 relative: the WMMA's internal sum is not FP32-exact), for ragged batches, chunked prefixes and two CTA shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fsx950223
left a comment
There was a problem hiding this comment.
Reviewed a906e3e, including the complete diff, dispatch and merge helpers, tests, earlier feedback, and CI results. No concrete blocking defect was established. Approval remains pending independent gfx1250 correctness validation of the new NVFP4 pipeline, especially split-query and shared/last-arriver merge modes. The reported intermittent incorrect rows remain unexplained; the author's subsequent stress results are useful evidence but were not independently reproduced.
Validation:
- PASS on
local:git -C source rev-parse HEAD; git -C source diff --check bf5994891 HEAD; Python AST parsing of all six changed files
HEAD is a906e3e. Diff whitespace checks and Python parsing passed. - PASS on
hjbog-srdc-39.amd.com / sixifang_dev:HIP_VISIBLE_DEVICES=1 python3 -c 'import torch,flydsl,aiter; ...'
Verified gfx942:sramecc+:xnack-, FlyDSL 0.5.3 from the task-specific environment, and AITER imports from /tmp/codex-pr-review-8289-a906e3e/source. Details in gfx942-final-tests.log. - PASS on
hjbog-srdc-39.amd.com / sixifang_dev:PYTHONPATH=$PWD:/tmp/codex-pr-review-8289-a906e3e/venv/lib/python3.12/site-packages HIP_VISIBLE_DEVICES=1 flock -w 30 /tmp/codex-pr-review-8289-a906e3e/gpu.lock timeout 180 python3 -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'nvfp4 or export_import_order or softmax_scale_rejected'
Exit 0: 9 passed, 35 skipped, 533 deselected in 33.62s. All NVFP4 cases skipped because this device is gfx942. Source and compilation caches were task-specific. Log: gfx942-final-tests.log. - FAIL on
dzm-mi355-gpu34-dev:ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none -o RemoteCommand=none dzm-mi355-gpu34-dev "squeue -h -u zhiming_ding_qle -o '%i|%N|%t'"
SSH connection to aac16.amd.com port 22 timed out; no allocation or GPU tests could be reached. Log: gfx950-access.log. - SKIP on
gfx1250:python3 -m pytest -q op_tests/test_flydsl_pa_decode.py -k nvfp4
Neither configured host supports gfx1250. The new NVFP4 kernel was not executed during this review.
Remaining validation:
- The gfx942 subset validates imports and existing rejection behavior, not NVFP4 numerical correctness, DMA synchronization, or merge behavior on gfx1250.
- Initial gfx942 collection failed with installed FlyDSL 0.4.0. A task-specific FlyDSL 0.5.3 installation enabled the successful subset without changing global dependencies; setup logs are preserved.
- The failed current CI shard reports a Triton compilation error in unchanged op_tests/test_gemm_a4w4.py. No evidence attributed that failure to this diff. The shard log is preserved in ci-shard.log.
- No independent base comparison or performance measurement was performed. Author-reported GPU, ISA, stress, and serving results were treated as supporting evidence rather than tests executed by this reviewer.
Automated Codex review of commit a906e3e7c5e3.
NVFP4 K/V (packed e2m1, one E4M3 scale per 16 values, token-major per (page, KV head): [128, 64] payload and [128, 8] scale bytes) for the gfx1250 FlyDSL pa_decode, selected by key/value scales of dtype float8_e4m3fn. Gfx1250Nvfp4WavePipeline serves one query tile (<= 16 rows: M3.1 TP4 decode, MTP and prefill rows): each wave owns 32 tokens of every page and DMAs them into a private 3-page ring, QK is v_wmma_scale16_f32_16x16x128_f8f6f4 straight from the raw K rows and their E4M3 scales (the query split into FP8 terms exact to 2^-21 of a 16-dim block's maximum), V is dequantized and transposed by the same instruction with a constant selector, and softmax and P stay in registers, so the page loop has no CTA barrier. Direct, last-arriver, cluster and reducer outputs and the FP8 output epilogue are supported. v_wmma_scale16 misreads 64-bit scale operands that come from an inline constant or an SGPR pair on gfx1250; every selector scale is ORed with a lane-varying zero so it stays in a VGPR pair. The tests extend op_tests/test_flydsl_pa_decode.py: accuracy against an fp32 reference over the dequantized cache in every output mode, and the FP8 output bit for bit against the standalone per-token quant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ode_tile kv_scale_dtype is the dtype of the K/V block scales, not of K/V: packed e2m1 K/V with E4M3 scales is NVFP4, and FP8, BF16 and MXFP4 callers leave it None. Comment only; the module's AST is unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…s, query splits
NVFP4 is a compute dtype of the gfx1250 tile ("nvfp4"), selected by
nvfp4_kv(kv_dtype, kv_scale_dtype) in the host wrapper, compile_pa_decode_tile
and gfx1250_tile_traits alike. compile_pa_decode_tile takes it through the
existing gfx1250 branch, and Gfx1250Traits.bf16 is main's again: the wave tile
passes its 2-byte DMA unit to tdm_copy instead.
pa_decode validates NVFP4 caches with the common shape, dtype, device and
contiguity checks and their scales with the per-token scale checks. The tile's
own limits (head_dim 128, page 128, 16 query rows a CTA) are stated once, in
compile_gfx1250_pa_decode.
No longer refused: sinks (the reducer applies them), sliding windows (the wave
tile masks the window as the BF16 wave tile does) and more than 16 query rows
(query positions split evenly over up to 8 CTAs; cluster selection counts
their grid rows).
ISA of the 15 NVFP4 and 14 FP8/BF16 tile kernels compared is byte-identical to
the previous revision; the NVFP4 symbol tag is now kvnvfp4.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
a906e3e to
a99508c
Compare
…e NVFP4 index cache aiter.ops.flydsl.index_score_prefill.index_score_prefill_nvfp4: the MiniMax-M3 prefill indexer's block scores on gfx1250. The index cache is the NVFP4 one: e2m1 payload [pages, 128, 64] plus an E4M3 scale per 16 values [pages, 128, 8], each with its own page stride. score[h, r, blk] is the max, over the block's keys at or before row r's position, of e4m3(clamp(q)) . dequant(K), times sm_scale * log2(e). It is written exactly where and how the Triton prefill scorer writes it. Every dot is the 128-deep scaled WMMA (ROCm#8289's _wmma_scale16). Pages arrive by tensor DMA into an LDS ring (`ring` pages in flight), and operands are read from LDS 16 B at a time. A CTA scores block_q rows (`waves` waves). With lds_scores, each row's chunk of at most CHUNK_MAX blocks goes out in one coalesced store. index_score_prefill_nvfp4_supported() accepts gfx1250 and the cache shapes above only. MI455X, MiniMax-M3.1 TP4 rank, 14336 new tokens on 99968 cached: 97 us against 172 us for the Triton scorer (score + select + emit 141 vs 216 us), the scores bit for bit the Triton scorer's. Short prefills (300 rows) are 2-4 us slower, so callers use it from about 2048 rows. op_tests/test_flydsl_index_score_prefill_nvfp4.py checks it against an FP32 torch reference (about 2e-3 relative: the WMMA's internal sum is not FP32-exact), for ragged batches, chunked prefixes and two CTA shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What this does
Adds NVFP4 K/V to the gfx1250 FlyDSL
pa_decode. The format is packed e2m1 with one E4M3 scale per 16 values, stored token-major per (page, KV head) as[128, 64]payload bytes and[128, 8]scale bytes. Passingkey_scale/value_scaleof dtypetorch.float8_e4m3fntogether with auint8/fp4x2cache selects it. This is the layout of the MiniMax-M3.1 NVFP4 sparse KV pool (ROCm/ATOM#2744), whose checkpoint is QAT-trained for an NVFP4 KV cache.A new tile,
Gfx1250Nvfp4WavePipeline(pa_decode/pipeline_nvfp4.py), runs at most 16 query rows a CTA. That covers M3.1 TP4 decode, DSpark verify and prefill rows, since the sparse path flattens tokens to one row each. Longer queries split their positions evenly over up to 8 CTAs.v_wmma_scale16_f32_16x16x128_f8f6f4directly on the raw e2m1 K rows and their E4M3 scales, so K is never widened. The query is split into FP8 terms (two for BF16, three for FP16) whose sum is within 2^-21 of each 16-dim block's maximum.quantized_output), sinks, sliding windows, and up to 128 query rows per sequence and KV head (8 CTAs of 16).How it plugs in:
nvfp4_kv(kv_dtype, kv_scale_dtype), decides the format forpa_decode,compile_pa_decode_tileandgfx1250_tile_traits. NVFP4 is its own compute dtype ("nvfp4") of the gfx1250 tile and goes through the existing gfx1250 compile branch;Gfx1250Traits.bf16is unchanged.pa_decodevalidates the caches with its common shape, dtype, device and contiguity checks and the scales with the per-token scale checks (now shared by both scale layouts). The tile's own limits are stated once, incompile_gfx1250_pa_decode.FP8 and BF16 kernels are unchanged: the gfx1250 ISA of 14 FP8/BF16 tile specializations (page16 and page128; direct, cluster, reducer-fed, FP8 output, sliding window) is byte-identical to main, and the reducer is not touched.
gfx1250 erratum:
v_wmma_scale16misreads 64-bit scales from scalar sourcesOn MI455X,
v_wmma_scale16_f32_16x16x128_f8f6f4reads its i64 block-scale operands correctly only from VGPRs. A one-wave probe fed the same selector dequantization with the B scale supplied in four ways:const | lane-varying zero(VGPR)56for block 0, VGPR literal for blocks 1-7)The tile ORs every selector scale with a lane-varying zero,
(lane + context) >> 31, so each scale stays in a VGPR pair (one VALU OR per scale, outside the page loop). Other gfx1250 kernels passing uniform scales tov_wmma_scale*should check their ISA for inline-constant ors[...]scale operands.Benefit
Kernel time on this branch, MI455X,
run_perftest, M3.1 TP4 shape (GQA 16, D128, one KV head), every row attending a full top-16 × 128-token window, median of 3 runs. FP8 is the existing FlyDSL page16 tile with per-token FP8 K/V scales on the same rows and context.NVFP4 halves the KV bytes against FP8 (1.73x KV capacity with the scales), which is what M3.1 serving uses it for; at small batches the kernel is 0.7–1.4 µs slower than FP8 page16.
End to end, MiniMax-M3.1-Flash, TP4 on MI455X, AgentX c64 for 10 min, NVFP4 KV with an FP8 index, measured on an internal stack with this tile, the fused NVFP4 K/V write (companion PR) and the ATOM integration:
GSM8K: 0.947 with this tile, 0.958 for FP8 KV (about 1.1 combined standard errors apart).
Testing
op_tests/test_flydsl_pa_decode.py(extended), run on MI455X:test_pa_decode_nvfp4, 34 cases: plain decode and MTP8 at c4/c64, direct, prefill rows, cluster8, cluster4, last-arriver merge, shared clusters 2×4 / 3×4 / 8×2, reducer, short rows, FP16 query,fp4x2view, GQA 8 with 2 KV heads, query_length 2 (cluster and, with 2 KV heads, reducer); query positions split over 2, 3, 4, 5 and 8 CTAs (cluster, direct, last-arriver merge, reducer; one with 2 KV heads); sinks (also with a split and with a window); sliding windows (direct, last-arriver merge, split cluster); K/V scale planes interleaved in one buffer. Each checks against the file's fp32 reference over the dequantized cache (empty rows included, never-written tail scales poisoned with NaN), pins the output mode the plan picks (merge cases must split a row over several tasks), and checks the FP8 output bit for bit against the standalone per-token quant of the same call (store and quant-only, padded rows, graph replay).test_pa_decode_nvfp4_rejects: partial scale planes, an unaligned scale plane, 64-token pages, 32 query heads over one KV head. Every input stays in bounds for the tile the call must not reach.kvnvfp4w→kvnvfp4); the new split and window specializations compile without spills or scratch (206–245 VGPRs); the 14 FP8/BF16 tiles are byte-identical to main.Not covered
ci:gfx1250-ffm-tritoninffm-bringup.yaml, whose shard 0 runs this test file) requireshead.repo.full_name == github.repository, so it is skipped for this fork PR even with the label.Dependencies
pa_decode.py,traits.pyandpa_decode_kernel.py; the two select different scale dtypes, so whichever lands second needs a rebase only.PR Self-Review
Reviewed revision
a99508c
Behavior and intent
New NVFP4 K/V path for gfx1250
pa_decode, selected only whenkey_scaleisfloat8_e4m3fnand the cache isuint8/fp4x2(nvfp4_kv). Before this PR everyuint8/fp4x2cache is routed to the MXFP4 path, which raisesNotImplementedError("MXFP4 pa_decode supports gfx950")on gfx1250, so the MiniMax-M3.1 NVFP4 KV pool cannot be read there. Existing FP8, BF16, MXFP4 and NHD dispatch is unchanged: NVFP4 is a separate compute dtype ingfx1250_tile_traits, so the FP8/BF16 selection rules do not see it, and FP8/BF16 calls pass the same compile arguments as on main. The per-token scale checks ofpa_decodeare generalised to serve both scale layouts; their FP8 behaviour is the same, with four reworded messages that no test matches. Cluster selection counts a query-split tile's grid rows; cluster runs are not used for NVFP4. The DMA ring depth is fixed at 3 pages (2/3/4 measured within 1.4%; 4 needs more than 256 VGPRs).Validation and unverified scope
op_tests/test_gemm_a4w4.pyfails to compile a Triton kernel in CI). The PA sources and the test file are byte-identical to a906e3e, the 39 tile kernels compared compile to the same ISA as before the rebase, and the host dry run below passes. Nothing was re-run on a GPU after the rebase: the GPU results below are a906e3e's. One whole-file attempt on the rebased tree was aborted (Fatal Python error: Aborted, intest_pa_decode's output check of an existing FP8/BF16 case) at the moment another tenant's job started on the GPU, and was not repeated.python3 -m pytest -q op_tests/test_flydsl_pa_decode.py, MI455X (gfx1250), one GPU, imagerocm/fw-bringup:gfx1250-minimax-m3-20261112with the tree mounted, a906e3e: 403 passed, 174 skipped (another job was loading on the same GPUs during this run).-k nvfp4alone on an idle GPU, a906e3e: 35 passed (test_pa_decode_nvfp4, 34 cases, andtest_pa_decode_nvfp4_rejects). The same whole-file command on main bf59948: 368 passed, 174 skipped.COMPILE_ONLY=1 FLYDSL_COMPILE_ARCH=gfx1250 FLYDSL_DEBUG_DUMP_ASM=1): at a906e3e, 15 NVFP4 tile specializations byte-identical to 4c523d0 apart from the symbol tag and 14 FP8/BF16 tile specializations byte-identical to main bf59948; this revision, the same 29 and the 10 split/window specializations byte-identical to a906e3e's.pa_decodefor the 34 NVFP4 cases and the rejects (validation, plan, tile selection, compile and launch-argument marshalling, nothing launched): the selected output modes equal the ones the GPU run pins.run_perftest, 3 runs, script kept outside the tree) on MI455X: the NVFP4 vs FP8 page16 table above, measured on an earlier revision (a2a59ff08) whose NVFP4 kernels compile to byte-identical ISA; not re-run for this revision.-k nvfp4run that overlapped another tenant's multi-GPU job on the same GPUs (all four at 100% load, about 390 GB of VRAM each) failed three cases whose kernels and launch arguments are unchanged from 4c523d0:mtp8-c64(last-arriver merge, 512 rows),shared-cluster3andshared-cluster8(clusters shared by several sequences) each had a few wrong, finite rows. Those three modes add only the shared cross-CTA merge code (op_merge.py), which compiles to the same instruction sequences in the FP8 and BF16 kernels. Follow-up on one GPU: these three cases and four neighbours (shared cluster 2×4, cluster8, reducer, direct), as NVFP4 and as BF16 and FP8 K/V over the same plans, with the scratch refilled with NaN before every launch and every output compared bit for bit, gave 0 bad launches in 74,700 (about a third per format): idle, next to a memory-bound load process, next to a process that keeps starting short GPU jobs, and with four such probe processes sharing the GPU. The whole-file run above also overlapped another job's start and passed. The original condition could not be recreated.ci:gfx1250-ffm-tritonjob is skipped for fork PRs (ffm-bringup.yamlrequireshead.repo.full_name == github.repository).PR-specific question
What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
test_pa_decode_nvfp4(34 cases inop_tests/test_flydsl_pa_decode.py): before this PR every case fails at the firstpa_decodecall, because theuint8cache is routed to the MXFP4 path, which raisesNotImplementedErroron gfx1250 (or refuses the query length, sinks or window first). No existing test builds an NVFP4 cache (E4M3 scales per 16 values): the file's FP4 cases are MXFP4 with E8M0 scales per 32 values and run on gfx950 only. The reference is the file's existing_reference.test_pa_decode_nvfp4_rejects: before this PR all four calls raiseNotImplementedError("MXFP4 pa_decode supports gfx950")from the MXFP4 path instead of the expected errors and messages. No existing test covers the NVFP4 refusals, since no existing path accepts NVFP4.Changed op tests
op_tests/test_flydsl_pa_decode.py: adds the NVFP4 cache construction (random e2m1 bytes and E4M3 scales, never-written tail scales poisoned with NaN, empty rows, optional sinks, windows and interleaved scale planes) and a 34-case table that pins the output mode (direct, cluster 3/4/8, shared clusters, last-arriver merge, reducer) and runs each case twice (the second call reuses the cached compiled launch). It reuses the file's_referencefor the expected output and_check_quant_outputfor the per-token FP8 output instead of adding a second reference or checker. It is not redundant: no other test callspa_decodewith NVFP4 K/V (op_tests/test_flydsl_sparse_pa_nvfp4.pytests the separate gfx950sparse_pa_nvfp4_*kernels and their own page layout), and this file is the canonicalpa_decodetest that CI collects with pytest.