Repository navigation
[FlyDSL] [Feature] Add quantized attention-output intranode all-to-all for Ulysses sequence-parallel attention - #7648
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
johannes-graner
left a comment
There was a problem hiding this comment.
Thanks for the work on this. Below are the items I would like to see addressed before merge, with a few exceptions. Item 15 is a shared follow-up with the in-hop kernel from #5815, and whether it lands in this PR or a follow-up is up to you. Items 15 to 17 are lower importance and are listed last. Two design questions are also open: one below the items, and one inline on the bench registration line. I would like your view on both.
Items
- 1 — Parity-reuse gate is not exercised by the test
- 2 — e4m3 output diverges from the canonical quantizer for groups containing NaN
- 3 — External-scale reference mirrors the kernel formula
- 4 — External-scale baseline is an eager torch expression
- 5 — Serialized submission streams
- 6 — Input extent is not checked against the raw-buffer limit
- 7 — External-scale agreement and lifetime
- 8 — Arch selection in the wrapper, builder, test and benchmark
- 9 — Shared transport lifecycle
- 10 — Unselected MX encoder in the push builder
- 11 — Share the Hadamard butterfly with the in-hop kernel
- 12 — Unused constant, reimplemented stdlib function, and cache version suffix
- 13 — Input is not stream-recorded when a side stream is passed
- 14 — MX scale swizzle as a shared layout
Lower importance
- 15 — Deprecated and unstable FlyDSL API uses
- 16 — Row-count help text
- 17 — Benchmark sample size
Design questions
- Layout ownership. The transport hard-codes the MXFP6 tile sizes (256 rows, 128 K), the K guards, the payload and scale tile bytes, and the MXFP4 scale shuffle. The host takes its pack size from
mxfp6_gemm_pack_size, but the device addresses the layout independently. A codec name does not pin the layout either: ordinary A4W4 MXFP4 and the H32-rotated FP4 operand for A6W4 weights share a dtype and shape. If the canonical packer changes, source quantization follows it while the peer copy may keep the old addressing. Which module should own each codec's physical layout, and what should happen when that layout changes?
- E4M3 matches per_1x128 for NaN and infinite inputs: a NaN-ignoring group amax from aiter::kAmaxFloor and a clamp that saturates NaN as v_med3_f32 does. - e4m3_external_scale is documented as TorchAO's per-tensor quantization (divide, clamp, cast), with its caller preconditions. - The push kernel only builds the two E4M3 modes; the unused MX encoder is gone. - The wrapper passes its arch to the builders, checks it against the FlyDSL target, requires one stream across calls, records a side-stream input, checks every raw-buffer extent and symmetric-buffer offsets, aggregates missing peer pointers on every rank, and wires AITER_A2A_SPIN_TIMEOUT_ITERS. - The test adds a slow reader against the parity reuse gate, NaN/Inf corners, a stream change, and MXFP4 tail scales of real rows. - The benchmark moves into bench_attention_a2a.py --hop output, times aiter's HIP per-tensor quantizer for e4m3_external_scale, and reports min/median/max.
…e input hop The attention-output packed copy now takes the MXFP6 tile geometry (tile rows, K tile, K guard tiles, payload and scale tile bytes) from aiter.ops.gemm_op_a6w6 instead of restating it. Construction checks that mxfp6_gemm_pack_size for the source packs and the destination matches the tiles the copy addresses and raises on every rank, before any collective or symmetric allocation, if it does not. A negative-construction case patches the packer's pack size and checks that every rank raises. The docstring names each MX codec's layout owner: mxfp4 is the A4W4 activation layout of the per_1x32 quantizer, not the H32-rotated FP4 operand for A6W4 weights. The input-hop kernel from #5815 moves to the stable FlyDSL forms: flyc.get_backend().target.arch instead of flydsl.compiler.backends.current_target, fx.max/fx.min instead of maximumf/minimumf, and fx.gpu.shuffle_xor instead of Numeric.shuffle_xor. For xDiT's A2A profiles and the benchmark's recipes, every compiled kernel's ISA is unchanged.
|
Thanks for the careful review. Everything is addressed on the branch, including item 15 for the input hop's kernel, and item 3 is resolved by changing the contract rather than the kernel (details in the thread). Verification on 8x MI355X:
Design question: layout ownership Each codec's canonical quantizer owns its layout, and the transport now depends on it rather than restating it.
On naming, |
johannes-graner
left a comment
There was a problem hiding this comment.
Thanks for the changes, looks great! Just a couple of nits.
Before merge: the branch conflicts with main in attention_a2a_intranode_kernel.py after #7600 moved to FlyDSL 0.5.0 and removed the _JIT_CACHE_TAG / key tuples there. Taking main's side and dropping the same leftovers in attention_output_a2a_intranode_kernel.py should resolve it. Two minor notes inline, neither blocking.
Resolves the conflict in attention_a2a_intranode_kernel.py by taking main's removal of the cache-key tuple (#7600).
…s bench report FlyDSL 0.5.0 keys its JIT cache on the traced IR, so the _JIT_CACHE_TAG and the key tuples kept alive in both launchers are redundant; this drops them as #7600 did for the input hop. The output hop of bench_attention_a2a.py now writes /tmp/bench_attention_a2a_output_w{world}.md, a name derived from the merged script, instead of the removed bench_attention_output_a2a.py's. Since #5985, per_1x128 skips a bf16 signalling NaN like a quiet one, while the e4m3 path resets the running maximum it is folded into. The docstring now claims byte identity for finite, infinite and quiet-NaN inputs.
|
Merged main and resolved the conflict as you suggested: main's side in
One thing main changed under this PR: since #5985, |
WAITING ON AUTHORPR 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 |
…its PE The attention-output all-to-all (ROCm#7648) reads mori's PE and allocates from its heap. With mori's heap now initialised lazily, it calls ensure_mori_shmem() first, as MoriSymmetricHeap does; that stays a no-op when no aiter EP manager registered a group (the caller initialises mori, as the op's tests do). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Add
AttentionOutputA2AIntraNodeOp, a FlyDSL intranode operator for the attention-output hop of Ulysses sequence parallelism. It quantizes the BF16 MHA output and performs the inverse Ulysses all-to-all over MoRI symmetric memory, writing each destination rank's activation directly in the layout consumed by the following output-projection GEMM.It is the output-side counterpart of the input-hop operator from #5815 and reuses that operator's parity-reuse gate and completion kernels.
Motivation
The output hop currently sends the BF16 attention output through RCCL, and each destination then quantizes it again for its quantized output projection. This operator quantizes at the source and sends quantized bytes, removing the BF16 exchange and the destination's separate activation quantizer:
Changes
aiter/ops/flydsl/attention_output_a2a_intranode.py: the new operator. No existing op changes behavior.aiter/ops/flydsl/kernels/attention_output_a2a_intranode_kernel.py: the E4M3 quantize-and-push kernel and the copy kernel for the canonically packed MX codecs. Buffer reuse and completion usemake_attention_a2a_reuse_jitandmake_attention_a2a_completion_kernelfrom [FlyDSL] [CI] Add FlyDSL fused intranode all-to-all for Ulysses sequence-parallel attention #5815.aiter/ops/flydsl/kernels/attention_a2a_intranode_kernel.py(the input-hop kernel from [FlyDSL] [CI] Add FlyDSL fused intranode all-to-all for Ulysses sequence-parallel attention #5815): moves from deprecated FlyDSL APIs to their stable forms (flyc.get_backend().target.arch,fx.max/fx.min,fx.gpu.shuffle_xor). The compiled ISA is unchanged for every configuration xDiT and the benchmark use.op_tests/multigpu_tests/test_attention_output_a2a.py: the multi-GPU correctness test.op_tests/multigpu_tests/bench_attention_a2a.py:--hop outputbenchmarks the new op against RCCL plus the consumer's quantizer. The input hop stays the default, and both hops share the distributed and MoRI setup.Public contract
AttentionOutputA2AIntraNodeOp(*, rank, world_size, shape, group, codec="e4m3", block_num=128, warp_num_per_block=8)op(input, stream=None, destination_scales=None) -> PackedAttentionOutputResult(payload, scale)ATTENTION_OUTPUT_A2A_CODECS = ("e4m3", "e4m3_external_scale", "mxfp4", "mxfp6")[1, S_global, H_local, 128].S_globalmust divide by the world size, and the world size must be 2, 4, or 8.S_global / world_sizerows for allH_local * world_sizeheads.e4m3per_1x128quantizesgemm_a8w8_blockscalee4m3_external_scaleclamp(x / destination_scales[dst])as TorchAO quantizesdestination_scales[rank], viewed as(1, 1)torch._scaled_mm)mxfp4[rows, features / 2]gemm_a4w4mxfp6gemm_a6w6,gemm_a6w4e4m3is byte-identical to aiter'sper_1x128quantizer for finite, infinite and quiet-NaN inputs. A signalling NaN, which arithmetic never produces, can get a different scale:per_1x128skips it like a quiet NaN ([HIP] Opt group quant gfx1250 #5985), while the op resets the running maximum it is folded into.e4m3_external_scalefollows TorchAO's dynamic per-tensor activation quantization (_quantize_affine_float8: divide, clamp, cast), which the consuming projection runs. It is notstatic_per_tensor_quant, which multiplies by the hardware reciprocal of the scale and rounds a few values differently. A NaN input becomes an FP8 NaN, though not always with TorchAO's sign bit.e4m3_external_scaleapplies no scaling policy and performs no reduction. The caller passes one FP32 descale per destination rank and must keep them positive and finite, identical on every source rank for a given destination, ready on the launch stream, and unchanged until the consuming GEMM has read the result. The op checks only dtype, shape, device and contiguity.e4m3also targets gfx942 (FNUZ). The other codecs require gfx950.e4m3_external_scale, alias double-buffered symmetric storage that is reused two calls later. Consumers must finish before then, and a consumer on another stream must be joined explicitly.destination_scales, andinputwhenstreamis passed, are recorded on the launch stream.groupis mandatory and must contain exactly the MoRI participants.Safety checks
mxfp6, the copy takes its tile geometry from the A6W6 packer (aiter/ops/gemm_op_a6w6.py), and construction raises ifmxfp6_gemm_pack_sizedisagrees with the tiles the copy addresses. Themxfp4scale shuffle matchesaiter::mx_scale_shuffle_idx, and the test compares both layouts byte for byte against the canonical quantizers.destination_scalescontract.AITER_A2A_SPIN_TIMEOUT_ITERS=Nmakes each device wait loop trap after N polls instead of hanging, as in [FlyDSL] [CI] Add FlyDSL fused intranode all-to-all for Ulysses sequence-parallel attention #5815.Performance (if applicable)
python3 op_tests/multigpu_tests/bench_attention_a2a.py -w 8 --hop output --shapes wan2.2 --iterations 50. "Before" is the work the operator replaces: the RCCL inverse all-to-all of the BF16 output followed by the consumer's quantizer on the destination, which fore4m3_external_scaleis aiter's HIP per-tensor quantizer. Fore4m3_external_scale, "After" also includes the caller's scale policy (per-destination amax and a world-size MAX all-reduce). Outputs are compared bit-exactly before timing; fore4m3_external_scalethe comparison is against TorchAO's formula.Bandwidth is the BF16 attention output each rank exchanges (97.0 MB at the Wan2.2 shape) divided by the slowest rank's median time, as in the
nccl-testsalgorithm bandwidth. The benchmark also reports min and max.e4m3e4m3_external_scalemxfp4mxfp6End to end, the xDiT integration speeds up 40-step Wan2.2 T2V runs on eight GPUs by 1.4% to 2.5%, depending on the GEMM format.
Testing
Tested on MI355X (gfx950). MI250X is not supported.
e4m3also targets gfx942 but has not been run on MI300X; see "Validation and unverified scope".Documentation
The contract is documented in the module, class, and result docstrings. The guides have no page for the intranode attention A2A operators.
Dependencies
The operator uses MoRI and FlyDSL, which the input-hop operator from #5815 already requires.
Breaking Changes
None.
PR Self-Review
Reviewed revision
c10d847
Behavior and intent
This PR adds a new op,
AttentionOutputA2AIntraNodeOp, and changes no existing op's behavior. For the Ulysses output hop, xDiT currently sends the BF16 attention output through RCCLall_to_all_single, and the output projection then quantizes it again. The new op quantizes at the source into the consumer GEMM's activation layout and writes each destination's rows into its MoRI symmetric buffer, so both the BF16 exchange and the separate quantizer go away. At the Wan2.2 shape on eight MI355X GPUs, it reaches 2.3x to 2.9x the bandwidth of RCCL plus the quantizer.Validation and unverified scope
python3 op_tests/multigpu_tests/test_attention_output_a2a.py -w 2 4 8:completed rows=24 checks=952 failures=0. For all four codecs at world sizes 2, 4, and 8, with 256 and 1184 destination rows (1184 is not a multiple of 256, so it exercises the row-tile tails), it checks:e4m3_external_scalebytes are compared up to the sign of NaN. MXFP4 tails compare the scales of real rows at their shuffled offsets.gemm_a8w8_blockscale,torch._scaled_mm,gemm_a4w4,gemm_a6w6, andgemm_a6w4.python3 op_tests/multigpu_tests/test_attention_a2a.py -w 2 4 8 --heads 8 40, as CI runs it, passes on both:completed rows=273 checks=14686 failures=0.e4m3path has not been run. End-to-end coverage comes from the xDiT integration, which is not part of this PR.PR-specific question
Pending: answered once the automated PR Self-Review comment posts its question for this revision.
Changed op tests
op_tests/multigpu_tests/test_attention_output_a2a.py: the correctness test for the new op, which no existing test covers. It checks every codec's payload and scale bytes against the canonical quantizer after an RCCL inverse all-to-all, the consumer GEMM outputs bitwise, buffer reuse across calls, a delayed rank, a slow reader against the reuse gate, and the errors every rank raises for invalid configurations.op_tests/multigpu_tests/bench_attention_a2a.py:--hop outputis the perf harness for the op and the source of the table above. Before timing, it compares the op's outputs bit-exactly against RCCLall_to_all_singleplus the consumer's quantizer. CI already skips this file viaskip_tests.