Skip to content

[Triton/Gluon] Feat/gfx1250 replayssm kda verify - #7975

Open
Liang-jianhao97 wants to merge 9 commits into
mainfrom
feat/gfx1250-replayssm-kda-verify
Open

Liang-jianhao97 wants to merge 9 commits into
mainfrom
feat/gfx1250-replayssm-kda-verify

Conversation

@Liang-jianhao97

Copy link
Copy Markdown
Contributor

Summary

Add a gfx1250 Gluon implementation of ReplaySSM KDA verification.

The new public entry rebuilds committed state from checkpoint and history records, processes the current tokens, and writes output and updated records.

Motivation

The existing one-token decode entry does not implement ReplaySSM checkpoint and history-buffer semantics.

This change adds an optimized path for speculative verification, including the M128 workload with four draft tokens and one verification token per active request.

Changes

  • Add replayssm_sigmoid_gating_delta_rule for gfx1250 with K=V=128.
  • Use one CTA per request and value head, with shared record staging and vector checkpoint access.
  • Use interleaved state layouts and AMD DPP reductions.
  • Use a compiler reduction for FP32 output.
  • Reuse the shared fast launcher and JSON config loaders.
  • Support strided beta inputs, checkpoint flushing, negative slots, slot zero, and multi-chunk token processing.
  • Preserve the existing one-token decode interface.
  • Add reference tests and a benchmark with standard do_bench() and Graph/Event timing.

Performance

Hardware: gfx1250.

Configuration:

  • Request capacity: 128.
  • H=HV=12, K=V=128, record capacity=16, max_query_len=5.
  • BF16 activations and k/u records; FP32 checkpoint and g records.
  • Fixed inputs use one writable state set. Rotating inputs use 16 distinct writable state sets.
  • Timings cover the complete public call.

Before is the frozen ATOM ReplaySSM implementation, not the ordinary one-token decode kernel. After is this AITER implementation. Before and After were collected in separate runs on the same machine and software stack; speedups are representative cross-run comparisons.

Hardware Workload/configuration Before After Change
gfx1250 109 active / 545 tokens, fixed, do_bench 44.227 µs 20.792 µs 2.13×
gfx1250 109 active / 545 tokens, rotating ×16, do_bench 48.593 µs 22.554 µs 2.15×
gfx1250 109 active / 545 tokens, fixed, Graph/Event 39.592 µs 16.744 µs 2.36×
gfx1250 109 active / 545 tokens, rotating ×16, Graph/Event 44.979 µs 18.662 µs 2.41×
gfx1250 128 active / 640 tokens, fixed, do_bench 50.316 µs 22.755 µs 2.21×
gfx1250 128 active / 640 tokens, rotating ×16, do_bench 54.281 µs 24.637 µs 2.20×
gfx1250 128 active / 640 tokens, fixed, Graph/Event 45.644 µs 18.503 µs 2.47×
gfx1250 128 active / 640 tokens, rotating ×16, Graph/Event 50.628 µs 20.473 µs 2.47×

do_bench() uses 25 ms warmup and 100 ms measurement. Graph/Event uses 64 calls per graph and nine event samples.

These are standalone operator measurements, not full-model speedups.

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

The public wrapper docstring defines supported inputs, state updates, output behavior, and limits. No separate docs/ changes are included.

Dependencies

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

Uses the existing PyTorch, Triton/Gluon, launcher, and config utilities.

Breaking Changes

None. This adds a separate public entry and does not change existing decode APIs.

PR Self-Review

Reviewed revision

Candidate HEAD: 9c0c33ec038abdb449dfdd932bbb67db2272a88f.

Automated PR Self-Review revision confirmation is pending.

Behavior and intent

The entry reconstructs committed state, flushes the checkpoint when required, processes the current tokens, and appends k/u/g records.

It does not advance write_pos; the caller commits accepted tokens separately. Negative slots and empty sequences write nothing. Slot zero remains valid.

The implementation requires gfx1250, K=V=128, and the input constraints documented in the wrapper.

Validation and unverified scope

Executed on d01-3, gfx1250:

pytest op_tests/triton_tests/attention/test_kda_replayssm.py -q

Result: 24 passed.

pytest op_tests/triton_tests/attention/test_kda_one_token.py op_tests/triton_tests/attention/test_kda_atom.py -q

Result: 36 passed.

python op_tests/op_benchmarks/triton/bench_kda_replayssm.py --requests 128 --live 109
python op_tests/op_benchmarks/triton/bench_kda_replayssm.py --requests 128

Both benchmarks completed with standard do_bench and Graph/Event timing for state pools of 1 and 16.

Ruff, Black, and Git whitespace checks passed.

Software:

  • PyTorch 2.11.0+rocm10.1.0a20260811-bkc.20260820
  • HIP 7.16.26315
  • Triton 3.9.0

