You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Triton/Gluon] KDA: add the chunk_delta_attn backward pass - #6498
chunk_kimi_delta_attn is now differentiable w.r.t. q, k, v, g, beta, A_log,
dt_bias and initial_state. When an input requires grad it runs under an
autograd function that saves only the inputs; the backward recomputes the
default pipeline's intermediates (fla's disable_recompute=False), whichever
path ran the forward.
- _triton_kernels/kimi_delta_attn/chunk_bwd.py: backward kernels after fla's
chunk_kda_bwd (dAv, dhu, WY dq/dk/dg, intra, reverse gate cumsum + gate
activation, l2norm, beta sigmoid), launched through fast_launch
- With too few states to fill the GPU, the recomputed forward recurrence and
dhu share one launch; dhu reads qg from the recompute
- bwd_intra finishes the l2norm and dbeta (beta sigmoid included) in its
epilogue with the in-kernel l2norm, no GVA and K <= 128
- dhu, the fused recurrence and bwd_intra renumber program ids with
remap_xcd so programs sharing loads stay on one XCD
- Launch tiles published for gfx950 under CHUNK_DELTA_ATTN
- out / state_cache stay inference-only and are rejected with grad
- Tests: gradients vs autograd through the fp32 token recurrence
(FlashKDA-eligible, safe_gate, softplus + GVA, K=256, precomputed gate,
varlen, V-first state, wide recurrences), FlashKDA vs default forward,
partial requires_grad, and parity with fla's chunk_kda
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm
vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all
All standard extended tests (excludes ci:atom_full)
Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6498 --add-label <label>
One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.
PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.
- chunk_delta_attn.py: main no longer packs q, k, v, g in the wrapper
(gfx1250 FlashKDA reads them at their own stride). The backward assumes
contiguous saved inputs, so pack them on the autograd path only.
- chunk_bwd.py: pid_preprocessing moved to _triton_kernels/common/ (#6505).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Fix int32 overflow in _fwd_h_body: token offsets scaled by H*K and the
gate index wrapped past 2**31 / (H*K) tokens (dq, dk, dg wrong after
token 262144 at H=64, K=128). Chunk starts now go into int64 pointers.
- Give each backward kernel a config-aware repr (make_kernel_repr).
- Move the L2 norm backward device helper to _triton_kernels/common/l2norm.py.
- Share the forward preparation (activations, gate cumsum, intra) between
the forward and the backward recompute: chunk_delta_attn_fwd_prepare.
- Add bench_chunk_delta_attn_bwd.py.
- Test: give the gradient tensors an explicit dtype.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Micky774 Can you address the lint errors, copilot review and also review from @omuhamma?
Updated now to account for all review comments thus far. Note that a couple of the copilot ones are out of scope or inapplicable, but I've addressed the remaining ones.
When only state_cache requires grad, this tuple excludes it, so the inference-only guard is skipped and the cache is updated without autograd tracking. Reject gradient-bearing state_cache and out buffers before this check.
The fixed eight-XCD count misses supported four- and six-XCD devices, and _num_cus repeats an existing device query. Use get_num_xcds and get_num_sms from utils/device_info.py with the input device selected at launch time, as required by the shared-helper rule in aiter/ops/triton/README.md:25-28.
Cache chunk indices for both forward and backward sizes
For FlashKDA varlen calls with chunk_size=None, forward requests size 32 and backward requests size 64, so the single-entry prepare_chunk_indices cache misses on every pass and repeats its .tolist() host sync. Keep a bounded cache for both (cu_seqlens, chunk_size) keys so training can reuse the indices after warmup.
Add op_tests/test_kda_chunk_bwd.py (aiter-op-test structure): K3 shapes
(H=96/48/12 x 128) graded against an fp32 chunked torch reference adapted
from #8739, with a us/TFLOPS/TB/s summary table. Add 96-head cases to the
Co-authored-by: Sealeen Zhang <[email protected]>
#6498 pytest suite.
cursorBot
pushed a commit
that referenced
this pull request
Nov 26, 2026
fast_launch moved to aiter/ops/triton/utils in #8061; the #6498 import path
no longer exists on main (also fixes ruff I001).
Co-authored-by: Sealeen Zhang <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
chunk_kimi_delta_attndifferentiable w.r.t.q,k,v,g,beta,A_log,dt_biasandinitial_state.Changes
_triton_kernels/kimi_delta_attn/chunk_bwd.py:chunk_kda_bwd.chunk_delta_attn_bwdrecomputes the default pipeline's intermediates from the saved inputs, so the forward can still take FlashKDA.dhushare one launch.bwd_intrafolds the l2norm and beta-sigmoid backward into its epilogue when it can.remap_xcdis applied to the recurrence and intra kernels.chunk_delta_attn/DEFAULT.json, with fallbacks in code for other archs.out/state_cacheremain inference-only and raise when grad is required.disable_recomputeis accepted and ignored.Tests
test_chunk_delta_attn_bwd.pychecks gradients against autograd through the fp32 token recurrence. It covers:safe_gate, softplus with GVA, K=256, precomputed gate, varlen, V-first state, and wide recurrences.requires_grad.chunk_kda.All 146 KDA tests pass on MI355X (1 skipped).
Perf (MI355X, training fwd + bwd, µs)
chunk_kda🤖 Generated with Claude Code