Skip to content

[FlyDSL] [MI350X] causal conv1d backward support for Kimi-K3 - #8726

Open
huizzhan wants to merge 8 commits into
mainfrom
cursor/mi350-causal-conv1d-bwd-a20d
Open

huizzhan wants to merge 8 commits into
mainfrom
cursor/mi350-causal-conv1d-bwd-a20d

Conversation

@huizzhan

@huizzhan huizzhan commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add the training backward of the varlen causal conv1d with split q/k/v output: causal_conv1d_split_qkv_bwd_triton_fn. It gives dx, dweight (the depthwise conv weight gradient), dbias and dinitial_states. The target is the Kimi-K3 KDA short conv on MI350X / MI355X (gfx950). One backend: Triton.

Requirements: ZhangDanyang-AMD/Lumen#35 (row "causal conv1d backward": depthwise [12288, 1, 4] for each of q, k and v, "Needs Conv1D wgrad").

Motivation

main has only forward and update (inference) kernels for causal conv1d. Lumen issue #35 lists the conv1d weight gradient as a P0 gap for Kimi-K3 training. The chunk-KDA backward in #6498 does not differentiate the conv weight.

Changes

  • aiter/ops/triton/gated_delta_net/causal_conv1d_bwd.py: new public wrapper causal_conv1d_split_qkv_bwd_triton_fn. It uses the layout of causal_conv1d_split_qkv_triton_tile_fn ([Triton/Gluon] Updates to causal_conv1d_split_qkv kernel #7028): x is [dim, cu_seqlen] with channels [Q | K | V], and the gradients are dq, dk: [cu_seqlen, k_dim], dv: [cu_seqlen, v_dim]. It accepts the same varlen arguments: query_start_loc, cache_indices, has_initial_state, pad_slot_id, and metadata (a CausalConvPrefillMetadata or a nums_dict schedule). A prefilled nums_dict needs no host sync, so the call can be captured in a graph. dq, dk and dv must share one dtype.
  • aiter/ops/triton/_triton_kernels/gated_delta_net/prefill/causal_conv1d_bwd_split_qkv.py: new kernel. Each program handles one (sequence, chunk) from the existing chunk schedule and one block of BLOCK_N channels. It walks the chunk one token row at a time and keeps the last width - 1 rows of x and of the pre-activation gradient in registers, so x and the output gradient are read once and dx is written once. It recomputes the pre-activation from x, so the forward saves nothing. It writes per-chunk fp32 partials of dweight and dbias, and the host sums them in a fixed order. This makes the result deterministic, with no atomics. Width 2, 3 and 4. SiLU or no activation. Optional bias and initial states. Padded sequences get zero gradients.
  • aiter/ops/triton/configs/gfx950/triton/conv/causal_conv1d_split_qkv_bwd/DEFAULT.json: the gfx950 launch config: BLOCK_M 64, BLOCK_N 128, 1 warp. It comes from a sweep of 45 configs on the benchmark cases; on every case it is within 3% of the best config for that case. Other archs use the wrapper default, which has the same values.
  • aiter/ops/triton/gated_delta_net/__init__.py: export the new wrapper.
  • op_tests/triton_tests/gated_delta_net/test_causal_conv1d_bwd.py: tests against an fp32 torch autograd reference. This replaces the skipped skeleton from the first commit.
  • op_tests/op_benchmarks/triton/bench_causal_conv1d_bwd.py: benchmark with Kimi-K3 TP8 and TP1 cases (RotatingBufferBench, CUDA graph).

No existing code path changes.

FlyDSL version

4faa6bc adds causal_conv1d_split_qkv_bwd_flydsl_fn (aiter/ops/flydsl/causal_conv1d_bwd_flydsl.py, kernel in aiter/ops/flydsl/kernels/causal_conv1d_bwd.py), and 794546a speeds it up. It takes the same arguments and returns the same results as the Triton function, which stays in this PR for now. Each thread owns one or two adjacent channels and walks its chunk in a runtime loop over groups of prefetch rows, loading the next group before the current one is used (50-62 VGPRs, no spills). The SiLU gradient uses the exp2 (afn) + rcp sigmoid of the other FlyDSL kernels. It keeps the Triton semantics: varlen chunk schedule (CausalConvPrefillMetadata or nums_dict), pad slots with NaN-safe zero gradients, int64 offsets, tail dx zeroed in the kernel, and fp32 per-chunk dweight/dbias partials summed in a fixed order (deterministic, no atomics, CUDA-graph safe). The defaults (block_m 64, 64 threads, prefetch 4, 2 channels per thread) are preliminary.

op_tests/test_flydsl_causal_conv1d_bwd.py runs the cases of the Triton test against the same fp32 autograd reference, plus odd q/k/v splits, 1 and 2 channels per thread, and CUDA-graph capture and replay: 46/46 pass on MI350X (gfx950, flydsl 0.5.3) at 794546a, with the tolerances of 4faa6bc. The Triton test passed 42/42 at 4faa6bc.

Preliminary performance of 794546a, one short run on one idle MI350X (RotatingBufferBench, CUDA graph, 200 calls per graph, 5 replays), Triton and FlyDSL in the same run, us:

Workload Triton 21100d0 FlyDSL 794546a FlyDSL vs Triton
TP8, 1 x 8192 92 72 -22%
TP8, 2 x 4096 93 79 -15%
TP8, varlen 8 x ~2048 159 136 -14%
TP8, 1 x 32768 316 274 -13%
TP1, 1 x 4096 316 272 -14%
TP1, 1 x 8192 607 535 -12%

Pending: a formal two-round A/B against Triton 21100d0 and FlyDSL 4faa6bc, the torch eager comparison, a final config sweep, and the error of the fast sigmoid against the fp32 reference for FlyDSL and Triton. The formal numbers of the first FlyDSL version follow.

4faa6bc (first FlyDSL version, unrolled loop) against Triton on one idle MI350X, bench_causal_conv1d_bwd.py method (RotatingBufferBench, CUDA graph), two alternating rounds, means in us (the rounds differ by less than 1%). The torch column is the eager torch.autograd.grad backward described under Performance, timed with eager launches, where FlyDSL and Triton take the times in parentheses.

Workload Triton 21100d0 FlyDSL 4faa6bc FlyDSL vs Triton torch backward, eager (Triton / FlyDSL eager)
TP8, 1 x 8192 95.7 99.5 +4.0% 1313 (97.7 / 97.2)
TP8, 2 x 4096 96.2 100.1 +4.0% 1334 (98.8 / 97.2)
TP8, varlen 8 x ~2048 158.9 180.4 +13.5% — (155.0 / 171.8)
TP8, 1 x 32768 319.9 381.3 +19.2% 5035 (274.2 / 307.4)
TP1, 1 x 4096 316.8 377.4 +19.1% 5134 (269.6 / 313.2)
TP1, 1 x 8192 613.0 758.7 +23.8% 9972 (505.2 / 646.1)

4faa6bc matched Triton on the TP8 short-sequence cases and was 13-24% slower on the larger ones: its unrolled token loop needed 164 VGPRs at block_m 32 and 294 with 146 SGPR spills at block_m 64, and each row spent most of its ~325 instructions on the IEEE exp expansion, an IEEE divide and 64-bit position compares. 794546a addresses all three.

Performance (if applicable)

Measured on one idle MI350X (gfx950) in a ROCm 7.2.4 container (torch 2.10.0, triton 3.6.0). Lumen issue #35 gives no performance target for this op.

bench_causal_conv1d_bwd.py (RotatingBufferBench, CUDA graph). Before is the first version of this PR (cf3f8fd, one tile per program that recomputes the pre-activation for every tap), after is 0db0348. Two rounds, before and after alternating on the same GPU; the table gives the mean of the two rounds, which differ by less than 1%. TB/s counts x and the output gradient read once and dx written once.

Hardware Workload/configuration Before After Change
MI350X (gfx950) TP8, 1 x 8192, x row stride 6288 436.8 us (0.52 TB/s) 94.4 us (2.40 TB/s) 4.6x faster
MI350X (gfx950) TP8, 2 x 4096, x row stride 6288 437.2 us 95.2 us 4.6x faster
MI350X (gfx950) TP8, varlen 8 x ~2048, x row stride 4608 779.0 us 156.6 us 5.0x faster
MI350X (gfx950) TP8, 1 x 32768, x row stride 4608 1699.7 us 311.2 us 5.5x faster
MI350X (gfx950) TP1, 1 x 4096, x row stride 36864 1688.2 us 308.8 us 5.5x faster
MI350X (gfx950) TP1, 1 x 8192, x row stride 36864 3364.2 us (0.54 TB/s) 593.9 us (3.05 TB/s) 5.7x faster

The review fixes in 21100d0 (int64 channel offsets, NaN-safe padded sequences, tail dx fill) were timed the same way against 0db0348: every case is within 0.5% (two alternating rounds, means in us):

Hardware Workload/configuration 0db0348 21100d0 Change
MI350X (gfx950) TP8, 1 x 8192 93.8 93.6 -0.3%
MI350X (gfx950) TP8, 2 x 4096 94.0 93.8 -0.2%
MI350X (gfx950) TP8, varlen 8 x ~2048 154.7 154.6 -0.1%
MI350X (gfx950) TP8, 1 x 32768 308.2 308.2 0.0%
MI350X (gfx950) TP1, 1 x 4096 305.8 306.4 +0.2%
MI350X (gfx950) TP1, 1 x 8192 589.8 589.1 -0.1%

Bandwidth context: at the TP8 1 x 8192 size (75 MB per tensor), torch itself reaches 2.74 TB/s for a read-read-write elementwise op and 3.05 TB/s for a contiguous copy on this GPU (triton.testing.do_bench); the main kernel of this op runs at about 2.66 TB/s there, and at about 4.0 TB/s on the larger cases, where the torch copies reach 4.1-4.3 TB/s. Splitting each chunk into 2-4 token segments that advance together made the TP8 1 x 8192 case 3-4% faster but the TP1 1 x 8192 and TP8 1 x 32768 cases about 1% slower, so it is not used.

Against torch, on the same GPU, at 21100d0, with eager launches timed by CUDA events over 4 rotating inputs (not CUDA graphs, so these numbers differ from the tables above). The torch reference is a bf16 depthwise F.conv1d (groups=dim, causal padding) plus SiLU. "torch backward" is torch.autograd.grad for x and the weight with the forward already done. "torch wgrad only" is aten.convolution_backward with only the weight gradient. The varlen case is left out: torch needs a loop over the sequences.

Workload This op (dx + dweight) torch backward torch wgrad only
TP8, 1 x 8192 97.1 us 1312 us (13.5x) 602 us
TP8, 2 x 4096 97.3 us 1333 us (13.7x) 638 us
TP8, 1 x 32768 261.1 us 5018 us (19.2x) 2186 us
TP1, 1 x 4096 259.1 us 5107 us (19.7x) 2388 us
TP1, 1 x 8192 468.3 us 9985 us (21.3x) 4537 us

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

0db0348

Behavior and intent

This PR adds a new op and changes no existing behavior. Before this PR, AITER had only the forward and the decode update of the causal conv1d. A training step of Kimi-K3 KDA cannot get the gradients of the q, k and v short convs (depthwise weight [12288, 1, 4] each, Lumen issue #35). Lumen must use a slow eager path for them. The new causal_conv1d_split_qkv_bwd_triton_fn gives dx, dweight, dbias and dinitial_states in one launch, in the [Q | K | V] layout of the forward. The existing forward, update and prefill paths, and their configs, do not change.

Validation and unverified scope

Done on MI350X (gfx950), ROCm 7.2.4 container with torch 2.10.0 and triton 3.6.0:

  • All 42 tests of test_causal_conv1d_bwd.py pass at 21100d0, including the Kimi-K3 TP8 long sequences and the TP1 cases (12288 channels per tensor). The tests added for the three review findings fail on 0db0348: NaN in dx with NaN in padded sequences, nonzero tail dx with a reused nums_dict, and a GPU memory fault that aborts the process with the large channel stride. 0db0348 passed its 40 tests, and the first version (cf3f8fd) its 39, on the same GPU.
  • bench_causal_conv1d_bwd.py before and after, a config sweep for the gfx950 config, and a torch autograd comparison (see Performance).
  • ruff check (0.16.0) and black --check (26.10.1) pass on the changed files.

Not verified:

  • Only gfx950 was run. Other archs use the wrapper default config.
  • No end-to-end Kimi-K3 training step.

PR-specific question

Q: Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

A: The only config change is the new file aiter/ops/triton/configs/gfx950/triton/conv/causal_conv1d_split_qkv_bwd/DEFAULT.json, family CAUSAL_CONV1D_SPLIT_QKV_BWD. It has one key, "any". Only _bwd_config() in the new aiter/ops/triton/gated_delta_net/causal_conv1d_bwd.py reads it, so only calls of causal_conv1d_split_qkv_bwd_triton_fn on gfx950 use it. No existing config file changes (git diff --stat origin/main shows the new file only), and no other loader reads this family name (grep -rn CAUSAL_CONV1D_SPLIT_QKV_BWD aiter/ finds only the new wrapper). So every existing shape keeps its previous selection. The forward family CAUSAL_CONV1D_SPLIT_QKV is a different directory and does not change.

Changed op tests

  • op_tests/triton_tests/gated_delta_net/test_causal_conv1d_bwd.py (new): compares dx, dweight, dbias and dinitial_states with an fp32 autograd reference. It covers Kimi-K3 TP8 (1536 channels per tensor, x row stride 6288 or 4608) and TP1 (12288 channels per tensor), varlen batches, zero-length sequences, pad slots (also with NaN in the x and gradient rows of the padded sequences), initial states, widths 2/3/4, activations, bias, unaligned q/k/v splits, token-contiguous x and gradients (no unit channel stride), a token-contiguous x in a [36864, 65536] buffer whose channel offsets pass 2**31 (skipped with less than 8 GiB free), fp32, determinism and the nums_dict schedule (reused, with tail tokens and a NaN-poisoned allocator). No other test covers a causal conv1d backward.
  • op_tests/op_benchmarks/triton/bench_causal_conv1d_bwd.py (new): times causal_conv1d_split_qkv_bwd_triton_fn with RotatingBufferBench (CUDA-graph replays over a rotating input pool) on Kimi-K3 cases: TP8 (1536 channels per tensor, x row stride 6288 or 4608, 1 x 8192, 2 x 4096, varlen 8 x ~2048, 1 x 32768) and TP1 (12288 channels per tensor, 1 x 4096 and 1 x 8192). It reports the time and the effective bandwidth. It does not check accuracy; the unit test does that. It shares the input generator _make_inputs with the unit test. No other benchmark covers a causal conv1d backward; bench_causal_conv1d_prefill.py times only the forward.
Open in Web Open in Cursor 

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full 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 8726 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@cursor cursor Bot changed the title mi350的causal conv1d backward support for Kimi-K3 【MI350X】causal conv1d backward support for Kimi-K3 Nov 26, 2026
@cursor cursor Bot changed the title 【MI350X】causal conv1d backward support for Kimi-K3 [MI350X] causal conv1d backward support for Kimi-K3 Nov 26, 2026
cursoragent and others added 2 commits November 26, 2026 02:55
…al_states) for Kimi-K3

Add causal_conv1d_split_qkv_bwd_triton_fn, the backward of the varlen
causal conv1d with the [Q | K | V] layout of causal_conv1d_split_qkv.
It recomputes the pre-activation, so the forward saves nothing. dweight
and dbias are reduced from per-chunk fp32 partials, so the result is
deterministic. Add a gfx950 launch config, an fp32 autograd reference
test with Kimi-K3 shapes and a benchmark.

Co-authored-by: Sealeen Zhang <[email protected]>
@huizzhan
huizzhan marked this pull request as ready for review November 26, 2026 03:15
@huizzhan
huizzhan requested a review from a team November 26, 2026 03:15
@github-actions github-actions Bot changed the title [MI350X] causal conv1d backward support for Kimi-K3 [Triton/Gluon] [MI350X] causal conv1d backward support for Kimi-K3 Nov 26, 2026
@aiter-bot

aiter-bot commented Nov 26, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 794546aef7a4 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_causal_conv1d_bwd.py

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

…950)