MI250X and MI300X were not tested. This kernel uses gfx1250-specific instructions. Other architectures and full-model integration remain unverified.

PR-specific question

Pending the path-specific question from the automated PR Self-Review comment.

Changed op tests

  • op_tests/triton_tests/attention/test_kda_replayssm.py

    • Checks output, checkpoint, records, and metadata against a PyTorch reference.
    • Covers flush boundaries, skipped requests, slot zero, M128 verification, consecutive transitions, BF16/FP16/FP32, token chunks, side streams, and graph capture.
    • Adds ReplaySSM state-history coverage that the ordinary decode tests do not provide.
  • op_tests/op_benchmarks/triton/bench_kda_replayssm.py

    • Measures the complete public ReplaySSM call with do_bench and Graph/Event.
    • Supports fixed and rotating writable state sets and partially active M128 batches.
    • Covers checkpoint/history workloads that the ordinary decode benchmark does not exercise.

codex and others added 9 commits November 13, 2026 13:07
Select a JSON write-back config for supported BF16 paged decode with FP32
state. Reuse the existing recurrence and add a short launch entry with an
exact specialization cache, current-stream launches and hook fallback.

Use a 4D register layout, clause-free b64 whole-line state stores, staged
output and spread chunks. Keep full gating, normalization and state math.
Keep slot zero valid and skip negative slots, including multi-token stores.

Validation on d07 B0: 27 new public API tests passed; selected existing
regressions plus the new tests passed 69 with 12 expected dtype skips.
Black, Ruff, compileall and diff checks passed. RotatingBufferBench pool1
and pool16 smoke tests passed. Standard direct-public-call do_bench measured
9.574/14.823 us versus main 37.416/37.656 us, geometric mean 3.151x.
Accept gfx1250-strict in the write-back selector and KDA test markers.
Use the gfx1250 configuration tree for both compiler targets, including
the test config fixture. Keep the native compiler target unchanged.

Validation on g21-10: 27 write-back tests and 66 selected existing KDA
tests passed, with 12 expected BF16-state skips. Black, Ruff and diff
checks passed. RotatingBufferBench pool1 and pool16 smoke tests passed.
Two direct public-call do_bench runs measured 14.82-14.86 us fixed and
14.90-14.94 us with 16 rotating states. The main control uses the same
strict config-path correction; geometric-mean speedup was 2.18-2.22x.
The fast path is selected only for length-0/1 sequences, and longer sequences stay on the generic kernel.

Co-authored-by: Cursor <[email protected]>
The length check uses itertools.pairwise, which is what ruff 0.16.0 reports on this PR.

Co-authored-by: Cursor <[email protected]>
…slots.

Ordinary gfx1250 decode still uses the one-token kernel. A state fork or
speculative verify can load one slot and store another, including slot 0
and negative slots, without clobbering the checkpoint.

Co-authored-by: Cursor <[email protected]>
…chmark.

Move ssm_state_indices_in in try_kda_one_token_decode to a keyword-only
argument so existing positional callers that pass out keep working.
Fix a nested-if lint issue in fused_recurrent_kda, format the new test,
and add bench_kda_atom.py comparing one-token, generic, and the ATOM entry
(same slots, split tensors, state fork) on gfx1250.

Co-authored-by: Cursor <[email protected]>
Fold the separate one-token and ATOM benches into bench_kda's shape and metric table, including a state-fork column that reads a disjoint slot.

Co-authored-by: Cursor <[email protected]>
Add checkpoint replay and fused token verification with a Gluon kernel.
Use the shared fast launcher and JSON config loaders. Keep the existing
one-token decode interface unchanged.

Cover flushes, strided beta, FP16 and FP32 output, graph capture and state
updates. Add a benchmark for standard do_bench and graph/event timing.

Validation on gfx1250: 24 ReplaySSM tests and 36 existing decode/ATOM tests
passed. Ruff and Black checks passed.
@Liang-jianhao97
Liang-jianhao97 requested a review from a team November 15, 2026 06:00
@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 7975 --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.

@github-actions github-actions Bot changed the title Feat/gfx1250 replayssm kda verify [Triton/Gluon] Feat/gfx1250 replayssm kda verify Nov 15, 2026
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 9c0c33ec038a · 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 — PR-specific question is too short to show concrete reasoning (10 units; need 14)
  • FAIL — changed op test not explained in Changed op tests: op_tests/op_benchmarks/triton/bench_kda.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/attention/test_kda.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/attention/test_kda_atom.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/attention/test_kda_one_token.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.

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

Critical issues can leave tokens unwritten during graph capture, select a missing configuration tree on gfx1250-strict, and load the wrong state when cached updates use distinct read/write tables.

