Repository navigation
[FlyDSL] [gfx1250] FMHA prefill m32x8: skip query tiles past a varlen sequence's end - #7098
Conversation
… sequence's end The varlen launch sizes grid.x from max_seqlen_q, so every sequence of the batch gets the longest sequence's tile count. The entry only kept an empty sequence out of the core (q_len == 0 or kv_len == 0). A shorter sequence's trailing tiles, which own no packed query row, went through the full core: `_wg_kv_span` clamps their last row to the sequence's last query, so each streamed the whole KV band with every row masked and stored nothing. Prefix-cached agentic prefill batches mix 1-16 token turns (tool results) with turns of thousands of tokens, and launched 5.7-8.6x the tiles they need. Such a tile now skips the core like an empty sequence does; the condition is uniform across the workgroup's waves. Outputs and LSE are bit-identical to the current kernel. Adds two skewed varlen shapes to op_tests/test_mha_flydsl.py.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
… sequence's end (#7098 on the Qwen branch) The varlen launch sizes grid.x from max_seqlen_q, so every sequence of the batch gets the longest sequence's tile count. The entry only kept an empty sequence out of the core (q_len == 0 or kv_len == 0). A shorter sequence's trailing tiles, which own no packed query row, went through the full core: `_wg_kv_span` clamps their last row to the sequence's last query, so each streamed the whole KV band with every row masked and stored nothing. Prefix-cached agentic prefill batches mix 1-16 token turns (tool results) with turns of thousands of tokens, and launched 5.7-8.6x the tiles they need. Such a tile now skips the core like an empty sequence does; the condition is uniform across the workgroup's waves. Outputs and LSE are bit-identical to the current kernel. Adds two skewed varlen shapes to op_tests/test_mha_flydsl.py on main (#7098); this branch version carries the kernel change only.
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 |
…arlen sequence's end The a8w8 varlen launch sizes grid.x from max_seqlen_q, as the a16w16 one does. A shorter sequence's trailing tiles own no packed query row, but they streamed the whole KV band with every row masked and stored nothing. Such a tile now skips the core, as in the a16w16 kernel. In both kernels, a tile with no row also skips the kv_len == 0 zero fill. Before, it ran the zero fill with every store masked off. Outputs and LSE are bit-identical to the current kernels (fp8 and bf16, causal and not, 6 shapes). gfx1250, 16 q / 2 kv heads, d 256, fp8, causal, median of 100 launches: - 15 x 8-token turns + 1 x 4096, ~20k-token prefixes: 5538.6 -> 623.5 us - 8 turns of 1-2048 tokens, 2k-90k prefixes: 2566.3 -> 605.2 us - 4 x 2048 (no skew): 77.8 -> 78.4 us Adds a skewed varlen shape with seqlen_k == 0 to op_tests/test_mha_flydsl.py.
e89add1 to
c97ba47
Compare
… sequence's end (#7098) * [FlyDSL] [gfx1250] FMHA prefill m32x8: skip query tiles past a varlen sequence's end The varlen launch sizes grid.x from max_seqlen_q, so every sequence of the batch gets the longest sequence's tile count. The entry only kept an empty sequence out of the core (q_len == 0 or kv_len == 0). A shorter sequence's trailing tiles, which own no packed query row, went through the full core: `_wg_kv_span` clamps their last row to the sequence's last query, so each streamed the whole KV band with every row masked and stored nothing. Prefix-cached agentic prefill batches mix 1-16 token turns (tool results) with turns of thousands of tokens, and launched 5.7-8.6x the tiles they need. Such a tile now skips the core like an empty sequence does; the condition is uniform across the workgroup's waves. Outputs and LSE are bit-identical to the current kernel. Adds two skewed varlen shapes to op_tests/test_mha_flydsl.py. * [FlyDSL] [gfx1250] FMHA prefill a8w8 m32x8: skip query tiles past a varlen sequence's end The a8w8 varlen launch sizes grid.x from max_seqlen_q, as the a16w16 one does. A shorter sequence's trailing tiles own no packed query row, but they streamed the whole KV band with every row masked and stored nothing. Such a tile now skips the core, as in the a16w16 kernel. In both kernels, a tile with no row also skips the kv_len == 0 zero fill. Before, it ran the zero fill with every store masked off. Outputs and LSE are bit-identical to the current kernels (fp8 and bf16, causal and not, 6 shapes). gfx1250, 16 q / 2 kv heads, d 256, fp8, causal, median of 100 launches: - 15 x 8-token turns + 1 x 4096, ~20k-token prefixes: 5538.6 -> 623.5 us - 8 turns of 1-2048 tokens, 2k-90k prefixes: 2566.3 -> 605.2 us - 4 x 2048 (no skew): 77.8 -> 78.4 us Adds a skewed varlen shape with seqlen_k == 0 to op_tests/test_mha_flydsl.py.
Problem
The varlen kernel sets
grid.xfrommax_seqlen_q. Each sequence in the batch gets the same number of tiles as the longest sequence.A short sequence has tiles that start after its last query row. The kernel does not stop these tiles. Each of these tiles reads all the KV of its sequence. The masks remove all the results, and the tile writes no output.
Prefix-cached agentic prefill has this problem. One batch can have tool-result turns of 1 to 16 tokens and turns of 4,000 tokens. For these batches, the kernel launches 5.7 to 8.6 times the necessary tiles.
Fix
A tile that starts after the last packed query row of its sequence does not enter the core. The kernel already skips the core in the same location for an empty sequence. All waves of the workgroup get the same result, so they skip together.
Results
gfx1250, bf16, 16 query heads, 2 KV heads, head dim 256, one call. A1 and A2 are two prefill steps from a Qwen3.5 MLPerf agentic run (c=2048, DP attention).
op_tests/test_mha_flydsl.py -l thd -dq bf16 -k flydsl: 256 of 256 cases pass, with two new skewed varlen shapes.