The old kernel recomputed the pre-activation and SiLU for each of the width
output taps of every token. A 64 x 64 tile read 20 shifted x tiles and
12 masked dq/dk/dv tiles with scalar loads, and needed 310-482 VGPRs.

Each program now walks the tokens of its chunk one row of BLOCK_N channels at
a time. The last width - 1 rows of x and of the pre-activation gradient stay
in registers, so x and the output gradient are read once and dx is written
once. The next row is loaded before the current one is used. A channel block
inside one of q, k, v reads that tensor only. The kernel uses 54 VGPRs.

Host side: no torch.arange when cache_indices is None, a [chunk, channel, tap]
partial layout that sums straight into the dweight layout, and a two-step
fixed-order sum when there are 256 or more chunks. dq, dk and dv must share
one dtype.

gfx950 config: BLOCK_M 64, BLOCK_N 128, 1 warp, from a sweep of 45 configs on
the Kimi-K3 cases. The worst case is within 3% of the per-case best.

MI350X (gfx950), bench_causal_conv1d_bwd.py, 2 alternating rounds on one GPU,
before -> after (us):
  TP8, 1 x 8192           437 -> 94
  TP8, 2 x 4096           437 -> 95
  TP8, varlen 8 x ~2048   778 -> 156
  TP8, 1 x 32768         1698 -> 310
  TP1, 1 x 4096          1688 -> 308
  TP1, 1 x 8192          3363 -> 592

