Skip to content

Rewrite flash-attention backward on current ferro-kittens (first backward consumer — expect library gaps) #69

Closed

Description

@feitreim

Blocked on #66, and best sequenced after the forward rewrite (see the flash-forward issue) so the staging/scheduling decisions are settled once.

Rewrite the flash-attention backward path — flash_backward_q_tcgen05 / flash_backward_kv_tcgen05 and their _pipelined forms in gpu/flash-attn/src/tcgen05.rs — on current ferro-kittens.

This one has no reference kernel

Unlike gemm and flash forward, ferro-kittens has no backward kernel in examples/ or experiments/ — this is the first consumer of the current surface for the backward dataflow (dS, dQ/dK/dV, the recomputation or stash of P). Expect it to be the biggest source of library gaps of the four rewrite issues, and treat that as part of the deliverable:

Every gap goes on feitreim/ferro-kittens as an issue, linked from the PR. Candidates visible from GAPS.md before writing a line:

  • RegVec cannot reach memory at all (ferro The pin reaches ferro main, and the module the driver refused loads: #227 confirmed downstream #130) — the per-row statistics the backward carries (row-sum of dO∘O, the LSE) cross kernel boundaries, and a RegVec's slots are spread across lane / 4, so staging one is a scatter the library doesn't have yet.
  • No transpose / swap_layout / second FragmentLayout (GAPS §1.3, §3.4, filed nowhere) — the backward wants Sᵀ/Pᵀ operands; check whether the MMA operand-order square (mma_atb, mma_atbt) covers each site before concluding a register-side transpose is needed. If one genuinely is, that's the issue that finally motivates a second FragmentLayout — file it with the concrete dataflow attached.
  • TMA reduction stores (store_add_async) are absent from the generated crate though upstream records exist (ferro Convert the flash attention kernels to HD=128 #42) — relevant if dQ is accumulated across KV blocks.

Surface to build on

mm_*/mma_* operand-order entry points (all four orders exist single-CTA), pipeline::run/run_stealing, SharedPlan, the shipped epilogue pattern (store_tile_x4 + store_shared_rows), masking with coordinate origin for the causal case.

Process

Branch off main, one PR per kernel (q and kv split as today unless a fused form measures better); never touch main. Correctness against existing gradient gates; performance on B200 via modal_app.py against the _pipelined baselines. A Modal check red in ~15s is the spend limit, not the code.

Activity

  1. added 2 commits that reference this issue on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions