You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The gated-delta-rule (GDN) prefill K5 hidden-state recurrence currently ships as a serial,
single-launch emit. A blocked parallel-scan implementation existed in the tree but was
reachable only from bench harnesses. A same-harness, cache-defeated A/B showed the blocked
path beats serial at every measured shape once its partitioning is made count-driven rather
than a fixed block size.
This PR adds the blocked path as a single unified FlyDSL K5 path, wired into
dispatch behind a regime gate, with the existing serial emit as the fallback.
There is no public API change: chunk_gated_delta_rule_fwd_h_flydsl_opt
keeps its signature and return contract, so any shape the gate rejects behaves exactly as before.
Technical Details
The K5 recurrence carries a [V, K] hidden state across chunks. The blocked path partitions
each sequence's chunks into segments (host-scheduled map) and runs three eager FlyDSL launches: build-map
(per-block local products), carry (fp32 carry checkpoints at block boundaries), and emit (re-seed from the block carry and emit outputs).
Partitioning is count-driven per sequence, not a fixed block size:
target_segments = 8 which fills the emit grid at small T and self-limits to the saturating
block size at large T, so one default covers the shape range.
Regime gate. The blocked path is taken only when all of the following hold; any miss falls
through to the unchanged serial emit:
B == 1; gate g present (head-major, g_head_major), no gk; use_exp2; bf16_convert_trunc
K == V == 128, chunk size BT == 64
num_decodes == 0, num_decode_tokens == 0; no state-pool indices; not in-place
bf16 k/w/u; SSM state cache fp32 or bf16; gfx950; not under stream capture
every sequence length > 0, and the longest sequence >= 96 chunks (_BLOCKED_MIN_CHUNKS)
work ratio: blocks * H <= 6 * max_chunks (_BLOCKED_MAX_WORK_PER_CHUNK), where blocks is the total over all sequences
During stream capture the dispatch always falls back to the serial emit. The blocked entry point raises on a zero-length sequence; the gate never routes one to it.
Numerics. The blocked path is a reassociated affine scan (fp32 carry checkpoints at block
boundaries), so it is ~1 BF16 ULP off the uninterrupted serial recurrence by construction. Its distance to the fp32
reference is of the same order as serial's.
AOT replay integration. Upstream #6956 moved FlyDSL AOT to replay-based
compilation. This PR extends that shared framework; review from the authors of #6956 is
requested on these changes:
XCD count is a replay device-profile field mirroring CU_NUM: job key num_xcds, env AITER_NUM_XCDS set by dry_run, and chip_info.get_num_xcds() honors it.
DEVICE_PARTS in replay.py lists the real (num_xcds, cu_num) parts per arch: gfx942 (8, 304) MI300X/MI325X, (6, 228) MI300A, (4, 80) MI308X; gfx950 (8, 256) MI350X/MI355X, (4, 128) MI350P.
Each AOT module declares XCD_VARIANTS as a tuple of arches to fork; _with_xcd_variants expands a job over those parts. A job with a cu_num (a tuned row) forks only to parts of its arch with that cu_num, and an unknown cu_num raises ValueError; a job without one (the blocked module) forks to every part of the arch. chunk_gdn_h uses ("gfx942", "gfx950"), chunk_gdn_blocked uses ("gfx950",). The chunk_gdn_h prebuild is 1344 jobs; the 368 shipped tuned rows are all gfx942 cu_num=80 (MI308X, 4 XCDs) and build only the 4-XCD variant.
chunk_gdn_blocked.py is a replay module enrolled in AOT_MODULES with gfx950 jobs; chunk_gdn_h.py adapted.
Runtime calls chip_info.get_num_xcds() (default 8, a prebuilt variant) instead of a local probe.
The dense wrapper passes lengths=(T_flat,), avoiding a device-to-host .tolist().
Test Plan
op_tests/test_flydsl_linear_attention_prefill.py: correctness is checked against the fp32 torch reference recurrence ref_chunk_gated_delta_rule_fwd_h at rtol = atol = 2e-2, applied independently to the h
snapshots, v_new, and the final state (the bar the serial path already holds to), not
bit-exactness against the serial kernel, which the reassociated scan is not expected to match.
The blocked sweep is a 16-row CLI matrix, plus the existing Qwen3.5-35B sweep:
--context-lens: 8257, 8192,0, 8257,4097
--blocked-mode: dense, varlen (dense rows with more than one prompt are skipped)
--blocked-state-dtype: bf16, fp32
--init-state: 1, 0
Each row asserts the path taken: 12 rows take the blocked path; the 4 (8192, 0) rows fail the gate on the zero length and take the serial path. The (8192, 0) rows also check that the empty sequence's final state equals its initial state.
op_tests/test_gated_delta_rule.py covers the existing GDN prefill path. tests/test_flydsl_aot_replay.py covers the blocked replay jobs, the part expansion through _with_xcd_variants (rows fork 1:1 to (4, 80), every shipped (gfx, cu_num) has a part, an unknown cu_num raises, DEVICE_PARTS CU counts equal GFX_CU_NUMS_MAP), and distinct kernel identities for 4 and 8 XCDs.
Test Result
test_flydsl_linear_attention_prefill.py passes (gfx950): 16/16 blocked-matrix rows and the 16-row Qwen3.5-35B sweep (flydsl, triton, hip), every error within 2e-2.
test_gated_delta_rule.py: 183 passed, 2 skipped.
tests/test_flydsl_aot_replay.py: 16 passed. AOT replay CLIs: chunk_gdn_blocked gfx950 64/64 ok; chunk_gdn_h gfx942 is 1344 jobs (was 2688 before forking by real parts).
flydsl versions: the reviewer re-ran the replay tests, the blocked matrix and the sweep on flydsl 0.4.2 (the version main pins) at f7313ce with all passing; the review-fix commits since then (through 362a0fc451) were run on flydsl 0.4.1.
tp1 L4096 T8192 varlen bf16: 208 µs.
Performance (gfx950, cache-defeated, vs serial emit; applies to calls with output_final_state=True that pass the gate):
Adds an adaptive blocked scan for GDN K5 prefill on gfx950: build_map, an fp32 carry, then emit, replacing the serial chunk recurrence when the gate passes (longest sequence at least 96 chunks, bounded blocks-times-heads work ratio, positive lengths). Other batches keep the serial kernel. The blocked kernels are enrolled in replay-based AOT with an XCD-count device-profile field and a per-arch table of real (XCDs, CUs) parts.
Validation and unverified scope
python3 -m pytest tests/test_flydsl_aot_replay.py gave 16 passed and python3 op_tests/test_flydsl_linear_attention_prefill.py passed 16/16 blocked-matrix rows and the 16-row Qwen3.5-35B sweep on gfx950 (GPU 6, flydsl 0.4.1, FlyDSL runtime cache disabled), all revalidated at 362a0fc451. The AOT replay CLIs gave chunk_gdn_blocked gfx950 64/64 ok and chunk_gdn_h gfx942 1344 jobs. The reviewer validated f7313ce on flydsl 0.4.2. Unverified: the review-fix commits on flydsl 0.4.2, a gfx942 GPU run, and a full PREBUILD_KERNELS wheel build end to end. Main's replay_env sets HIP_VISIBLE_DEVICES=-1, which aborted HIP on our node; that is pre-existing and unchanged here. Merged origin/main and moved the blocked-gate constants into aiter/ops/flydsl/gdn_blocked_constants.py so AOT parse_csv no longer imports the Triton GDN package on GPU-less hosts; verified with GPUs hidden (32 jobs, identical job list).
PR-specific question
In op_tests/test_flydsl_linear_attention_prefill.py the blocked rows would fail before this PR because each row asserts the path taken (blocked for 12 rows, serial for the 4 (8192, 0) rows) and the blocked path did not exist, and no canonical GDN test covers the 96-chunk gate, the work-ratio limit, or both state dtypes with and without an initial state. The AOT part is checked by tests/test_flydsl_aot_replay.py, which asserts distinct kernels for 4 and 8 XCDs and the (arch, cu_num) part forking.
Changed op tests
op_tests/test_flydsl_linear_attention_prefill.py: adds the 16-row blocked matrix (dense and varlen, bf16 and fp32 state, with and without an initial state), each row asserting the path taken against the fp32 reference. Before this PR the blocked recurrence had no test in the canonical GDN prefill suite, so none of these cases would have run. tests/test_flydsl_aot_replay.py (not under op_tests) covers replay XCD expansion.
All standard extended tests (excludes ci:atom_full)
Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5732 --add-label <label>
PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.
The adaptive blocked-scan K5 prefill path previously excluded FlyDSL
run-only deployments from its fast path because its three kernel launches
(build-map, carry, blocked-emit) were not AOT-prebuilt, while the serial
emit fallback was. Under FLYDSL_RUNTIME_RUN_ONLY=1 the blocked path would
have hit a cache-miss RuntimeError, so the regime gate routed run-only to
the serial emit.
Enroll all three blocked kernels for AOT prebuild and drop the run-only
gate clause so run-only takes the fast path too:
- Carry (chunk_gdn_carry_gfx950): convert blocks/requests from
compile-time ints to fx.Int32 runtime kernargs, so the builder cache
key is partition-independent and AOT-enumerable (one variant per
use_initial_state instead of one per (blocks,requests)). Bit-parity
verified against the pre-conversion kernel.
- New chunk_gdn_blocked AOT family (build-map/carry/emit phases) deriving
its (H,Hg) coverage from the serial K5 opt CSV, giving exact automatic
parity with the serial-emit enrollment.
- Drop the not _flydsl_run_only() clause from the blocked-path regime
gate; the helper is retained for its op_test consumer.
Accept fp32 or bf16 external initial_state/final_state at the blocked-path
boundary. Carry loads bf16 h0 via a 16-bit atom and promotes to fp32; emit
compiles its existing bf16 egress branch; final_state allocates in the
resolved dtype. All internal accumulation (maps, carry, entry, emit
recurrence) stays fp32. AOT enrolls bf16 emit+carry variants. Global
serial default is unchanged (still fp32); vLLM passes a bf16 tensor.
Double-buffer A in groups of eight K4 steps, issue all eight C loads before
the multiply loop, and prefetch the next block's first A group during the
current block's tail. Factor the step as _affine_step with the RHS width
as a compile-time parameter for a later log-depth scan.
The PR description presents its regime gate as exhaustive, but these additional conditions are not listed. In particular, g_head_major defaults to False, so a token-major caller can satisfy every documented condition yet silently miss the blocked path; save_new_value=False, in-place state, natural-exp mode, and non-truncating conversion do likewise. Either support these forms or document the complete gate so applicability and performance claims are accurate.
Replace the hard-coded blocked case list with --context-lens,
--blocked-mode, --blocked-state-dtype and --init-state swept through
itertools.product; bf16 and fp32 state both covered by default.
For varlen callers that omit prefill_metadata, this calls cu_seqlens.tolist() before _resolve_adaptive_k5_metadata can inspect its tensor-attached cache. Consequently every repeated eligible forward incurs a blocking device-to-host synchronization even after both the existing prologue and adaptive schedule are cached. Check the adaptive cache using tensor identity/version, T, and target_segments first, and derive/store host lengths only on a cache miss.
Require the longest sequence to have at least 64 chunks and
total_blocks * H <= 6 * max_chunks. Serial time tracks the longest
sequence while blocked time tracks total block-head work, so packed
batches of short prompts fall back to serial; this also bounds the
maps/entry scratch.
Add the missing CLI entry point for direct AOT compilation
aiter/aot/flydsl/chunk_gdn_blocked.py:344
This new AOT module has no main/__main__ entry point, so python -m aiter.aot.flydsl.chunk_gdn_blocked exits successfully without compiling anything. That differs from every sibling AOT module and defeats the direct compile-smoke workflow documented in aiter/aot/flydsl/README.md:34-38; add the same CLI/job runner wiring used by chunk_gdn_h.py:333-399.
Use the input tensor device when selecting the CUDA stream
This launch takes the stream from the process's current CUDA device rather than from k.device. If a caller passes tensors on a non-current GPU, build-map can launch with a stream owned by another device, and it will not be ordered with the carry/emit launches below, which correctly select the tensor device. Use the input device here as well.
Count final-state output traffic when no initial state exists
The final-state tensor is written for every row, including init_state=0, but its traffic is counted only when h0 exists. Consequently the reported TB/s undercounts every no-initial-state row, while rows with h0 correctly count both the input and output state. Count ref_fs unconditionally as the final-state output.
Thanks for the 0.4.2 run. All 24 inline threads are addressed in 66cfe046cf, ff6b9710cd, 35f4fdb9bb, 1f7f4fc2db, 8533bb34b9 (replies inline). The empty-request carry branch is removed and the blocked entry raises on a zero length. The blocked AOT module now reuses XCD_VARIANTS with (xcds, cu_num) pairs; keying chunk_gdn_h's variants by (arch, cu_num) is deferred to a follow-up. The description is updated: 16-row CLI matrix, full gate list, 0.4.2 note replaced by your validation. Revalidated at 8533bb34b9 on GPU 6 (gfx950, flydsl 0.4.1): tests/test_flydsl_aot_replay.py 12 passed, blocked matrix 16/16, Qwen3.5-35B sweep 16/16 (flydsl/triton/hip). The new commits are not yet run on 0.4.2. On the squash message: the merger should drop the branch name (it carries the ticket ID) from the default squash message.
…ports
Move the blocked-gate constants to a dependency-free module so the AOT
collector no longer imports the Triton GDN package on GPU-less build hosts.
The runtime module re-exports the names unchanged.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The raw AITER_NUM_XCDS value causes cache misses for equivalent specializations, and the unbound carry factory bypasses the exported-object cache, preventing full AOT reuse during inference.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because stale cached sequence boundaries and divergent architecture detection threaten correctness, while permissive output checks can miss corrupted tiles.
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
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.
Motivation
The gated-delta-rule (GDN) prefill K5 hidden-state recurrence currently ships as a serial,
single-launch emit. A blocked parallel-scan implementation existed in the tree but was
reachable only from bench harnesses. A same-harness, cache-defeated A/B showed the blocked
path beats serial at every measured shape once its partitioning is made count-driven rather
than a fixed block size.
This PR adds the blocked path as a single unified FlyDSL K5 path, wired into
dispatch behind a regime gate, with the existing serial emit as the fallback.
There is no public API change:
chunk_gated_delta_rule_fwd_h_flydsl_optkeeps its signature and return contract, so any shape the gate rejects behaves exactly as before.
Technical Details
The K5 recurrence carries a
[V, K]hidden state across chunks. The blocked path partitionseach sequence's chunks into segments (host-scheduled map) and runs three eager FlyDSL launches: build-map
(per-block local products), carry (fp32 carry checkpoints at block boundaries), and emit (re-seed from the block carry and emit outputs).
Partitioning is count-driven per sequence, not a fixed block size:
block_chunks = max(12, ceil(ceil(seq_len / 64) / target_segments))
target_segments = 8which fills the emit grid at small T and self-limits to the saturatingblock size at large T, so one default covers the shape range.
Regime gate. The blocked path is taken only when all of the following hold; any miss falls
through to the unchanged serial emit:
B == 1; gategpresent (head-major,g_head_major), nogk;use_exp2;bf16_convert_truncK == V == 128, chunk sizeBT == 64num_decodes == 0,num_decode_tokens == 0; no state-pool indices; not in-placeoutput_final_state=True,save_new_value=True,snapshot_bf16=Truek/w/u; SSM state cache fp32 or bf16; gfx950; not under stream capture_BLOCKED_MIN_CHUNKS)blocks * H <= 6 * max_chunks(_BLOCKED_MAX_WORK_PER_CHUNK), whereblocksis the total over all sequencesDuring stream capture the dispatch always falls back to the serial emit. The blocked entry point raises on a zero-length sequence; the gate never routes one to it.
Numerics. The blocked path is a reassociated affine scan (fp32 carry checkpoints at block
boundaries), so it is ~1 BF16 ULP off the uninterrupted serial recurrence by construction. Its distance to the fp32
reference is of the same order as serial's.
AOT replay integration. Upstream #6956 moved FlyDSL AOT to replay-based
compilation. This PR extends that shared framework; review from the authors of #6956 is
requested on these changes:
CU_NUM: job keynum_xcds, envAITER_NUM_XCDSset bydry_run, andchip_info.get_num_xcds()honors it.DEVICE_PARTSinreplay.pylists the real(num_xcds, cu_num)parts per arch: gfx942(8, 304)MI300X/MI325X,(6, 228)MI300A,(4, 80)MI308X; gfx950(8, 256)MI350X/MI355X,(4, 128)MI350P.XCD_VARIANTSas a tuple of arches to fork;_with_xcd_variantsexpands a job over those parts. A job with acu_num(a tuned row) forks only to parts of its arch with thatcu_num, and an unknowncu_numraisesValueError; a job without one (the blocked module) forks to every part of the arch.chunk_gdn_huses("gfx942", "gfx950"),chunk_gdn_blockeduses("gfx950",). Thechunk_gdn_hprebuild is 1344 jobs; the 368 shipped tuned rows are all gfx942cu_num=80(MI308X, 4 XCDs) and build only the 4-XCD variant.chunk_gdn_blocked.pyis a replay module enrolled inAOT_MODULESwith gfx950 jobs;chunk_gdn_h.pyadapted.chip_info.get_num_xcds()(default 8, a prebuilt variant) instead of a local probe.lengths=(T_flat,), avoiding a device-to-host.tolist().Test Plan
op_tests/test_flydsl_linear_attention_prefill.py: correctness is checked against the fp32 torch reference recurrenceref_chunk_gated_delta_rule_fwd_hatrtol = atol = 2e-2, applied independently to the hsnapshots,
v_new, and the final state (the bar the serial path already holds to), notbit-exactness against the serial kernel, which the reassociated scan is not expected to match.
The blocked sweep is a 16-row CLI matrix, plus the existing Qwen3.5-35B sweep:
--context-lens:8257,8192,0,8257,4097--blocked-mode:dense,varlen(dense rows with more than one prompt are skipped)--blocked-state-dtype:bf16,fp32--init-state:1,0Each row asserts the path taken: 12 rows take the blocked path; the 4
(8192, 0)rows fail the gate on the zero length and take the serial path. The(8192, 0)rows also check that the empty sequence's final state equals its initial state.op_tests/test_gated_delta_rule.pycovers the existing GDN prefill path.tests/test_flydsl_aot_replay.pycovers the blocked replay jobs, the part expansion through_with_xcd_variants(rows fork 1:1 to(4, 80), every shipped(gfx, cu_num)has a part, an unknowncu_numraises,DEVICE_PARTSCU counts equalGFX_CU_NUMS_MAP), and distinct kernel identities for 4 and 8 XCDs.Test Result
test_flydsl_linear_attention_prefill.pypasses (gfx950): 16/16 blocked-matrix rows and the 16-row Qwen3.5-35B sweep (flydsl, triton, hip), every error within 2e-2.test_gated_delta_rule.py: 183 passed, 2 skipped.tests/test_flydsl_aot_replay.py: 16 passed. AOT replay CLIs:chunk_gdn_blockedgfx950 64/64 ok;chunk_gdn_hgfx942 is 1344 jobs (was 2688 before forking by real parts).f7313cewith all passing; the review-fix commits since then (through362a0fc451) were run on flydsl 0.4.1.output_final_state=Truethat pass the gate):Submission Checklist
flydsl-kernel-code-cleanupguidelines.Co-authored-by: Mikko Tukiainen ([email protected])
PR Self-Review
Reviewed revision
283f060
Behavior and intent
Adds an adaptive blocked scan for GDN K5 prefill on gfx950: build_map, an fp32 carry, then emit, replacing the serial chunk recurrence when the gate passes (longest sequence at least 96 chunks, bounded blocks-times-heads work ratio, positive lengths). Other batches keep the serial kernel. The blocked kernels are enrolled in replay-based AOT with an XCD-count device-profile field and a per-arch table of real (XCDs, CUs) parts.
Validation and unverified scope
python3 -m pytest tests/test_flydsl_aot_replay.pygave 16 passed andpython3 op_tests/test_flydsl_linear_attention_prefill.pypassed 16/16 blocked-matrix rows and the 16-row Qwen3.5-35B sweep on gfx950 (GPU 6, flydsl 0.4.1, FlyDSL runtime cache disabled), all revalidated at362a0fc451. The AOT replay CLIs gavechunk_gdn_blockedgfx950 64/64 ok andchunk_gdn_hgfx942 1344 jobs. The reviewer validatedf7313ceon flydsl 0.4.2. Unverified: the review-fix commits on flydsl 0.4.2, a gfx942 GPU run, and a full PREBUILD_KERNELS wheel build end to end. Main's replay_env sets HIP_VISIBLE_DEVICES=-1, which aborted HIP on our node; that is pre-existing and unchanged here. Merged origin/main and moved the blocked-gate constants intoaiter/ops/flydsl/gdn_blocked_constants.pyso AOTparse_csvno longer imports the Triton GDN package on GPU-less hosts; verified with GPUs hidden (32 jobs, identical job list).PR-specific question
In
op_tests/test_flydsl_linear_attention_prefill.pythe blocked rows would fail before this PR because each row asserts the path taken (blocked for 12 rows, serial for the 4(8192, 0)rows) and the blocked path did not exist, and no canonical GDN test covers the 96-chunk gate, the work-ratio limit, or both state dtypes with and without an initial state. The AOT part is checked bytests/test_flydsl_aot_replay.py, which asserts distinct kernels for 4 and 8 XCDs and the(arch, cu_num)part forking.Changed op tests
op_tests/test_flydsl_linear_attention_prefill.py: adds the 16-row blocked matrix (dense and varlen, bf16 and fp32 state, with and without an initial state), each row asserting the path taken against the fp32 reference. Before this PR the blocked recurrence had no test in the canonical GDN prefill suite, so none of these cases would have run.tests/test_flydsl_aot_replay.py(not under op_tests) covers replay XCD expansion.