← Back to Pull requests

[TE] CK small-seq: fix index overflow, empty-KV sequences and LSE over-read #785

Closed
unknown closed this pull request without merging on Nov 04, 2026 15:21 UTC
View on GitHub
unknown unknown commented on Oct 30, 2026 14:31 UTC
Author

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

  • Documentation change (change only to the documentation, either a fix or a new content)

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Infra/Build change

  • Code refactoring
  • 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.

  • Tests: test_ck_smallseq_empty_kv and test_ck_smallseq_large fail 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:

  • I have read and followed the contributing guidelines

  • The functionality is complete

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation

  • My changes generate no new warnings

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes
  • Diff: 349 lines (+261 / -88) across 4 files Reviewer: Micky774 Review duration: 7249m
    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
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%