Repository navigation
Conversation
…educe - A sequence with no KV segment (kv_len 0, e.g. a padded decode slot) loads an all -inf maximum in reduce_segments - exp2(-inf - -inf) is NaN, so the exp sum and the whole output row came out NaN instead of 0 - Map a -inf maximum to 0 so the weights and the exp sum are 0 and the existing safe divide stores 0 - Applies to the single-tile and the segment-block merge paths; rows with a segment are unchanged - Clamp tiles_per_segment to at least 1: for kv_len 0 it was 0, and the segment count divided by it - Add a decode test with one kv_len 0 row (G=8 and G=4, head size 64 and 256, sinks on/off, sliding window)
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
- The test only runs the Triton reduce, which gfx942 also uses, so MI300X CI should cover it - Not run on gfx942 here (no MI300X); the body says so
|
Closing: the padded-row case it fixes is not hit on the Kimi-K3/K3.1 serving paths. |
|
Reopening: the Kimi-K3 DSpark draft runs on unified_attention with #7088's length-aware split, and CUDA-graph padded decode slots have kv_len 0, so this keeps those rows at 0 instead of NaN. |
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
Summary
reduce_segmentskernel of unified attention stored NaN for a row withkv_len0 (a padded decode slot).Motivation
kv_len0 has no KV segment, so the reduce loadssegm_maxas all-inf.exp2(-inf - -inf)is NaN, so the exp sum and the whole output row are NaN.main: 512 of 512 values of the empty row are NaN (8 Q / 1 KV decode, 1M bound, sinks on and off).tiles_per_segmentis 0 for such a row, so the segment count divided by 0 (undefined in the IR).Changes
aiter/ops/triton/_triton_kernels/attention/unified_attention.py,reduce_segments-infoverall maximum becomes 0 in the single-tile and the segment-block merge pathstiles_per_segmentis clamped to at least 1 in the sliding-window and the plain branchkv_len0 then gets 0 segments without dividing by 0op_tests/triton_tests/attention/test_unified_attention.py: newtest_triton_unified_attn_3d_empty_row_is_zeroexp2(-inf - -inf)Performance (if applicable)
mainfc623e7458; after: this branchfb511b99ebbackend="triton", decode, bf16 Q, fp8 KV, head size 64, block size 128, 1M boundtriton.testing.do_bench(50 warmup, 300 rep); 3 alternating runs per revision, separate JIT cachesTesting
Documentation
Dependencies
Breaking Changes
kv_len0 row stores 0 instead of NaN; no caller is known to rely on the NaN.PR Self-Review
Reviewed revision
fb511b99eba5c53207b3201e45f27f19a3da9c5aBehavior and intent
kv_len0 row of the Triton unified attention 3D path stores 0 instead of NaN. Other rows are unchanged.Validation and unverified scope
-k empty_row_is_zero: 24 passed with this changemain's kernel (the empty row is not zero)op_tests/triton_tests/attention/test_unified_attention.py: 2818 passed, 2963 skipped, 0 failedreduce_segments_gluon, split rebalance): same NaN for akv_len0 rowPR-specific question
Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents
unsupported inputs from reaching it?
reduce_segmentsruns after the 3D kernel on every arch whose decode picks the Triton reduce-infmaximumChanged op tests
op_tests/triton_tests/attention/test_unified_attention.py: newtest_triton_unified_attn_3d_empty_row_is_zerokv_len0 row; 8 Q / 1 KV, 64 Q / 8 KV and 4 Q / 1 KVkv_len0 row on the Triton reduceRelated: #7088