Add a test with token-contiguous x and gradients (no unit channel stride).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The backward kernels retain int32 stride overflow that can cause out-of-bounds accesses, NaN-padding contamination, and uninitialized tail gradients when reusing nums_dict.

3 open issues
What changed in this PR

Adds Triton causal conv1d backward support for Kimi-K3 training, complementing the existing forward kernels and KDA attention backward with convolution weight gradients.

Changes:

  • Exports a variable-length, split-QKV backward API returning input, weight, bias, and initial-state gradients.
  • Adds a sliding-window kernel with per-chunk gradient partials, fixed-order reduction, and a gfx950 launch config.
  • Adds autograd-reference tests and CUDA-graph benchmarks for TP8 and TP1 workloads.
File Description
op_tests/​triton_tests/​gated_delta_net/​test_causal_conv1d_bwd.py Tests gradients, layouts, padding, initial states, and schedule reuse.
op_tests/​op_benchmarks/​triton/​bench_causal_conv1d_bwd.py Benchmarks Kimi-K3 workloads with rotating inputs and CUDA graphs.
aiter/​ops/​triton/​gated_delta_net/​causal_conv1d_bwd.py Implements the public wrapper, scheduling, allocations, and gradient reduction.
aiter/​ops/​triton/​gated_delta_net/​__init__.py Exports the new backward API.
aiter/​ops/​triton/​configs/​gfx950/​triton/​conv/​causal_conv1d_split_qkv_bwd/​DEFAULT.json Supplies gfx950 launch settings.
aiter/​ops/​triton/​_triton_kernels/​gated_delta_net/​prefill/​causal_conv1d_bwd_split_qkv.py Computes input gradients and partial parameter gradients with a sliding window.