14 open issues
What changed in this PR

Adds gfx1250 ReplaySSM verification to AITER’s Kimi Delta Attention support. The new entry rebuilds committed state from checkpoints and history, processes current tokens, and updates records without advancing the caller’s commit cursor.

Changes:

  • Adds a ReplaySSM wrapper, Gluon kernel, and JSON configuration for K=V=128.
  • Adds one-token decode dispatch and ATOM read/write slot support, plus shared launcher compatibility changes.
  • Adds reference tests and benchmarks for state transitions, graph capture, and fixed or rotating state pools.
File Description
op_tests/​triton_tests/​attention/​test_kda.py Enables existing tests for the strict gfx1250 target.
op_tests/​triton_tests/​attention/​test_kda_replayssm.py Tests replay, checkpoint flushing, records, dtypes, and capture.
op_tests/​triton_tests/​attention/​test_kda_one_token.py Tests one-token dispatch, fallback, strides, and launch behavior.
op_tests/​triton_tests/​attention/​test_kda_atom.py Tests separate read/write slots and speculative verification.
op_tests/​op_benchmarks/​triton/​bench_kda.py Adds one-token and ATOM benchmark providers.
op_tests/​op_benchmarks/​triton/​bench_kda_replayssm.py Adds ReplaySSM timing with fixed and rotating state pools.
aiter/​ops/​triton/​configs/​gfx1250/​gluon/​attention/​kda_replayssm/​DEFAULT.json Defines ReplaySSM launch settings.
aiter/​ops/​triton/​configs/​gfx1250/​gluon/​attention/​kda_decode/​DEFAULT.json Adds a one-token configuration bucket.
aiter/​ops/​triton/​attention/​kda.py Integrates one-token dispatch and read/write slot arguments.
aiter/​ops/​triton/​attention/​kda_replayssm.py Adds the public ReplaySSM entry and input checks.
aiter/​ops/​triton/​attention/​kda_one_token.py Selects and launches supported one-token decode calls.
aiter/​ops/​triton/​attention/​kda_atom.py Adds the ATOM-compatible fused gating entry.
aiter/​ops/​triton/​_triton_kernels/​kimi_delta_attn/​fast_launch.py Adds launch-hook checks and launcher-signature fallback.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​attention/​kda_replayssm.py Implements checkpoint reconstruction and token recurrence.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​attention/​kda_decode.py Adds one-token kernels and split-slot handling.

Review effort: Balanced

Comment on lines +142 to +144
if ssm_state_indices_in is not None:
if ssm_state_indices is None:
raise ValueError("ssm_state_indices_in requires ssm_state_indices")
Comment on lines +38 to +46
"""True when every sequence length is 0 or 1.

The bounds live on device. Reading them syncs, which is what keeps a longer
sequence on the generic kernel instead of dropping its extra tokens. CUDA
graph capture cannot sync, so a captured call is required to already be a
one-token batch; the eager path still checks.
"""
if torch.cuda.is_current_stream_capturing():
return True
@functools.lru_cache(maxsize=8)
def _config(arch, cu_num):
# Include the CU count to keep device-specific config trees separate.
path = resolve_config_dir("attention", "kda_replayssm", backend="gluon")
"""
if torch.cuda.is_current_stream_capturing():
return True
bounds = starts.tolist()
def bench_kda(H, B, T, provider):
torch.manual_seed(0)
if provider in ONE_TOKEN_BACKENDS:
case = make_one_token_case(B, provider, args.padded)
Comment on lines +220 to +224
def _kda_dot8(S0, S1, S2, S3, S4, S5, S6, S7, x0, x1, x2, x3, x4, x5, x6, x7):
"""Row sums of S * x: an fma chain over the blocks, then across lanes."""
p = S0 * x0[None, :]
p = gl.fma(S1, x1[None, :], p)
p = gl.fma(S2, x2[None, :], p)
Comment on lines +333 to +335
b_beta = 1.0 / (1.0 + gl.exp(-b_b))
if USE_LOWER_BOUND:
b_g = LOWER_BOUND * (1.0 / (1.0 + gl.exp(-(gl.exp(b_Alog) * x))))
Comment on lines +9 to +11
from aiter.ops.triton.attention.kda_atom import ( # noqa: F401
fused_sigmoid_gating_delta_rule_update,
)
Comment on lines +156 to +157
if _ARCH in ("gfx1250", "gfx1250-strict"):
result = try_kda_one_token_decode(
Comment on lines +169 to +170
from aiter.ops.triton._gluon_kernels.gfx1250.attention import kda_decode
from aiter.ops.triton._triton_kernels.kimi_delta_attn.fast_launch import fast_launch
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Dec 2, 2026

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

Labels

stale The PR hasn't been updated in 2 weeks Triton/Gluon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants