[TE] CK small-seq: fix index overflow, empty-KV sequences and LSE over-read #785
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 349 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.350
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #785"
general
weight: 0.35
Micky774
Description
The max-logit work in #755 exposed a permuted LSE in the opt-in CK small-seq path (
NVTE_FUSED_ATTN_CK_SMALLSEQ=1, #625), which #784 fixes. Reviewing the small-seq kernels for #784 turned up three more edge cases, independent of it. #625's tests never hit them: tensors stayed far below 2^31 elements and every sequence had keys.1. Index overflow: the backward wrote dQ/dK/dV through 32-bit offsets, so past 2^31 elements per tensor (e.g. over 262k tokens with 32 heads of 256) it wrote out of bounds. It now uses a 64-bit base per sequence and head.
2. Sequences without keys: a THD sequence with queries but no keys gave those queries a NaN output: #625 set their LSE to -inf but still divided by their zero softmax sum. The clamped K/V loads also read one row past K and V when that sequence came last. Those queries now get a zero output and gradient.
3. LSE over-read: the backward indexed the LSE of rows past each sequence's end, which for the last sequence can lie past the end of the buffer. This was latent, since the compiled kernels only loaded it for unmasked rows. The row is now clamped to the last valid one.
No performance cost: on gfx950 the small-seq forward is up to 4% faster and the backward about 1% faster.
Type of change
Changes
attn_bwd_mfma_16x16.h: 64-bit dQ/dK/dV bases, clamped LSE row, sequences without keys skipped.attn_fwd_mfma_16x16.h: zero weights for rows without keys; V rows past the sequence zeroed instead of clamped.fused_attn_ck.cpp: comments that the small-seq backward relies on the dQ memset for sequences without keys.test_ck_smallseq_empty_kvandtest_ck_smallseq_largefail before and pass after (gfx950). They check outputs and gradients, not the saved LSE, whose layout #784 fixes. The large one needs about 40 GiB of device memory and skips with less than 48 GiB free.Checklist: