← Back to Pull requests

[Ops] Add fused_recurrent kernel for Triadic Gated DeltaNet #1737

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 14, 2026 20:54 UTC
Author

Summary

Adds fused_recurrent_triadic_gdn, the decoding kernel for Triadic Gated DeltaNet, after the chunk kernels in #1625 (design in #1370). It takes the same tensors and [N, H, E, K, V] fp32 state as chunk_triadic_gdn and is forward-only like fused_recurrent_gated_delta_rule, so inference can prefill with the chunk op and decode from its final state.

Each program keeps all E slices of one value block of the state in registers, since every step's delta update sums S_eᵀ κ_e over the slices. Tiles come from a BV × num_warps sweep on H100 and B200 at decode shapes (B=32, H=32, T=1 and 4, K=128 and 256). The two prefer different sizes, so Hopper holds up to 32K state values per program (BV=32 up to two slices, 16 beyond) and other GPUs up to 16K (BV=32 up to four slices), with BV halved past that and up to 8 warps. At B=32, H=32 this is the fastest swept tile on B200 at every K=128 shape and within 4% of the fastest elsewhere at T=1. At T=4 the worst cases take 1.08x the fastest tile's time on H100 (K=128, E=16), and at K=256 1.09x on B200 (E=8) and 1.18x on H100 (E=4).

Supported: K, V <= 256, varlen, initial/final states; the tiles are tuned for E up to 16. Not supported yet: GVA, state_v_first, in-kernel L2 norm and gate activation.

Test plan

test_fused_recurrent and test_fused_recurrent_varlen in tests/ops/test_triadic_gdn.py compare outputs and final states against naive_recurrent_triadic_gdn. Cases cover one and four decoding steps, E = 1, 2, 4, 8, 12, 16, K = 8, 60, 64, 100, 128, 256, V = 12, 64, 96, 128, 256, strong decay, fp32/fp16/bf16, initial and final states each on and off, a state block narrowed to BV=8, and varlen with one token per sequence. test_chunk_then_fused_recurrent prefills with chunk_triadic_gdn and decodes from its final state. The one-step decode case is marked smoke.

FLA_CI_ENV=0 pytest tests/ops/test_triadic_gdn.py

| GPU | torch / Triton | Result |
|---|---|---|
| H100 80GB | 2.12.1 / 3.7.1 | 32 passed |
| H100 80GB | 2.9.1 / 3.5.1 | 32 passed |
| B200 | 2.12.1 / 3.7.1 | 32 passed |

scripts/find_dependent_tests.py selects only tests/ops/test_triadic_gdn.py. I also ran tests/test_public_api.py for the new export, plus tests/ops/test_gdn2.py, tests/ops/test_dplr_tilelang.py and tests/test_dispatch.py: 247 passed and 56 skipped on H100 80GB (2.12.1 / 3.7.1). The TileLang routes skip since TileLang isn't installed in the test env, and the rest are Ascend-only.

pre-commit and scripts/check_header.py --check pass.

Benchmark / NCU

This is a new op, so the reference is fused_recurrent_gated_delta_rule with H * E heads, which reads and writes the same state bytes but has no coupling between slices. Decode with initial and final states, K=V=128, bf16 q/k/v, fp32 state, B=32 and H=32, timed with triton.testing.do_bench through the public APIs at a29dd439. H100 80GB and B200, both torch 2.12.1 / Triton 3.7.1.

| T | E | H100 (us) | H100 reference (us) | B200 (us) | B200 reference (us) |
|---|---|---|---|---|---|
| 1 | 1 | 51.8 | 52.9 | 30.8 | 35.9 |
| 1 | 2 | 97.7 | 98.7 | 49.0 | 61.2 |
| 1 | 4 | 190.6 | 191.2 | 90.9 | 110.6 |
| 1 | 8 | 371.8 | 376.6 | 181.4 | 215.0 |
| 1 | 16 | 729.0 | 748.4 | 467.1 | 421.5 |
| 4 | 1 | 69.2 | 69.4 | 54.8 | 58.2 |
| 4 | 2 | 123.8 | 127.3 | 82.8 | 104.4 |
| 4 | 4 | 230.3 | 239.5 | 159.7 | 188.9 |
| 4 | 8 | 479.7 | 461.4 | 318.6 | 359.3 |
| 4 | 16 | 1136.0 | 906.4 | 763.2 | 707.8 |

Varlen, 32 sequences of 1 to 8 tokens (142 in total), H=32:

| E | H100 (us) | H100 reference (us) | B200 (us) | B200 reference (us) |
|---|---|---|---|---|
| 1 | 71.1 | 72.1 | 57.3 | 63.8 |
| 2 | 127.5 | 132.5 | 88.1 | 112.6 |
| 4 | 244.4 | 253.7 | 163.7 | 210.6 |
| 8 | 499.4 | 498.6 | 326.8 | 399.8 |
| 16 | 1147.7 | 975.7 | 802.7 | 785.2 |

At one step with E = 2 to 8, the state is read and written at 2.7 to 2.9 TB/s on H100 and 5.5 to 5.9 TB/s on B200. Up to E = 8 it is within 4% of the reference on H100 and faster on B200, where the reference uses BV=8. At E = 16 it takes up to 1.25x the reference time on H100 at four steps and 1.11x on B200 at one step.

python -m benchmarks.ops.run --op fused_recurrent_triadic_gdn fused_recurrent_triadic_gdn_varlen runs the registry shapes.

Breaking changes

None. Adds fused_recurrent_triadic_gdn (also exported from fla.ops) and two benchmark registry entries.

Checklist

  • I have read [CONTRIBUTING.md](../CONTRIBUTING.md) and follow its conventions (code style, docstrings, commit prefixes).

  • I have read [AGENTS.md](../AGENTS.md) and, where my change matches its scope, the relevant skill under [.agents/skills](../.agents/skills).

  • Dependent tests pass locally or in CI, and new behavior is covered by tests where applicable (tick as N/A for changes with no testable code, e.g. docs-only).

  • Kernel changes include same-hardware before/after benchmark numbers, dense + varlen where applicable (tick as N/A when no kernel code changed).

  • This PR is minor/cosmetic-only (typo, formatting, style-only tweaks) — tick only if it is, and justify below.

  • I understand this PR exceeds 500 changed lines and have explained its single purpose and why it should stay together below.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: ischencheng Review duration: 3992m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1737"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 57% (MEDIUM) · Higher = larger blast radius
    57%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 30.4% · Safe to merge
    30.4%