Review effort: Balanced

seqlen = tl.load(query_start_loc_ptr + seq + 1) - seq_start

blk_lo = pid_n * BLOCK_N
feats = blk_lo + tl.arange(0, BLOCK_N)
Comment on lines +323 to +329
gin = tl.where(i < n_tok, g, 0.0)
dw0 += gin * xu
dw1 += gin * xd1
if KERNEL_WIDTH >= 3:
dw2 += gin * xd2
if KERNEL_WIDTH >= 4:
dw3 += gin * xd3
Comment on lines +173 to +174
if end is not None and end < cu_seqlen:
dx[:, end:].zero_()
…tail dx fill

Three fixes from review, each reproduced on the previous revision:

- Channel offsets for x, dx, dq/dk/dv, the initial states and dinitial_states
  are computed in int64 when the channel stride is not 1. A token-contiguous x
  in a [36864, 65536] buffer overflowed int32 at channel 32768 and aborted the
  process with a GPU memory fault.
- x is read under the live length of the sequence, as the output gradient
  already was, so NaN or Inf in the x rows of a padded sequence no longer
  reach dx, dweight or dbias through 0 * NaN and SiLU.
- dx of the tokens after the last sequence is zeroed in the kernel, with the
  end read on the device. Reusing a nums_dict schedule left those rows
  uninitialized before; now every path zeroes them, the documented exception
  is gone, and the plain path drops a query_start_loc[-1].item() host sync.

