← Back to Pull requests

[ROCm] Add THD/ragged bf16 (atomic16) backward test coverage #671

Closed
unknown closed this pull request without merging on Aug 04, 2026 04:24 UTC
View on GitHub
unknown unknown commented on Jul 16, 2026 00:55 UTC
Author

Summary

On ROCm/gfx950 the CK fused-attention backward silently corrupts dQ for THD/ragged (packed / document-masked) attention on the default bf16 dq-accumulation path (NVTE_CK_IS_V3_ATOMIC_FP32=0). Forward, dK and dV are correct.

Root cause


build_bwd_fmha_args allocates the dq_acc scratch as fp32-packed (nsplits, H, total_q, d_qk) with batch_stride_dq_acc = 0. That matches the fp32 dq_convert post-kernel, but the bf16 dq_shuffle post-kernel expects a per-segment padded layout — with batch_stride=0 every ragged segment past cu_seqlens offset 0 is written to the offset-0 slot, so dQ is correct only for the first segment and garbage for the rest.

Fix


When the v3 asm path actually runs — probed via ck_attn_bwd_uses_v3 (added in #662) — switch dq_acc to AITER's per-segment bf16 layout (nsplits, B, H, pad16(s_q), 128) with matching stride/nhead/batch/split strides. The v2/fallback path and non-ragged/atomic_fp32=1 keep the fp32-packed layout. fused_attn_ck.cpp sizes the scratch to hold either layout (the layout choice needs a GPU probe that must not run in the workspace-sizing pass).

Tests


  • Add an equal-dim-128 bf16 GQA self-attn config (BSHD + THD/RAGGED) to test_fused_attn.py. Previously there was no symmetric 128/128 THD backward coverage (only asymmetric 128/64) — exactly the llama3 shape.

  • Add an NVTE_CK_IS_V3_ATOMIC_FP32=0 (atomic16 / dq_shuffle) CI run of the THD backward tests in ci/jax.sh. The default fp32 path never exercised the bf16 dq_acc path.
  • Verification (MI355X / gfx950)


    TE THD padding_causal backward vs a pure-JAX block-diagonal reference:
  • dQ cosine 0.0036 → 1.0000 with atomic_fp32=0; per-segment all correct across [256], [100,80,76], [128,128], [64×4], [200,56], for both the v3 (dq_shuffle) and v2 paths.

  • Still uses the fast bwd_hd128_dq_shuffle_group kernel (fix is on the fast path, not a fallback).

  • atomic_fp32=1 unchanged; end-to-end MaxText llama3.1-8B block-diagonal THD packing converges to eval-loss 3.3 (previously stalled ~6.1 and NaN'd).
  • Builds on the V3 API check mechanism from #662. Supersedes #657 (which targeted an earlier base before #662).

    🤖 Generated with Claude Code

    Diff: 287 lines (+215 / -72) across 3 files Reviewer: wangye805 Review duration: 27568m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 287 lines diff across 3 files
    0.40
    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%
    56%
    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.339
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #671"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 17.2% · Safe to merge
    17.2%