Skip to content

[Triton/Gluon] [FlyDSL] feat(flydsl): Add HSTU Backward kernel - #4885

Merged
damien-lejeune merged 119 commits into
mainfrom
dlejeune/flydsl_hsta_bwd
Sep 21, 2026
Merged

damien-lejeune merged 119 commits into
mainfrom
dlejeune/flydsl_hsta_bwd

Conversation

@SamiAario-AMD

@SamiAario-AMD SamiAario-AMD commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The purpose of this work is to implement the backward counterpart to the FlyDSL HSTU forward kernel.

Jira ID : SILOTIGER-616

Technical Details

Depends on the FlyDSL HSTU forward kernel in #4441. This PR adds the backward pass for the same attention block defined in HSTU (arxiv 2402.17152v2).

The backward does not stash activations from the forward — it recomputes S = alpha * Q K^T and the SiLU derivative from (Q, K), then produces (dQ, dK, dV) via two lock-free FlyDSL kernels:

  1. Fused KV-owned kernel (hstu_attention_bwd.py) — owns a KV tile, streams query tiles, and computes dV and dK from a single S recompute.
  2. Q-owned kernel (hstu_attention_bwd_dq.py) — mirrors the forward layout; each program owns a query tile and streams KV tiles to compute dQ.

Shared indexing/layout helpers live in hstu_attention_common.py. The public API is flydsl_hstu_attention_bwd in hstu_attention_kernels.py, wired into FlydslHstuAttention for end-to-end autograd.

Feature parity with the forward kernel:

  • Jagged (variable-length) batching via seq_offsets
  • Causal masking plus the same optional variants: num_targets, sliding window (max_attn_len), and contextual prefix (contextual_seq_len)
  • attn_dim != hidden_dim (asymmetric head dims)
  • {f16, bf16} inputs, fp32 accumulation, fast-math SiLU (same conventions as forward: alpha-in-score, 1/N on dS)

Tuning & dispatch:

  • Per-kernel tuned configs in hstu_attention_bwd_tuned.csv

Test Plan

  • Correctness (pytest) — op_tests/flydsl_tests/test_flydsl_hstu_attention_bwd.py

  • Perf / op-test gate — op_tests/test_flydsl_hstu_attention_bwd.py

  • Benchmark harness — extended op_tests/op_benchmarks/triton/bench_hstu_attn.py with --provider flydsl --mode bwd (and optional --sort_by_length).

Test Result

  • All unit tests in op_tests/flydsl_tests/test_flydsl_hstu_attention_bwd.py pass on gfx942 and gfx950.

Submission Checklist

Damien Lejeune and others added 30 commits July 7, 2026 12:44
…tead of two (for dV/DK and dQ), bringing minor performance gain
@damien-lejeune
damien-lejeune marked this pull request as ready for review September 11, 2026 12:16
@damien-lejeune
damien-lejeune requested a review from a team September 11, 2026 12:16
@github-actions github-actions Bot changed the title [FlyDSL] feat(flydsl): Add HSTU Backward kernel [Triton/Gluon] [FlyDSL] feat(flydsl): Add HSTU Backward kernel Sep 11, 2026
@coderfeli

Copy link
Copy Markdown
Collaborator

move the hstu related files in kernels/ into a sub folder and hstu_attention_kernels.py ->hstu_attention.py?

@damien-lejeune

Copy link
Copy Markdown
Contributor

move the hstu related files in kernels/ into a sub folder and hstu_attention_kernels.py ->hstu_attention.py?

Good suggestion. Fixed in a598aac

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@coderfeli

Copy link
Copy Markdown
Collaborator

need rebase @damien-lejeune

@damien-lejeune
damien-lejeune merged commit 43eb3d5 into main Sep 21, 2026
67 of 70 checks passed
@damien-lejeune
damien-lejeune deleted the dlejeune/flydsl_hsta_bwd branch September 21, 2026 13:40
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.

7 participants