Tests: test_pad_slots_nan, test_large_channel_stride, and tail tokens plus a
NaN-poisoned allocator in test_nums_dict_schedule.

MI350X (gfx950), bench_causal_conv1d_bwd.py, 2 alternating rounds on one GPU:
within 0.5% of the previous revision on every case (TP8 1 x 8192: 93.8 vs
93.6 us; TP1 1 x 8192: 589.8 vs 589.1 us).
cursor Bot pushed a commit that referenced this pull request Nov 26, 2026
…v bwd, pluggable chunk bwd

Co-authored-by: Sealeen Zhang <[email protected]>
@cursor cursor Bot changed the title [Triton/Gluon] [MI350X] causal conv1d backward support for Kimi-K3 [FlyDSL] [MI350X] causal conv1d backward support for Kimi-K3 Nov 26, 2026
Add causal_conv1d_split_qkv_bwd_flydsl_fn, the FlyDSL counterpart of
causal_conv1d_split_qkv_bwd_triton_fn, with the same arguments, layout and
results: dx, dweight, dbias and dinitial_states of the varlen causal conv1d
with split q/k/v output. The Triton version stays.

- aiter/ops/flydsl/kernels/causal_conv1d_bwd.py: the kernel. Each program
  owns one (sequence, chunk) of the chunk schedule; each thread owns one or two
  adjacent channels and walks the chunk plus width - 1 halo rows in an
  unrolled loop, loading prefetch rows of x and of the output gradient ahead.
  The q/k/v source is picked once per thread, outside the token loop. Rows past
  the live length, and all rows of padded sequences, read clamped addresses
  and select zero, so NaN there reaches no gradient. Offsets are 64-bit. dx of
  the tokens after the last sequence is zeroed in the kernel from the device
  copy of the end, so a reused nums_dict schedule needs no host sync.
