Repository navigation
[FlyDSL] Add fused QSA sparse decode for gfx950 - #6670
Conversation
Qwen sparse attention (QSA) decode and speculative verify straight from the KV pool: each query row's top-k positions are mapped to pool slots through req_to_token inside the kernel, so there is no gather pass and no packed scratch, and each row's selection is split across CTAs with a separate merge kernel. BF16 Q with BF16 or FP8 e4m3fn KV, head_dim 256, GQA group up to 16. CUDA-graph safe given a caller-provided workspace. Moved from SGLang (sglang.kernels.ops.attention.qsa_flydsl) so the kernel lives next to the other FlyDSL attention kernels. op_tests/test_flydsl_qsa_sparse_decode.py: pytest correctness cases (masking, small top-k, index dtypes, >int32 pool offsets, CUDA-graph replay, workspace sizing, operand checks) and a perf sweep over Qwen3.8 TP1/TP8 shapes. Co-Authored-By: Claude <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
fsx950223
left a comment
There was a problem hiding this comment.
The existing 18 correctness tests pass on gfx950 with the pinned FlyDSL 0.3.4.1. Additional tests with holes in the selection and GQA groups 1, 7, and 16 also pass. However, the public wrapper has three reproducible issues involving workspace memory corruption, GPU device selection/caching, and accepting CPU inputs. Please address the inline findings before merging.
The failed MI35X CI shard stopped at pytest tests because that directory was missing, before running the operator tests; it did not exercise this new operator.
|
One non-blocking test-cost question: est_slot_offsets_beyond_int32 allocates two FP8 tensors with approximately 4.2 million slots and shape [num_slots, 2, 256]. This is about 2 GiB per tensor, or approximately 4 GiB total before the other inputs. Could you confirm that this cost is acceptable in the standard gfx950 op-test shard? If not, should this case be gated or marked as a targeted/slow test while retaining the 64-bit offset coverage? |
Motivation
Qwen3.8 decodes with Qwen sparse attention (QSA): an indexer picks up to 2051 KV positions per query row, then attention runs over that selection only.
This PR adds a fused FlyDSL kernel for gfx950 that reads the selected KV straight from the KV pool and splits each row across CTAs. It was developed in SGLang and moves here so it lives with the other FlyDSL attention kernels. SGLang will call it through
aiter.ops.flydsl.qsa_sparse_decode.Technical Details
API (
aiter/ops/flydsl/qsa_sparse_decode.py)0 <= pos < seq_lens[row], and maps to slotreq_to_token[row_req_pool_indices[row], pos]. Rows with no valid entry produce zeros.can_use_flydsl_qsa_sparse_decode(q, k, v)reports whether the operands are supported: gfx950, head_dim 256, GQA group <= 16, contiguous pool.recommended_num_splits(rows, Hkv, topk, device)picks the split count that fills the GPU at that batch.workspace_partials(max_rows, ...)sizes one workspace for every batch up tomax_rows. A CUDA-graph caller allocates once at its captured maximum and reuses it, since graphs keep raw pointers.Kernels (
aiter/ops/flydsl/kernels/qsa/)sparse_decode_attn.py: one CTA per (row, KV head, KV split). Four waves take 16-token tiles and each runs its own online softmax; the waves merge in LDS once, at the end.mfma_f32_16x16x32_bf16with tokens on M and query heads on N. The K rows are read straight from the pool.mfma_f32_16x16x16bf16_1k, so P never leaves registers.ds_read_b64_tr_b16.sparse_decode_reduce.py: merges the per-split partials (max, denominator, normalized output). It is skipped whennum_splits == 1; the attention kernel then writes the output directly.Test Plan
op_tests/test_flydsl_qsa_sparse_decode.py, following the op_test standard. Runningpython op_tests/test_flydsl_qsa_sparse_decode.pyruns the correctness checks first, then the perf sweep:-1padding, an entry atseq_len, an empty row, NaN in an unreferenced slotValueErroron bad argumentsTest Result
MI355X (gfx950). All 18 pytest cases pass; every sweep row has
err0.The op is gfx950-only; on other archs
main()logs and skips, and the pytest cases are skipped.