Repository navigation
[Triton/Gluon] [HIP] [FlyDSL] fix(topk): graph-safe end=None; tgemm.mm(out=); one amax floor - #6833
Conversation
topk_select built its default `end` from an 8-entry LRU keyed on the row count. Capturing a ninth count evicted, and freed, the tensor an earlier graph had baked in; replaying that graph read reused memory (wrong draft tokens, then a memory fault, ROCm/ATOM#2663). Every backend now takes a full-rows build that reads each row's length from the runtime width, and is handed an empty sentinel (`row_lens.py`) in place of the tensor. Widths that are a whole number of vectors also compile the per-element row test out. Explicit lengths are clamped to the width, so an `end` past the row no longer selects the zeros an out-of-bounds load returns. The streaming selector's launch logic moves out of topk_select into aiter/ops/flydsl/topk/topk_per_row_radix_stream.py, beside the other backends' host wrappers.
`gemm_a16w16_out` (a mutating custom op) and `hipb_mm(out=)` let a caller whose consumer reads one fixed address take the GEMM result there. Every backend (asm, flydsl, opus, triton, skinny, hipBLASLt) writes into `out` directly; the untuned torch paths and a skinny call with a wider `out` take the result by copy. `-t out` in test_gemm_a16w16 checks each backend lands in `out` and matches its own `out=None` answer.
…izers The kernels seeded a group's amax with 1e-6, 1e-8, 1e-10 or 1e-12 depending on the file, so a fused quantizer and the reference one disagreed on all-zero groups (graph warmup, padded rows). They now share `kAmaxFloor = 1e-10` from csrc/include/quant_amax_floor.h, which is also ATOM's AMAX_FLOOR. The per-token KV cache quant floors the amax rather than the inverse scale, so the stored scale is the one used and never 0. The Triton dual RMSNorm + MXFP8 quant takes the same floor as an opt-in `amax_floor` (default 0, unchanged behaviour).
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Brings in #6833, where `seq_lens=None` selects a full-rows build that reads no length tensor. The adaptive kernel reads `seq_lens[r]`, so the gate now declines it when `seq_lens` is None and those calls take main's full-rows path. `max_row_len` is still threaded through `topk_select` and the decode entry.
… is graph-safe ROCm/aiter#6833 makes `topk_select(end=None)` read no row-length tensor, so the LM head no longer needs to hold one per captured row count. Back to main's `compute_argmax_token`. Also fold the batch-last capacity helper into `buffer()` and cover the Qwen3.8 MTP draft-graph declaration under MRoPE. Co-authored-by: Cursor <[email protected]>
#2663) * feat(spec): capture Qwen3.8 MTP draft steps 1+ with MRoPE positions Co-authored-by: Cursor <[email protected]> * fix(spec): keep the draft argmax row lengths alive across captured sizes Co-authored-by: Cursor <[email protected]> * refactor(spec): drop the draft argmax row-length cache now that aiter is graph-safe ROCm/aiter#6833 makes `topk_select(end=None)` read no row-length tensor, so the LM head no longer needs to hold one per captured row count. Back to main's `compute_argmax_token`. Also fold the batch-last capacity helper into `buffer()` and cover the Qwen3.8 MTP draft-graph declaration under MRoPE. Co-authored-by: Cursor <[email protected]> * docs(spec): say the staged pad repeats the last real sequence, not row For a batch_last input (MRoPE positions, [3, N]) the tail repeat copies the last column, so the _stage_one docstring now names the last real sequence instead of the last row. * fix(spec): refuse staging a view of the fixed storage other than its own A batch_last view's stride is its batch, so buffer(role, scheduled_bs) overlaps the running_bs view at a different layout. Staging it took the copy branch over that overlap and scrambled the positions without an error. No caller fills a batch_last input today (MRoPE positions are a fresh index_select), so assert instead of cloning, and say in `buffer` which view a producer fills for each layout. Tests: the batch_last fill at running_bs, the refused narrower view, and a draft step at running_bs > scheduled_bs, eager and replayed. * refactor(spec): name undeclared staged roles; keep batch_last out of buffer() stage() counted batches through self.inputs[role] before anything checked the role, so a typo surfaced as a bare KeyError. stage() and buffer() now share one assert that names the undeclared and the declared roles. The overlapping self-copy guard in _stage_one is replaced at its source: only buffer() could hand out a batch_last view whose stride differs from the one stage writes, and nothing fills a batch_last input in place. So buffer() refuses batch_last roles, and _stage_one's copy test, buffer()'s capacity and its docstring go back to main's. Also folds _view into its one caller, trims docstrings, and drops tests of the removed API; the batch_last staging test now uses a producer-filled leading input beside the positions. * refactor(spec): leave main's buffer() check and tests as they were Keep the change to main's code to what batch_last needs: - stage() names undeclared roles with its own assert; buffer() keeps main's role check, with only the batch-last refusal added after it. - The staging ndim message keeps main's "leading axis is not the batch" wording, so main's test for it keeps its match; its docstring changes only the two sentences batch_last made untrue. - The batch-last disagreement case is its own test again rather than a second case inside main's test. - The _declare_draft_graphs docstring keeps main's paragraph and adds one sentence for draft_graph_supports_mrope. * refactor(spec): stage MRoPE positions by batch_dim, not batch_last StagedInput says which axis is the batch (batch_dim, default 0) instead of whether it is last. bind() allocates max_num_seqs at that axis, and stage(), buffer() and the tail repeat narrow along it: one path for every layout, with no branch on it. MRoPE positions are now a [3, max_num_seqs] buffer, viewed per batch as [3, bs] with stride (max_num_seqs, 1). Every reader of the draft's positions indexes them by stride (rows by stride(0), tokens with stride(-1) == 1) or reads only shape[-1]. A batch-1 view is the front of a wider one at the same stride, so buffer() no longer refuses batch_dim=1 roles; a test stages a producer fill of one. --------- Co-authored-by: Cursor <[email protected]>
…oduce only Address review: - _vocab_shard_logits makes a single tgemm.mm(..., out=out) call. aiter's tgemm.mm takes out (ROCm/aiter#6833); the second call path for an older aiter is gone. The CPU test's tgemm stub takes out too. - DeviceBytes moves to atom/utils/device_bytes.py. The mono runtime (uncached, peer_memory, the V4 mono runtime) and the DP logits exchange import it from there, so atom/distributed no longer depends on atom/mono. - PeerLogitsExchange.__call__ is removed; produce is the one entry. The warm-up runs produce(lambda dst: None, rows, rows), so the scratch allocation and copy in prepare_dp_logits_exchange are gone. The four-rank test copies its inputs in through produce. - _gather_rows is inlined back into produce, with the raw 64-bit words comment restored. - start goes back next to the argmax branch that uses it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oduce only Address review: - _vocab_shard_logits makes a single tgemm.mm(..., out=out) call. aiter's tgemm.mm takes out (ROCm/aiter#6833); the second call path for an older aiter is gone. The CPU test's tgemm stub takes out too. - DeviceBytes moves to atom/utils/device_bytes.py. The mono runtime (uncached, peer_memory, the V4 mono runtime) and the DP logits exchange import it from there, so atom/distributed no longer depends on atom/mono. - PeerLogitsExchange.__call__ is removed; produce is the one entry. The warm-up runs produce(lambda dst: None, rows, rows), so the scratch allocation and copy in prepare_dp_logits_exchange are gone. The four-rank test copies its inputs in through produce. - _gather_rows is inlined back into produce, with the raw 64-bit words comment restored. - start goes back next to the argmax branch that uses it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* feat(spec): capture Qwen3.8 MTP draft steps 1+ with MRoPE positions Co-authored-by: Cursor <[email protected]> * fix(spec): keep the draft argmax row lengths alive across captured sizes Co-authored-by: Cursor <[email protected]> * Optimize QSA for gfx1250 TDM gather Co-authored-by: Cursor <[email protected]> * refactor(spec): drop the draft argmax row-length cache now that aiter is graph-safe ROCm/aiter#6833 makes `topk_select(end=None)` read no row-length tensor, so the LM head no longer needs to hold one per captured row count. Back to main's `compute_argmax_token`. Also fold the batch-last capacity helper into `buffer()` and cover the Qwen3.8 MTP draft-graph declaration under MRoPE. Co-authored-by: Cursor <[email protected]> * Optimize gfx1250 QSA index scoring Co-authored-by: Cursor <[email protected]> * docs(spec): say the staged pad repeats the last real sequence, not row For a batch_last input (MRoPE positions, [3, N]) the tail repeat copies the last column, so the _stage_one docstring now names the last real sequence instead of the last row. * fix(spec): refuse staging a view of the fixed storage other than its own A batch_last view's stride is its batch, so buffer(role, scheduled_bs) overlaps the running_bs view at a different layout. Staging it took the copy branch over that overlap and scrambled the positions without an error. No caller fills a batch_last input today (MRoPE positions are a fresh index_select), so assert instead of cloning, and say in `buffer` which view a producer fills for each layout. Tests: the batch_last fill at running_bs, the refused narrower view, and a draft step at running_bs > scheduled_bs, eager and replayed. * refactor(spec): name undeclared staged roles; keep batch_last out of buffer() stage() counted batches through self.inputs[role] before anything checked the role, so a typo surfaced as a bare KeyError. stage() and buffer() now share one assert that names the undeclared and the declared roles. The overlapping self-copy guard in _stage_one is replaced at its source: only buffer() could hand out a batch_last view whose stride differs from the one stage writes, and nothing fills a batch_last input in place. So buffer() refuses batch_last roles, and _stage_one's copy test, buffer()'s capacity and its docstring go back to main's. Also folds _view into its one caller, trims docstrings, and drops tests of the removed API; the batch_last staging test now uses a producer-filled leading input beside the positions. * refactor(spec): leave main's buffer() check and tests as they were Keep the change to main's code to what batch_last needs: - stage() names undeclared roles with its own assert; buffer() keeps main's role check, with only the batch-last refusal added after it. - The staging ndim message keeps main's "leading axis is not the batch" wording, so main's test for it keeps its match; its docstring changes only the two sentences batch_last made untrue. - The batch-last disagreement case is its own test again rather than a second case inside main's test. - The _declare_draft_graphs docstring keeps main's paragraph and adds one sentence for draft_graph_supports_mrope. * perf(qwen4-exp): keep 128-aligned MXFP4 expert intermediate unpadded (#2649) * perf(qwen4-exp): keep 128-aligned MXFP4 expert intermediate unpadded The MXFP4 MoE method pads expert weights to a multiple of 256, which turns Qwen3.8-Flash-Next's moe_intermediate_size 640 into 768 at TP1: one sixth of every expert is zeros, ~12 GB of HBM that the KV cache could use. Pass pad_align=128 when the per-rank intermediate is already a 128-multiple (as Kimi-K3 / DeepSeek-V4 do) and keep the default otherwise. ATOM_QWEN4_MOE_PAD_ALIGN overrides the choice (e.g. 256 for the old layout). Co-authored-by: Cursor <[email protected]> * refactor(qwen4-exp): drop ATOM_QWEN4_MOE_PAD_ALIGN, keep the TP-based 128 pad align The env override is not needed: 128 is used whenever the per-rank expert intermediate is already a multiple of 128 (TP1: 640), and every other shard keeps the MXFP4 default of 256. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]> * fix(mtp): keep side-stream D2H sources alive until the copy runs (#2654) * fix(mtp): keep side-stream D2H sources alive until the copy runs tokenIDProcessor copies the sampled ids, the MTP verdict (num_rejected / num_bonus) and the draft ids to the host on async_copy_stream. The sources are fresh default-stream allocations that the caller drops right after queuing the copy, so the caching allocator can hand their block to the next default-stream allocation before the side-stream copy has run. A late copy (work queued on the copy stream, or on another stream sharing its hardware queue) then reads the next step's tensor. Under MTP the stale num_bonus becomes num_accepted_tokens, which the GDN conv update kernel adds to the conv-state offset unchecked: an illegal memory access. Record each source on async_copy_stream so its block is not reused until the copy has executed. Co-authored-by: Cursor <[email protected]> * fix(dspark): keep the ell D2H source alive until the copy runs VerifyScheduler.record_ell queues the ell D2H on the runner's async_copy_stream, the same stream and the same race as the tokenIDProcessor copies: ell is a fresh default-stream tensor that is dropped after the copy is queued, so its block can be reused before the copy has run. Hold it with tokenIDProcessor._hold_for_copy_stream, and cover the path in the GPU test. Suggested by @yitingw1 in review. Co-authored-by: Cursor <[email protected]> * fix(output): hold side-stream D2H sources until the copy is waited on Replace `_hold_for_copy_stream` / `record_stream` with explicit references kept next to the completion events that already exist, released only after that event has been waited on. No new CUDA events. - `send_to_cpu_async`: the sampled ids and logprobs go into the `cpu_tensor_handle` entry with `cpu_tensor` and `copy_done`; `recv_async_output` waits on `copy_done`, then pops the entry. - `D2HQueue` (spec status, draft ids): each slot holds its source; `receive` clears it after `copy_done.synchronize()`. New `drain()` waits for and drops every pending transfer. - DSpark `record_ell`: `ell` is held with its ring slot's event and released when `_ell_stage` reuses the slot after that event; a one-off buffer keeps `ell` with the copy's own event until it completes. `_ell_pending` eviction no longer decides the source's lifetime. - `tokenIDProcessor.clean()` waits for every queued copy before dropping the handles and queues. Tests: the GPU lifetime test covers spec status, sampled ids, logprobs, draft ids, DSpark ell (ring slot and one-off buffer) and clean() with copies in flight; its positive control strips the holds (for clean(), skips the wait) and requires every path to race. CPU tests check each source is released only after its event has been waited on. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]> * feat(qwen4-exp): QSA FP8 KV and FP8 / FP4 index caches, with a stacked-head decode scorer (#2652) * perf(qwen4-exp): stack index heads into M for the QSA decode scorer Decode-sized QSA index scoring (the target's MTP verify and the draft, at most 256 rows) ran on the CUDA-core kernel, which reads every request's compressed keys once per query row. The new Triton MFMA kernel stacks 4 rows x 4 index heads into one M = 16 operand, so a request's keys are read once per verify and meet every head in a single dot; the per-head ReLU is applied before the heads are summed back out of M. On Qwen3.8-Flash-Next (MI355X, TP1, MTP 3) the target's decode scoring drops from 1130 to 320 us a step and the draft's from 147 to 85 us, -6.2% of decode kernel time. ATOM_QSA_STACKED_DECODE_SCORER=0 keeps the old kernel. Co-authored-by: Cursor <[email protected]> * feat(qwen4-exp): FP8 KV and FP8 / FP4 index caches for QSA Qwen QSA refused anything but a BF16 KV cache and ignored --index-cache-dtype. Serve --kv_cache_dtype fp8 and --index-cache-dtype {bf16,fp8,fp4} (unset follows the KV dtype, as Config resolves it): - K/V: E4M3 with one FP32 scale per (token, KV head) = row amax / FP8 max, written by a new Triton kernel (K and V in one launch). Dynamic scales need no calibration and never saturate. The sparse GQA kernel reads E4M3 tiles, multiplies the key scale into its score column and folds the value scale into the probability before PV; FP8 tiles have their own tuned block config. - Compressed index keys: FP8 with a per-row FP32 scale, or MXFP4 (packed E2M1 pairs, one E8M0 exponent per 32 dims, rounded up so a group never clips). Every scorer -- the stacked decode one, the CUDA-core one and the prefill MFMA one -- reads them; FP4 decodes with bit operations. The raw index keys stay BF16: they are mean-pooled before normalization and a group can straddle a prefill chunk. - The MTP draft layer keeps BF16 caches in a `qsa_draft` row space of its own (ATOM_QSA_DRAFT_KV_BF16, default 1): an FP8 draft KV lowers the real acceptance length by ~3.5%, a BF16 one not at all. - `_qsa_fields` declares the scale planes, so the arena sizes the pool by bytes; the memory profile runs on caches of the served format. Plugin hosts keep binding their own BF16 caches. On Qwen3.8-Flash-Next (MI355X, TP1, MTP 3) FP8 KV fits 1.64-1.67x the tokens, cuts prefill sparse GQA by 17%, and leaves GSM8K and the MTP acceptance length unchanged. With --block-size 64 and a BF16 index cache the prefill scorer stays on FlyDSL. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]> * Support FP8 K/V in the gfx1250 QSA TDM sparse GQA kernel Co-authored-by: Cursor <[email protected]> * feat(qwen4-exp): online PTPC FP8 for the GDN in_proj, with fused activation quant (#2650) `--online_quant_config` with a ptpc_fp8 target raised on every GDN layer of a BF16-attention checkpoint (amd/Qwen3.8-Flash-Next-Quark-MXFP4), so the GDN in_proj had to be excluded. An online ptpc_fp8 target on in_proj_qkv / in_proj_z now selects the same layout as an offline PTPC checkpoint: an FP8 QKVZ projection (loaded in BF16, quantized after load) and a BF16 BA projection, whatever the online config says about B/A. Mismatched or non-ptpc targets on QKV/Z still raise. Each per-token FP8 GEMM also launched its own activation quant kernel. The kernels in front of the four quantized GEMMs now emit the FP8 activation and its per-token scale themselves: - GDN out_proj: sigmoid_rmsnorm_quant - QSA o_proj: sigmoid_mul_quant - GDN in_proj_qkvz / QSA qkv_proj: hc_gated_mean_quant in the attention hyper-connection, up to HC_QUANT_ROWS_MAX (1024) rows; the BF16 output is still written for in_proj_ba and the indexer. The quantized value is the BF16-rounded output the unfused path stores, and the scale follows dynamic_per_token_scaled_quant (amax / FP8 max). Nothing changes when the consumer GEMM is not per-token FP8. Co-authored-by: Cursor <[email protected]> * refactor(spec): stage MRoPE positions by batch_dim, not batch_last StagedInput says which axis is the batch (batch_dim, default 0) instead of whether it is last. bind() allocates max_num_seqs at that axis, and stage(), buffer() and the tail repeat narrow along it: one path for every layout, with no branch on it. MRoPE positions are now a [3, max_num_seqs] buffer, viewed per batch as [3, bs] with stride (max_num_seqs, 1). Every reader of the draft's positions indexes them by stride (rows by stride(0), tokens with stride(-1) == 1) or reads only shape[-1]. A batch-1 view is the front of a wider one at the same stride, so buffer() no longer refuses batch_dim=1 roles; a test stages a producer fill of one. * perf(qwen38): enable opt-in GDN fork midstep checkpoints Co-authored-by: Cursor <[email protected]> * perf(qwen38): capture MRoPE MTP draft midsteps Co-authored-by: Cursor <[email protected]> * test(qwen38): initialize draft graph dtype in MRoPE test Co-authored-by: Cursor <[email protected]> * Revert "test(qwen38): initialize draft graph dtype in MRoPE test" This reverts commit f1fbc3c. * Revert "perf(qwen38): capture MRoPE MTP draft midsteps" This reverts commit 1328023. * perf(qwen38): one-wave Triton top-k softmax with fused sigmoid shared gate aiter topkGatingSoftmax spends 7.3 us on a 64x513 router (16 lanes per row, misaligned 64 B loads on the 513-wide rows, 10 serial key/value argmax rounds). Pack the order-preserving bf16 key with (0xFFFF - expert) so each round is one integer max; same ids, tie order and weights (<=1.2e-7), 2.4 us at M<=1024. ATOM_TRITON_TOPK_SOFTMAX=0 restores the aiter kernel. Co-authored-by: Cursor <[email protected]> * perf(qwen38): keep the Triton router top-k opt-in c16 AgentX 1200 s: fused route+psum alone improves ITL p50/p90 and throughput; adding the Triton top-k leaves ITL p50 unchanged and raises ITL/TTFT p90. * perf(qwen38): gfx1250 ReplaySSM verify launch ladder Bit-identical output; Qwen3.8 HV=48 T=4: bs16 20.6->18.7 us, bs48 49.3->43.7 us, bs1 9.3->6.6 us (cold state, CUDA graph). * fix(qwen38): interleave unquantized MTP MoE on gfx1250 * test(qwen38): allow forcing MXFP4 MTP on gfx1250 * Optimize QSA for gfx1250 TDM gather Co-authored-by: Cursor <[email protected]> * Optimize gfx1250 QSA index scoring Co-authored-by: Cursor <[email protected]> * perf(qwen38): gfx1250 ReplaySSM verify launch ladder Bit-identical output; Qwen3.8 HV=48 T=4: bs16 20.6->18.7 us, bs48 49.3->43.7 us, bs1 9.3->6.6 us (cold state, CUDA graph). * perf(qwen38): enable opt-in GDN fork midstep on current main * perf(qwen38): restore gfx1250 TDM sparse GQA for FP8 KV * perf(qwen38): auto-dispatch gfx1250 QSA and MTP * refactor(qwen38): drop the duplicate gfx1250 QSA scorer; give the stacked scorer gfx1250 tiles qsa_select_gfx1250 was the default-on stacked decode scorer again (4 rows x 4 heads in one M=16 operand, keys read once per request) with a different launch shape. Remove it and its test, and give the stacked scorer that launch shape on gfx1250 for BF16 keys: 64-column tiles and about 8 programs per CU split over the row programs. An MTP verify batch (4 rows per request) stays on the stacked kernel past 256 rows on gfx1250, as it did with the removed scorer. Qwen3.8 verify, ~98K context, 12 caches rotated in a CUDA graph, us per call, default -> gfx1250 tiles: bs1 4.78 -> 3.17, bs4 7.27 -> 5.16, bs16 14.84 -> 11.41, bs64 46.03 -> 37.34, bs96 89.13 -> 52.96 (stacked instead of the CUDA-core kernel). Logits match the removed scorer bit for bit at bs 1-128. Co-authored-by: Cursor <[email protected]> * revert(qwen38): keep the GDN fork transfer not midstep-readable The fork-path midstep flip did not fix the three gaps its docstring names (a write path that declines on conditions commit_midstep cannot see, a row index across three sequence lists, a 64 SSM grid midstep_positions does not enforce), each of which can store a findable checkpoint holding the wrong state. It will land separately with those fixes, the doc and test updates and an end-to-end resume run. Co-authored-by: Cursor <[email protected]> * fix(qwen38): gate the gfx1250 ReplaySSM ladder to its measured shape The ladder was measured on Qwen3.8 only (HV=48, V=128, T=4) but applied to every non-KDA multi-token shape on gfx1250. Gate it on that shape, label every measurement with the BV it picks, and pin the rule in a unit test. Qwen3.8 is unchanged; other shapes keep the large-batch config, as before the ladder. Co-authored-by: Cursor <[email protected]> * fix(moe): forward the unquantized gate/up layout to the modular kernel UnquantizedFusedMoEMethod interleaves gate/up weights on gfx1250 but only told fused_moe; the modular (all2all) path got no gate_mode and would read the interleaved weights as separated. Record the layout on the layer when the weights are processed and pass it to both paths (moe_extra_args for the modular kernel), using the runtime arch probe. Co-authored-by: Cursor <[email protected]> * fix(spec): refuse a draft batch that cannot be widened, by name _stage_one repeats the last real row up to running_bs. With zero real rows and running_bs > 0 there is no last row, and with more rows than running_bs the narrow fails; both raised an index error with no context. Assert the bound naming the input and the pass, and test both cases. Co-authored-by: Cursor <[email protected]> * refactor(gfx1250): probe the running GPU for the new runtime dispatch aiter's guidance is get_gfx_runtime() for runtime dispatch and get_gfx() for compile-time codegen. The ReplaySSM ladder and the MTP quantization choice are runtime decisions; use the runtime probe so a GPU_ARCHS build override cannot steer them. Co-authored-by: Cursor <[email protected]> * refactor(qsa): import the gfx1250 sparse GQA path at module level Hoist the function-level imports (torch and the MLA split-K reduce kernel in qsa_gfx1250, qsa_gfx1250 itself in qsa) to module scope. Gluon is already a module-level import elsewhere in ATOM, so this adds no new import-time requirement. Co-authored-by: Cursor <[email protected]> * refactor(qwen38): name why gfx1250 quantizes the MTP head The arch override is a kernel-capability question, not a checkpoint one: aiter has no BF16 fused MoE kernel on gfx1250 (its gfx1250 MoE kernels are MXFP4), and the CK 2-stage BF16 fallback does not build there, so a BF16 MTP head cannot be served unquantized. Keep it apart from _mtp_weights_quantized under a name that says so. No behavior change. Co-authored-by: Cursor <[email protected]> * revert(moe): drop the gfx1250 interleave for unquantized MoE aiter has no BF16 fused MoE kernel on gfx1250, and Qwen3.8's MTP experts are quantized online to MXFP4 there, so UnquantizedFusedMoEMethod's gfx1250 interleave was never reached and could not run if it were. Restore main's version and drop its test. Co-authored-by: Cursor <[email protected]> * feat(gdn): make the fork-slot transfer midstep-readable under ATOM_GDN_STATE_MIDSTEP The fork path's docstring kept it unreadable over three gaps: writes declined on conditions commit_midstep could not see, one row index over three sequence lists, and a 64-token grid midstep_positions did not enforce. All three, and the conv window, were fixed in the write path the PAGE transfer shares (#2591): midstep_target_ok on both ends with raises instead of skips, state_rows, grid snapping with align_midstep_chunk, and a conv_kernel - 1 window. The fork path writes through the same code into an ordinary pool slot that StateSlotPool.publish_midstep files after the forward. Declare it readable when ATOM_GDN_STATE_MIDSTEP=1 and the SSM state is stored at the model dtype (slicing h is exact only then). Rewrite the stale docstring, extend the env doc and the midstep test header to the fork path, and pin the declaration (off by default, grid and conv window when on, unreadable at another state dtype). Co-authored-by: Cursor <[email protected]> * fix(gdn): keep h at the state pool's dtype for interior midstep checkpoints Qwen4Exp stores its recurrent state in fp32 (mamba_ssm_dtype), but the chunk kernel stored h in bf16, so an interior midstep checkpoint held a bf16-rounded state where a forward ending there would store the exact fp32 one. The previous commit's dtype guard therefore left Qwen3.8 unreadable. The recurrence already runs in fp32 registers; only the store narrows. When a forward has an interior target, the layer now asks the chunk kernel for h at the pool's dtype (intermediate_state_dtype), so the slice is the value a shortened forward would store at any state dtype, and drops the guard. chunk_fwd_o casts h to the input dtype before its dot, so the forward's output is unchanged (bit-identical in the new test). FlyDSL prefill, whose snapshots are bf16 only, steps aside for such a forward. The varlen write-path GPU test now runs at bf16 and fp32 pools. Co-authored-by: Cursor <[email protected]> * test(gdn): reach the aiter skip before importing the chunk kernel TestForkMidstep imported fla_ops.chunk (triton) before _builder_cls() could skip on a runner without aiter, so the CPU job failed instead of skipping. Co-authored-by: Cursor <[email protected]> * perf(gdn): snapshot only the interior targets unnarrowed, not all of h Keeping all of h at the fp32 pool's dtype cost 0.2 ms per GDN layer at 16K tokens (+7.4 ms per prefill forward) and showed as +7.5% TTFT p90 in 1200 s AgentX. A checkpoint needs the unnarrowed state only at its own boundary. The chunk kernel now takes (snap_idx, h_snap): at each boundary it reads snap_idx[chunk] and, when set, also stores the fp32 recurrence into that row of h_snap. h stays bf16, so chunk_fwd_o is unchanged (its cast is reverted). interior_state_snapshots builds the table on device once per step for a pool wider than the activation dtype, and write_state_checkpoints reads interior targets through h_rows. Two snapshots cost 0.02 ms per layer at 16K tokens. Pools of the activation dtype, and FlyDSL prefill, keep reading h; the RTP writer passes h_rows through and refuses it on its own path. GPU tests cover the snapshot against a forward stopped there, and the varlen write path at bf16 (h) and fp32 (snapshots) pools. Co-authored-by: Cursor <[email protected]> * refactor(qsa): share the split-K buffers and reduce between both GQA kernels qsa_gfx1250.py copied the portable kernel's split-K partial allocation and its _mla_decode_fwd_reduce_kernel launch. Both now come from qsa_split_k.py (split_k_buffers, reduce_split_k); the two kernels write the same partial layout and differ only in the tile size the reduce is told. Co-authored-by: Cursor <[email protected]> * test(gdn): cover the interior snapshot plan on CPU interior_state_snapshots moves out of fla_ops (which imports triton) into the torch-only gdn_midstep_snapshots.py, so the CPU job can test it: each interior target of midstep_checkpoint_targets gets its own snapshot row at its chunk boundary, end targets take none, and a forward with only end targets plans nothing. The kernel and writer side stays in test_gdn_midstep_state_gpu.py. Co-authored-by: Cursor <[email protected]> * refactor(qsa): keep review constants and imports in one place Co-authored-by: Cursor <[email protected]> * refactor(qwen38): apply final review cleanups Co-authored-by: Cursor <[email protected]> * refactor(gdn): clarify snapshot ownership and routing Co-authored-by: Cursor <[email protected]> * test(moe): initialize HERD flag in recording stub Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Ling Zhang <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: minmengdie <[email protected]>
Three changes, one commit each.
1.
topk_select(end=None)reads no length tensor (fixes ROCm/ATOM#2663)The default
endcame from an 8-entry LRU keyed on the row count. Capturing a ninth row count evicted, and freed, the tensor that an earlier CUDA graph had baked in. Replaying that graph then read reused memory: first wrong draft tokens, then a memory fault.argmax,small_k,plain,decode,stream) now has a full-rows build. It takes each row's length from the runtime width and is handed an empty sentinel (aiter/ops/flydsl/topk/row_lens.py) instead of a tensor, so a captured graph holds no address for one.endis now clamped to the row width. Anendpast the row used to select the zeros that an out-of-bounds buffer load returns.topk_select.pyintoaiter/ops/flydsl/topk/topk_per_row_radix_stream.py, next to the other backends' wrappers.New tests:
test_full_rows_graphs: every launch shape, captured at 10 row counts, with all graphs replayed only after every capture.test_ragged_end_per_backend: an explicit and an over-longendon every launch shape.2.
tgemm.mm(out=)This adds
gemm_a16w16_out, a mutating custom op that returns None, andhipb_mm(out=). They let a caller whose consumer reads one fixed address receive the result there.outdirectly.out, and so does a skinny call whoseoutdtype differs from the input's.outandotyperaisesValueError.test_gemm_a16w16.py -t outchecks, per backend, thatoutis returned, fully written, and matches the same backend'sout=Noneresult.3. One amax floor:
aiter::kAmaxFloorThe dynamic quantizers seeded each group's amax with 1e-6, 1e-8, 1e-10 or 1e-12 depending on the file. As a result, a fused quantizer and its reference disagreed on all-zero groups (graph warmup, padded rows).
kAmaxFloor = 1e-10fromcsrc/include/quant_amax_floor.h. This is the same value as ATOM'sAMAX_FLOOR.amax_floor(default 0, so behaviour is unchanged).Test plan (MI355X, gfx950)
python op_tests/test_gemm_a16w16.py -t out: 13/13 cases (torch ×4, skinny ×2, unflattenable 3-D input, asm ×2, flydsl, opus, triton, hipBLASLt).test_full_rows_graphsandtest_ragged_end_per_backendfromop_tests/test_topk_select.py.end=Noneat widths 2048, 2050 and 129280 (bf16) matchestorch.argmax.op_tests/test_fused_qk_norm_rope_{1way,2way}_perhead.py: gfx942 only, not run here.Known follow-ups (not in this PR)
end=None,small_kcompiles the exact width in, so each distinct width is its own build (12 widths in one 4096 bucket gave 12 builds). It should compile the width in only when it equals the bucket.hipb_mmop schema declares a fresh return tensor, but without=it returnsoutitself.