- aiter/ops/flydsl/causal_conv1d_bwd_flydsl.py: the wrapper. Same schedule
  sources as the Triton wrapper (CausalConvPrefillMetadata, nums_dict, or a
  schedule built here), fp32 per-chunk dweight/dbias partials summed in a fixed
  order (deterministic, no atomics). Defaults (block_m 32, 128 threads,
  prefetch 16, 2 channels per thread) are the best of a 54-config gfx950 sweep
  on the Kimi-K3 TP8/TP1 shapes.
- op_tests/test_flydsl_causal_conv1d_bwd.py: the cases of the Triton test
  against the same fp32 autograd reference, plus odd channel splits, 1 and 2
  channels per thread, and CUDA-graph capture and replay; main() times FlyDSL
  and Triton on the Kimi-K3 shapes.

MI350X (gfx950), flydsl 0.5.3: 46/46 tests pass.
@github-actions github-actions Bot changed the title [FlyDSL] [MI350X] causal conv1d backward support for Kimi-K3 [Triton/Gluon] [FlyDSL] [MI350X] causal conv1d backward support for Kimi-K3 Nov 26, 2026
cursor Bot pushed a commit that referenced this pull request Nov 26, 2026
…-import, FlyDSL GEMMs for g_proj bwd

Co-authored-by: Sealeen Zhang <[email protected]>
…ositions

The unrolled token loop needed 164 VGPRs at block_m 32 and 294 with 146 SGPR
spills at block_m 64, and each row spent most of its ~325 instructions on the
IEEE exp expansion, an IEEE divide and 64-bit position compares.

- Walk the chunk in a runtime loop (scf.for with carried state) over groups of
  `prefetch` rows, loading the next group before the current one is used, so
  register use no longer grows with the chunk length (50-62 VGPRs, no spills)
  and block_m 64 halves the dweight partials. The unrolled loop stays behind
  runtime_loop=False.
- SiLU gradient through the exp2 (afn) + rcp sigmoid of the other FlyDSL
  kernels (act.sigmoid_batch).
- Token positions in int32; 64-bit only in the addresses, with the per-thread
  channel offsets hoisted out of the loop.
- Defaults: block_m 64, 64 threads, prefetch 4, 2 channels per thread.

MI350X (gfx950): the 46 FlyDSL tests pass with unchanged tolerances.
Preliminary short-timing bench (CUDA graph) vs Triton 21100d0, us:
TP8 1x8192 72 vs 92, TP8 1x32768 274 vs 316, TP1 1x4096 272 vs 316,
TP1 1x8192 535 vs 607.
@zufayu
zufayu requested review from a team, Boss2002n and brunomazzottiamd November 27, 2026 01:40
@huizzhan huizzhan changed the title [Triton/Gluon] [FlyDSL] [MI350X] causal conv1d backward support for Kimi-K3 [FlyDSL] [MI350X] causal conv1d backward support for Kimi-K3 Nov 27, 2026

@brunomazzottiamd brunomazzottiamd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. This PR changes two backends.

The PR changes Triton and FlyDSL. The repo rule is one backend for each PR, because different teams own these backends.

FlyDSL files (move to a separate PR):

  • aiter/ops/flydsl/causal_conv1d_bwd_flydsl.py
  • aiter/ops/flydsl/kernels/causal_conv1d_bwd.py
  • op_tests/test_flydsl_causal_conv1d_bwd.py

Keep only the Triton files here: the wrapper, the kernel, the config, the test and the benchmark. Open the FlyDSL PR as a stacked PR on top of this one. Ask the FlyDSL owners to review it.

2. Explain why two implementations exist.

Both functions have the same arguments and results. The PR does not say why we need both. Please answer these questions before proceeding with two stacked PRs (Triton and FlyDSL):

  • Which implementation is the intended default for callers?
  • Which archs does FlyDSL support? The PR shows tests on gfx950 only.
  • Will Triton be removed, or will it stay as a fallback? The text "stays in this PR for now" does not say.
  • What is the dependency on FlyDSL, and what happens when it is not installed?

3. The "FlyDSL is faster" claim has no firm evidence.

The numbers come from one short run on one GPU. The PR calls them "preliminary", and the formal A/B comparison is "pending". The first FlyDSL version was slower than Triton by 4% to 24%. Add the formal A/B numbers (at least two alternating rounds, same GPU, same method) for the final commit. Also add the accuracy check of the fast sigmoid. Until then, do not claim a speedup.

4. The PR description must describe what will be merged.

The description is a development log. Write one description of the final state to be merged, to avoid confusion. It must have the design, the supported cases, the tests and a performance table that matches the final head commit. Also remove the CURSOR_AGENT_PR_BODY markers and the "Open in Web" and "Open in Cursor" footer.

5. Commits: no AI-agent authorship.

All 8 commits have Cursor Agent as the author. Four of them also have a Co-authored-by trailer. See item 29 of aiter/ops/triton/README.md: remove AI-agent attribution from the commits before the merge. Rewrite the author of every commit to the human who is responsible for the change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants