Skip to content

Fix ReplaySSM flush record ordering - #3618

Merged
valarLip merged 16 commits into
mainfrom
task-693-main-kda-fused
Nov 27, 2026
Merged

valarLip merged 16 commits into
mainfrom
task-693-main-kda-fused

Conversation

@whx-sjtu

@whx-sjtu whx-sjtu commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes https://github.com/wuhuikx/LLM-Booster/issues/693. Fixes ReplaySSM flush ordering in the GDN and KDA fallback kernels; performance acceptance remains open.

Every value slice must finish reading the old k/g records before a flush overwrites them. A load wait and barrier precede each counted arrival; the last slice owns the k/g stores and resets the counter. Append steps keep their existing owner.

Arrival counters belong to each layer's record pool, and WAIT is selected when that pool is created. Native and SGLang callers pass this storage directly, including graph replay. Per-launch scratch that is zero between launches is excluded from persistent slot state.

88131eaba8 moves KDA's arrival after replay reconstruction consumes the record tiles and restores main's inline gate formula. It also reverts the import rewrap and adds the required test header. KDA non-flush timings are now near parity with the matched main reference; bs256 flush overhead remains open.

The fused update and its tests are in #3628. 2c655b178f retains _kda_log_decay with the fused caller.

Testing

  • 88131eaba8: 19 focused Windows CPU tests and 23 subtests passed using established AITER stubs. Black/Ruff and source checks passed. Independent source review found no source defect; performance acceptance remains open.
  • 88131eaba8: 32 gfx950 correctness cases passed, zero skips. Two complete timing passes show KDA bs256 flush still +7.86–17.36 µs per call.
  • 2a7471e1: native gfx942 parent/candidate checks passed for outputs and all mutable state (48 controls, 16 replicas each). Generic GDN batch 256 with 4 tokens is -0.39% nonflush and +0.81% flush versus main, replacing the reproduced ~52% regression. Generic occupancy returns from 1 to 2. e5187fd21 gfx942 evidence attributes KDA flush excess to arrival/owner/reset; unsafe fixed ownership retains wait/barrier and leaves -0.473/-0.563/+0.621 us versus main (batch256, T=1/2/4), with unchanged occupancy. Requested gfx950 measurements are complete; awaiting reviewer acceptance; no model-throughput result is claimed.
Native gfx942 validation of the GDN placement correction

Generic GDN ownership acquisition now follows replay contraction. Native main, old parent and candidate codegen matched their CPU-compiled instruction streams. Main/candidate use 256 total vector registers and occupancy 2; the parent used 272 and occupancy 1. Computation and returning-atomic instructions remain, with zero spills/scratch.

Two passes of the same paired CUDA-event method, 16 independent-state calls per span, with all 2,080 positive raw spans and statistics rechecked. Maximum pass drift: 0.77%. Strict candidate/correct-parent output and mutable-state equality passed, as did independent checkpoint references, zero counters and readonly/disjoint-storage checks. Same-session parent GDN batch 256 with 4 tokens controls were 599.916/731.137 µs (nonflush/flush), versus candidate 392.825/483.009 µs. Main drift between those segments was below 0.20%.

Path Batch T Flush Main µs Candidate µs Delta %
GDN 64 1 no 48.184 46.628 -3.23%
GDN 64 1 yes 113.481 118.335 +4.28%
GDN 64 2 no 73.920 73.432 -0.66%
GDN 64 2 yes 125.023 124.975 -0.04%
GDN 64 4 no 115.529 114.712 -0.71%
GDN 64 4 yes 154.661 154.240 -0.27%
GDN 256 1 no 161.479 153.931 -4.67%
GDN 256 1 yes 374.206 386.910 +3.39%
GDN 256 2 no 246.405 244.747 -0.67%
GDN 256 2 yes 384.250 388.282 +1.05%
GDN 256 4 no 394.358 392.825 -0.39%
GDN 256 4 yes 479.109 483.009 +0.81%
KDA 64 1 no 93.124 92.548 -0.62%
KDA 64 1 yes 143.152 151.855 +6.08%
KDA 64 2 no 110.818 109.966 -0.77%
KDA 64 2 yes 160.305 166.520 +3.88%
KDA 64 4 no 147.281 146.126 -0.78%
KDA 64 4 yes 195.951 200.695 +2.42%
KDA 256 1 no 339.516 337.066 -0.72%
KDA 256 1 yes 491.148 531.778 +8.27%
KDA 256 2 no 409.988 406.559 -0.84%
KDA 256 2 yes 562.706 585.061 +3.97%
KDA 256 4 no 551.791 546.933 -0.88%
KDA 256 4 yes 714.936 739.973 +3.50%

Sources: main 031d4da2671e, correct parent f0287a38 (measured kernel equals 88131eaba8), candidate 2a7471e1. MI308X/gfx942; Torch 2.10.0+rocm7.2.4.git3d3aa833, HIP7.2.53211, Triton3.8.0+amd.rocm7.2.0.git7cb7b059, image d49be4a1b03b. Evidence archive SHA256: 62ae00a1f9e8de0516d23f170a4029ff0170228d569bb2ab672decf734043121. This is scoped operator validation, not a new full-model result. KDA source is unchanged; its residual flush cost remains.

Matched gfx950 results at 88131ea, including both passes and batch 1

Main 031d4da2671e versus 88131eaba8c7, g27 GPU0. All 32 existing flush/strided numerical cases passed with zero skips. Two complete passes, twenty alternating pairs per row; each graph contains sixteen sequential fallback calls with independent identical mutable state. All 2,080 raw whole spans are retained and divided by sixteen without overhead subtraction. Reset copies and warmup are outside the event span; graph/event/submission overhead and inter-node gaps are included. These are not profiler kernel-only times or model throughput.

Table values are microseconds per call: pooled forty-sample medians per arm, their signed difference, and each pass's separate median difference. All per-arm pass drift was below 2%. KDA non-flush differences are below that scale; do not interpret the small negative values as a demonstrated speedup. Every KDA flush row was slower in all forty pairs, including batch 1. GDN's large-batch flush cost is also visible in this method.

Path Batch T Flush Main µs 88131 µs Delta µs Delta % Pass-1/2 delta µs
GDN 64 1 no 20.431 20.882 +0.450 +2.20% +0.424/+0.484
GDN 64 1 yes 31.264 33.115 +1.851 +5.92% +1.944/+1.844
GDN 64 2 no 25.400 25.458 +0.057 +0.23% +0.176/-0.014
GDN 64 2 yes 31.787 32.269 +0.482 +1.52% +0.427/+0.495
GDN 64 4 no 35.784 35.830 +0.046 +0.13% -0.001/-0.020
GDN 64 4 yes 41.805 42.254 +0.449 +1.07% +0.367/+0.548
GDN 256 1 no 55.609 56.993 +1.384 +2.49% +1.400/+1.463
GDN 256 1 yes 83.253 90.932 +7.679 +9.22% +7.655/+7.556
GDN 256 2 no 70.920 70.871 -0.049 -0.07% -0.117/-0.105
GDN 256 2 yes 88.576 93.822 +5.246 +5.92% +4.896/+5.291
GDN 256 4 no 110.196 110.078 -0.119 -0.11% +0.199/-0.075
GDN 256 4 yes 125.815 128.284 +2.469 +1.96% +2.643/+2.105
KDA 1 1 no 7.443 7.325 -0.118 -1.58% -0.107/-0.033
KDA 1 1 yes 7.821 8.461 +0.640 +8.18% +0.671/+0.616
KDA 64 1 no 25.579 25.615 +0.036 +0.14% +0.063/+0.060
KDA 64 1 yes 36.399 37.934 +1.535 +4.22% +1.451/+1.635
KDA 64 2 no 27.890 27.910 +0.020 +0.07% -0.075/+0.132
KDA 64 2 yes 37.762 38.877 +1.115 +2.95% +0.813/+1.314
KDA 64 4 no 32.800 32.938 +0.138 +0.42% -0.016/+0.196
KDA 64 4 yes 42.085 43.333 +1.248 +2.96% +1.013/+1.464
KDA 256 1 no 67.517 67.287 -0.230 -0.34% -0.208/-0.305
KDA 256 1 yes 105.712 123.075 +17.363 +16.42% +17.414/+17.336
KDA 256 2 no 77.317 76.960 -0.358 -0.46% -0.393/-0.328
KDA 256 2 yes 114.021 126.988 +12.966 +11.37% +12.614/+13.098
KDA 256 4 no 97.297 96.856 -0.441 -0.45% -0.450/-0.315
KDA 256 4 yes 131.994 139.850 +7.856 +5.95% +7.864/+7.959

Geometry: GDN H4/HV16, KDA H12/HV12; K=V=128, CAP16; non-flush cursor 16-2T, flush cursor 16-T. BF16 q/k/v and k/u, FP32 g, BF16 GDN checkpoint and FP32 KDA checkpoint; q/k normalization enabled, KDA lower bound -5. Seed103; three eager and three graph warmups per arm. Actual runtime: Torch 2.10.0+rocm7.2.4.git3d3aa833, HIP 7.2.53211, Triton 3.8.0+amd.rocm7.2.0.git7cb7b059, AITER 183a6ce66ebb975223534f3bdeaca4132d2f4530, amdgpu 6.16.13; image digest 72817ab903cf34722c670527a224c3177317fa2f6dc6f87fbd63acad52d623bb.

Evidence archive SHA256: 9b72d7af0933e511761e0999b07bade9f8ce16d55cd3edec0a3ba4171009c75c. The earlier unsupported event-API admission produced zero samples and ran no numerical tests; that failure is retained separately. These earlier measurements do not provide gfx942 or full-model qualification.

Earlier GPU evidence, with its original source

0934f5b0e: 32 gfx950 GPU tests passed with no skips. This is earlier-source evidence, not validation of the moved arrival in 88131eaba8.

Main 659c3ba49cd5 versus 0934f5b0e54b: 48 fallback configurations measured. At bs256, KDA increased by 16.30–32.38 µs without flush and 33.96–35.94 µs with flush. These warmed kernel durations include the previous gate factoring; wrapper/model throughput was not measured. These earlier measurements are not current-source validation.

@whx-sjtu whx-sjtu added the agent-team/hold-landing Holds landing only; development and review go on label Nov 20, 2026

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ATOM PR #3618 — Fuse KDA ReplaySSM update and order flush record writes

Adds a fused KDA update API and uses counters owned by each checkpoint pool to order fallback flush writes.

Review: ✅ LGTM for human review at 507c116b422c843e43767e62139eb18f38a156a5; hold landing remains.
Coverage: BEYOND ONE PASS -- 520 non-test added lines (p90 across 40 merged ATOM PRs is 519). Findings below are a sample, not a sweep: re-reviews of a diff this size return a similar count each time without converging. Recommend splitting along the seams the diff already has -- a reader cannot tell a complete review from a partial one by reading it.
Validation (advisory): Four CPU host tests and source interleaving controls pass on Windows; old-key, allocation-size, capture and ISA controls fail as expected — one run, this box, unverified. Actual target compilation and GPU numerical, graph, race and timing checks remain unrun.

📝 [verified] atom/model_ops/fla_ops/replayssm.py::replayssm_kda_fused_update overlaps AITER's ReplaySSM fusion but adds f_b, raw-output and independent conv-slot contracts, leaving related kernels in both repositories. Reviewer should ask maintainers to confirm the owning repository or require an AITER extension before landing.

@whx-sjtu
whx-sjtu marked this pull request as ready for review November 20, 2026 06:03

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

some changes needed..

gpu run of the fused kernel and the _owns_kg_records flush fix? and real gfx1200/1250 compile of the s_wait_loadcnt asm?

ci green.

Comment thread atom/model_ops/fla_ops/replayssm.py Resolved
Comment thread atom/model_ops/fla_ops/replayssm.py Resolved

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ATOM PR #3618 — Fuse KDA ReplaySSM update and order flush record writes

Documents arrival-counter lifetime, ordered address reuse and checkpoint storage obligations for graph replay.

Review: ✅ LGTM for the comment-only delta 507c116b4 → 6a37814a1021295c45ee3463ade2942bef1ea4a5; ready for human review with hold landing. The previous scoped review, including its AITER ownership question, stands.
Coverage: BEYOND ONE PASS -- 520 non-test added lines (p90 across 40 merged ATOM PRs is 519). Findings below are a sample, not a sweep: re-reviews of a diff this size return a similar count each time without converging. Recommend splitting along the seams the diff already has -- a reader cannot tell a complete review from a partial one by reading it.
Validation (advisory): Reviewer-run Windows comparison confirms identical full-module Python ASTs and only six added/six removed comment lines; head import path passes; one run, this box, unverified. CPU evidence at 507c116b4 is reused. No new runtime test was run. Actual compiler and GPU numerical/graph/concurrency/race/timing qualification, parent #3614 and final landing-tree checks remain required. Consumer #3628 has separate runtime qualification.

@valar-cop

valar-cop commented Nov 20, 2026 •

Copy link
Copy Markdown

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ATOM PR #3618 — Parent merge and test migration

Preserves the parent's real CPU tensor tests and the child's counter, wait-selection and full flush-matrix checks.

Review: ✅ LGTM for the merge/test delta 6a37814a1 → 13b6c0d8c09c70422e843a2f0e629d1444b1ed37, against parent task-689-main-kda-beta@fe7816613. No new source blocker; hold landing remains. The prior scoped production review, its coverage limit and ownership question stand.
Coverage: 0 files / 0 added lines -- within one review pass
Validation (advisory): Reviewer Windows Torch 2.10 CPU: four tests and 16 subtests pass; bounded key/count/capture/legacy-WAIT controls fail their intended assertions with no collection errors, then restored source passes; one run, this box, unverified. Production bytes match 6a; the GPU test function/decorators retain all 24 combinations. GPU fused/flush/replay, actual target compilation, concurrency/lifetime, timing, parent, formal review and final landing-tree gates remain open.

Scope and validation boundary

The coverage line counts non-test code; this delta changes two test files. The actual PR base is fe78166. The merge retains the parent's 12 non-flushing cases and restores 12 flushing cases only in this child, which contains the ordering correction. The first-parent production file is byte-identical; no GPU run was repeated or claimed.

CPU tests use actual imported production functions and real Torch tensors, with external kernel stubs and import-only Windows POSIX-name adapters. Negative controls replace only the helper bodies in memory; source files remain unchanged. CPU checks do not establish opcode assembly, GPU ordering or live cache/graph safety. The full parent snapshot accepts the PR patch; the fetch helper's sparse snapshot omitted the modified tests and produced a false stale warning.

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

some changes needed..

ci green.

Comment thread atom/model_ops/fla_ops/replayssm.py Resolved
Base automatically changed from task-689-main-kda-beta to main November 23, 2026 06:52
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
(cherry picked from commit bdda79f)
Co-authored-by: Cursor <cursoragent@cursor.com>
Ported-from: ROCm#3618
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
(cherry picked from commit 557fd87)
Co-authored-by: Cursor <cursoragent@cursor.com>
Ported-from: ROCm#3618
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
(cherry picked from commit 507c116)
Co-authored-by: Cursor <cursoragent@cursor.com>
Ported-from: ROCm#3618
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
(cherry picked from commit 6a37814)
Co-authored-by: Cursor <cursoragent@cursor.com>
Ported-from: ROCm#3618
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
Linearized port of merge commit 13b6c0d: test files taken
from that merge's tree; the intermediate ROCm#3618 commits above kept the ROCm#3614 test version.

Co-authored-by: Cursor <cursoragent@cursor.com>
Ported-from: ROCm#3618

@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.

⚠️ Action required before merge (5)

The flush-ordering fix is wanted. On main, during a flush the i_v == 0 program overwrites the k/g records while other V slices still replay them. We traced the new ordering (load wait + barrier before the counted arrival, last arrival resets the counter) and found it correct. The rest needs changes:

  1. Land the fused KDA update together with its caller. replayssm_kda_fused_update / _replayssm_kda_fused_kernel (fla_ops/replayssm.py:1989-2424, about 440 lines) have no caller in this PR, and nothing runs them in CI. Their only consumer is the stacked #3628, as valar-cop's still-open thread at :2290 notes. Keep the flush fix and its tests here, and move the fused update into #3628. We will settle there whether it belongs in ATOM or should extend aiter's fused_kda_decode_unified, which already fuses conv1d with the ReplaySSM KDA recurrence. When it moves, also assert conv_weight.dim() == 2 (:2341): the kernel reads stride(1) as the tap stride, so an nn.Conv1d-shaped [C, 1, 4] weight passes the assert and silently reads the wrong taps.
  2. Remove the per-launch host cost of _flush_arrivals / _flush_wait. These calls (replayssm.py:437-458, called at :1608 and :1950) build a (device, data_ptr, shape) key, look it up in a dict and call get_gfx_runtime() on every launcher call.
    • Two independent in-process A/Bs with controls measured about +1.2–4 µs per call, against a 50–160 ns base.
    • There is one call per GDN/KDA layer, so this is about 40–150 µs on every step that is not graph-replayed. That covers mixed spec+prefill batches, batches above the largest captured size, --enforce-eager and PP runs. ReplaySSM is on by default with MTP (gdn_attn.py:267).
    • Fix: allocate the int32 arrival counters (slots × HV) with the checkpoint pool, next to buf_k/u/g, and pass them in the same way. Resolve the WAIT mnemonic once at init.
    • This also removes the process-lifetime dict, the address-reuse rule and the raise when the first call happens inside graph capture.
    • We checked that a smaller variant (cached WAIT plus a lighter key) is still about 0.9 µs per call, which is why we ask for the pool-owned tensor.
  3. Post base-vs-head fallback kernel times. _owns_kg_records (:406-425, used at :923, :1005, :1798) adds a vmcnt wait, a barrier and a global atomic to every program of every flushing launch of the default GDN/KDA fallback kernels. The PR only times the fused path. Please post flush and non-flush steps at the Qwen3.5 (HV16) and Kimi-K3 (HV12) per-rank shapes, bs {1,16,64,256} × T {1,2,4}, on gfx950. If gfx942 is a target, include it too.

Nits (still need a change):

  1. Add a CPU-lane guard for the new ordering wiring. Both *_gpu.py files skip in CI, so reverting any if owns_kg: to if i_v == 0:, or dropping flush_arrivals/WAIT from the GDN _replayssm_fwd_kernel call, still passes. Add the GDN twin of _check_wrapper_layout plus an AST check that every buf_k/buf_g store in the two fallback kernels sits under owns_kg. Put both in tests/model_ops/test_replayssm_kda_strides_cpu.py, which runs in the CPU lane.
  2. Clean up the squash text. The commit headlines include "defer racy flush cases", which this PR undoes, plus two merge commits, and the PR body is a process log (gates, qualified=false, review links). Write a short squash message describing the flush fix (and the fused update, if it stays).

Reviewed at 746edbd (Deep, round 1; 2 independent passes). Rejected after checking: capture-time first-call raise (eager warmup runs first, model_runner.py:4406-4416), UT-kernel race (one V slice per program), counter reset across graph replays, _flush_wait as a copy of an aiter rule (it only picks an ISA mnemonic), aiter symbols (get_gfx/get_gfx_runtime exist on main). CI: Pre Checkin green; GPU unit tests and heavy lanes not run.

Pass initialization-time counters and wait selection through native and SGLang callers. Guard fallback launch wiring and record-store ownership in CPU tests. Move the unused fused KDA implementation and its tests to the existing consumer PR.
@whx-sjtu

whx-sjtu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixes the structural requests in this review at 0934f5b0e: fused KDA code/tests moved to #3628; pool-owned counters and initialization-time WAIT replace launch-time caching; CPU guards cover launch wiring and store ownership. The gfx950 comparison below retains the material large-batch KDA costs. Performance acceptance remains open. This campaign targets gfx950 only; no gfx942 performance claim is made.

Requested source and test changes

replayssm_kda_fused_update, its kernel and the fused GPU tests now live with their caller in #3628 (469e721e). That consumer also rejects non-2-D convolution weights. The GDN/KDA fallback flush fix and its tests remain here.

The native allocator owns int32 arrival storage shaped [layers, slots, HV] beside the record pools and includes it in memory accounting. Both native GDN/KDA branches and SGLang pass their pool's counter slice and initialization-time WAIT. The process-lifetime counter dictionary, checkpoint-address keys and per-launch flush-WAIT ISA lookup are removed. Counters reset after each flush and stay alive with the graph's record pool.

Follow-up dee0dbf46 also explicitly excludes both fields from LMCache MP PAGE transfers. The three existing QSA PAGE tests that exposed the missing classification now pass in Pre Checkin. This host-only change leaves the measured kernel code unchanged.

tests/model_ops/test_replayssm_kda_strides_cpu.py now exercises the real GDN wrapper and checks every fallback k/g store's ownership guard. Reverting any of the five owns_kg guards, or dropping either GDN launch argument, fails its CPU checks. The restored suite passes 7 tests and 23 subtests, including pool binding/accounting and capture reuse. The current-source gfx950 flush/stride suites pass 32 tests with no skips.

Squash message:

Fix ReplaySSM flush record ordering

Wait for every value slice to finish reading the old k/g records before
the last arriving slice overwrites them. Keep arrival counters with the
record pools and select WAIT during initialization. Cover native and
SGLang wiring and fallback record ownership in CPU tests.

The fused KDA update and its tests are delivered with their caller in #3628.
All fallback timings, source and measurement scope

Base 659c3ba49cd5; head 0934f5b0e54b. Medians of 20 alternating base/head pairs per configuration on one gfx950 MI355X GPU. Each sample is the fallback kernel's profiler duration from one graph replay; state reset copies, Python wrappers and compilation are excluded. Inputs are warm after reset. The fixed cursor is 16-2*T for non-flush and 16-T for flush, so every measured launch has the stated mode; CAP=16.

GDN uses H=4, HV=16; KDA H=HV=12; K=V=128. Q/k/v and k/u records are BF16; buf_g is FP32. GDN checkpoint is BF16; KDA checkpoint FP32. L2 normalization is enabled, and KDA uses lower_bound=-5. Default fallback launch choices are unchanged; no fused conv/f_b path is timed.

Op bs T Flush Base µs Head µs Δ µs (%)
GDN 1 1 no 4.70 4.52 -0.18 (-3.82%)
GDN 1 1 yes 6.52 6.84 +0.32 (+4.92%)
GDN 1 2 no 4.06 4.04 -0.02 (-0.49%)
GDN 1 2 yes 4.64 5.76 +1.12 (+24.14%)
GDN 1 4 no 5.72 5.64 -0.08 (-1.39%)
GDN 1 4 yes 6.26 7.44 +1.18 (+18.84%)
GDN 16 1 no 6.06 6.40 +0.34 (+5.61%)
GDN 16 1 yes 9.80 10.24 +0.44 (+4.49%)
GDN 16 2 no 11.12 11.16 +0.04 (+0.36%)
GDN 16 2 yes 17.92 17.96 +0.04 (+0.22%)
GDN 16 4 no 14.02 14.20 +0.18 (+1.28%)
GDN 16 4 yes 19.72 21.50 +1.78 (+9.02%)
GDN 64 1 no 15.88 15.92 +0.04 (+0.25%)
GDN 64 1 yes 27.20 28.28 +1.08 (+3.97%)
GDN 64 2 no 21.40 21.98 +0.58 (+2.71%)
GDN 64 2 yes 26.68 27.68 +1.00 (+3.75%)
GDN 64 4 no 33.48 34.06 +0.58 (+1.73%)
GDN 64 4 yes 38.32 38.76 +0.44 (+1.15%)
GDN 256 1 no 53.54 53.40 -0.14 (-0.26%)
GDN 256 1 yes 83.62 87.12 +3.50 (+4.19%)
GDN 256 2 no 70.18 70.08 -0.10 (-0.14%)
GDN 256 2 yes 89.24 90.72 +1.48 (+1.66%)
GDN 256 4 no 111.88 111.58 -0.30 (-0.27%)
GDN 256 4 yes 128.40 130.56 +2.16 (+1.68%)
KDA 1 1 no 5.76 5.12 -0.64 (-11.11%)
KDA 1 1 yes 6.28 6.16 -0.12 (-1.91%)
KDA 1 2 no 6.76 6.00 -0.76 (-11.24%)
KDA 1 2 yes 7.16 7.08 -0.08 (-1.11%)
KDA 1 4 no 8.52 7.76 -0.76 (-8.92%)
KDA 1 4 yes 8.96 9.08 +0.12 (+1.34%)
KDA 16 1 no 8.72 8.12 -0.60 (-6.89%)
KDA 16 1 yes 11.76 11.44 -0.32 (-2.72%)
KDA 16 2 no 10.00 9.52 -0.48 (-4.80%)
KDA 16 2 yes 13.10 12.66 -0.44 (-3.36%)
KDA 16 4 no 12.46 11.96 -0.50 (-4.01%)
KDA 16 4 yes 15.62 15.44 -0.18 (-1.15%)
KDA 64 1 no 21.42 23.48 +2.06 (+9.62%)
KDA 64 1 yes 31.44 34.18 +2.74 (+8.72%)
KDA 64 2 no 24.08 26.64 +2.56 (+10.63%)
KDA 64 2 yes 32.92 38.48 +5.56 (+16.89%)
KDA 64 4 no 29.98 34.56 +4.58 (+15.28%)
KDA 64 4 yes 37.10 44.44 +7.34 (+19.79%)
KDA 256 1 no 68.88 85.18 +16.30 (+23.67%)
KDA 256 1 yes 102.88 138.02 +35.14 (+34.16%)
KDA 256 2 no 80.00 101.50 +21.50 (+26.88%)
KDA 256 2 yes 111.76 145.72 +33.96 (+30.39%)
KDA 256 4 no 100.28 132.66 +32.38 (+32.29%)
KDA 256 4 yes 131.72 167.66 +35.94 (+27.28%)

GDN non-flush medians change by -0.30 to +0.58 µs. Its largest relative flush increase, +24.14%, is 1.12 µs at bs1/T2. At bs256 the GDN ranges overlap, so the small positive medians need cautious interpretation. KDA bs1/16 is generally faster or close; all bs64/256 cases are slower. Every one of those larger KDA configurations has 20/20 positive paired differences, with head p10 above base p90 in this run. Those costs warrant disposition independently of the 32 passing GPU correctness cases.

The matching CAP16 KDA compiler outputs use one warp, three stages and 16 KiB shared memory in both arms. Total vector registers rise from 234 to 269 (256 VGPR plus 13 AGPR); the compiler's reported occupancy drops from 2 to 1. Both report zero scratch bytes. This is consistent with a compiled-resource contribution to non-flush costs; it is not a causal ablation of synchronization or gate factoring.

Runtime: AITER 183a6ce66ebb975223534f3bdeaca4132d2f4530; Torch distribution 2.10.0+rocm7.2.4.lw.git3d3aa833; Triton 3.8.0+amd.rocm7.2.0.git7cb7b059; HIP 7.2.53211; amdgpu 6.16.13. One GPU was assigned on a shared node. Profiler cycle/duplicate-flow warnings were retained; all 1,920 target-kernel events matched the sample arrays. This is one run, not a repeatability or end-to-end throughput claim.

@valarLip valarLip added ci:atom and removed ci:sglang agent-team/hold-landing Holds landing only; development and review go on ci:atom labels Nov 25, 2026

@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.

⚠️ Action required before merge (5)

Thanks for moving the fused update to #3628 and for the pool-owned counters. We re-traced the flush ordering at this head (wait + barrier before the counted arrival, last arrival owns the k/g stores and resets the counter, every record store under owns_kg) and it is correct. The new CPU guards ran in Pre Checkin.

  1. Remove the KDA fallback slowdown on non-flush steps. Your gfx950 A/B shows _replayssm_kda_fwd_kernel +16–32 µs per layer at bs256 without a flush (+2–5 µs at bs64) and +34–36 µs with one, with VGPRs 234→269 and occupancy 2→1. Non-flush steps do no extra sync, so this is codegen cost of where _owns_kg_records sits (replayssm.py:1782; GDN :900, :982), not the price of the fix, and it hits every KDA layer on the default MTP path. Please bring non-flush back to main's time and flush close to GDN's 1–3 µs, then repost the bs64/256 rows (gfx950, and gfx942 since it is a listed target). One thing to try: call _owns_kg_records after b_h += _replay_dot(...), when the records are already consumed, so the wait is nearly free and b_kw/b_ru are not live across the asm and barrier.

Nits (still need a change):

  1. Move _kda_log_decay to #3628. replayssm.py:1654-1670 has one caller here; it only served the fused kernel, and your timing note says the KDA A/B includes this factoring.

  2. Revert the import rewrap in tests/test_aiter_flydsl_gdn.py:628-630; it changes nothing.

  3. Update the slot_indexed_caches docstring (gdn_attn.py:85-90). It says anything added to the pool belongs in that list; replayssm_flush_arrivals is in the pool and correctly left out. Say that per-launch scratch which is zero between launches is excluded.

  4. Use the three-line header in the new test file. tests/model_ops/test_replayssm_flush_order_gpu.py:1-2 lacks # Copyright (c) 2026 ATOM Project Contributors, which main's CLAUDE.md (from #3736) now requires on every new file.

Please also resolve the two open valar-cop threads (config.py:85 is fixed; the fused-kernel thread is moot).


Reviewed at dd0b942 (Deep, re-review round 2, passes A+B; both raise item 1). Already fixed: fused update moved to #3628, per-launch host cost (pool-owned counters, WAIT at init), CPU wiring/ownership guards, squash text, mp_page_layout roles. CI: Pre Checkin green; heavy ATOM Test Gate failure is a cancelled superseded run, new run pending.

@whx-sjtu

whx-sjtu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Part of review 6058597895, @valarLip: the requested gfx942 rows are now measured. They expose a GDN regression of up to 52.69%. I am validating a small correction that moves generic GDN ownership selection after its replay GEMM; it is not yet a validated performance fix. Current f0287a38 preserves the measured kernel.

Requested gfx942 KDA/GDN rows

MI308X/gfx942, native compilation, unchanged timing method and numerical inputs. Two passes, 20 alternating pairs per case; each CUDA-event span covers 16 independent-state calls and is divided by 16. All 48 pass/case rows and 1,920 positive raw spans are retained. Maximum arm-median drift: 1.14%.

Path Batch T Flush Main µs Head µs Delta µs Delta %
GDN 64 1 no 48.274 46.742 -1.533 -3.17%
GDN 64 1 yes 113.642 118.633 +4.991 +4.39%
GDN 64 2 no 73.839 104.867 +31.028 +42.02%
GDN 64 2 yes 124.983 153.081 +28.098 +22.48%
GDN 64 4 no 115.397 166.234 +50.837 +44.05%
GDN 64 4 yes 154.957 213.563 +58.605 +37.82%
GDN 256 1 no 161.952 153.934 -8.019 -4.95%
GDN 256 1 yes 374.311 387.188 +12.876 +3.44%
GDN 256 2 no 246.394 370.305 +123.911 +50.29%
GDN 256 2 yes 384.027 509.365 +125.337 +32.64%
GDN 256 4 no 394.424 599.913 +205.489 +52.10%
GDN 256 4 yes 478.613 730.812 +252.199 +52.69%
KDA 64 1 no 92.947 92.466 -0.481 -0.52%
KDA 64 1 yes 143.047 151.661 +8.614 +6.02%
KDA 64 2 no 110.734 109.976 -0.759 -0.69%
KDA 64 2 yes 160.497 166.302 +5.805 +3.62%
KDA 64 4 no 147.005 145.826 -1.179 -0.80%
KDA 64 4 yes 196.084 200.601 +4.518 +2.30%
KDA 256 1 no 339.737 337.077 -2.660 -0.78%
KDA 256 1 yes 492.081 532.112 +40.032 +8.14%
KDA 256 2 no 409.911 406.436 -3.475 -0.85%
KDA 256 2 yes 561.331 584.609 +23.278 +4.15%
KDA 256 4 no 550.746 546.002 -4.744 -0.86%
KDA 256 4 yes 714.551 738.470 +23.919 +3.35%
Source: main 031d4da2671e, head 88131eaba8; the current main/head kernel identities were audited before this run. Native runtime: Torch 2.10.0+rocm7.2.4.git3d3aa833, HIP 7.2.53211, Triton distribution 3.8.0+amd.rocm7.2.0.git7cb7b059, image d49be4a1b03b.

Benchmark assertions passed: finite head outputs, zero counters, immutable readonly inputs, disjoint storage, and exact nonflush main/head outputs. This does not rerun the full 32-case numerical suite or model qualification. Results SHA256: 5814443680af74fd88134f78ed312ce62b84844bfbf503c3baeef6cab69f1b8c.

Retained gfx950 resources, ordering ablation and timings

Part of review 6058597895, @valarLip: 88131eaba8 uses 236 VGPRs and compiler occupancy 2. Removing only wait/barrier changed flush by -0.399 µs (-0.32%): the explicit pair is not dominant. The residual gap is 16.843 µs; this proves neither a minimum nor the unsafe control's correctness.

Source-bound gfx950 resources and requested ablation

Main 031d4da2671e versus full 88131eaba8 versus a private clone dropping only the explicit wait and barrier. The atomic, counter reset, last-owner selection, math and all checkpoint/record stores remain. False reproduces the full head's compiled instructions/resources; actual GPU codegen matches the CPU gate.

Compiler metric Main Full Drop wait/barrier
VGPRs / SGPRs 234 / 70 236 / 78 236 / 78
Spills / scratch 0 / 0 0 / 0 0 / 0
LDS 16 KiB 16 KiB 16 KiB
Compiler occupancy 2 2 2

These are static compiler figures. The full-to-diagnostic ISA difference is deletion of the explicit s_waitcnt vmcnt(0) and one input v_mov. The one-wave barrier emits no hardware s_barrier. The residual includes counted arrival, winner/reset and their lowering; it is not isolated atomic latency. The atomic-result wait and LDS broadcast remain. The unsafe control is not adopted.

bs256/T1, CAP16, H=HV12, K=V128, BV32, one wave/three stages; non-flush h14, flush h15. Two passes of twenty balanced triples, sixteen independent mutable-state calls per graph. Values below are microseconds per call from ordinary event spans divided by 16, including amortized graph/event/submission overhead; reset copies and warmup are outside. They are not profiler kernel-only or model-throughput results.

Mode Pass Main Full Drop pair Full-main Drop-full Paired median drop-full
Non-flush 1 67.537 67.451 67.471 -0.086 +0.020 -0.044
Non-flush 2 67.498 67.553 67.296 +0.055 -0.258 -0.345
Flush 1 106.633 123.875 123.504 +17.241 -0.371 -0.371
Flush 2 106.498 123.780 123.306 +17.281 -0.474 -0.579

Pooled forty-sample flush medians: 106.591/123.832/123.434 µs (main/full/drop). Drop-full paired median: -0.444 µs; 30/40 triples favor drop and ten do not. Maximum pass drift: 0.260%. The small deletion effect leaves nearly all the gap and does not establish unavoidable overhead in every correct implementation.

The four end-of-row observations found finite diagnostic outputs and no mismatched output/checkpoint/k/u/g replicas. Only the final replay's sixteen replicas were inspected per row; this does not validate the weakened ordering guarantee. The prior 32-case full-head pass remains separate, and production synchronization is unchanged.

Actual runtime: gfx950, g48 GPU1, image ID 72817ab903cf; Torch 2.10.0+rocm7.2.4.git3d3aa833, HIP 7.2.53211, Triton 3.8.0+amd.rocm7.2.0.git7cb7b059, AITER 183a6ce66ebb. All 240 whole spans and normalized samples are retained. Archive SHA256: 14a81505340f07c1280d344ec263ca45eaed0d1ae7c19b223af9554e0ed27978.

Earlier source fixes and complete gfx950 matrix, including batch 1

Fixes the source nits from your review, in 88131eaba8: inline gate, import, scratch docstring and header. Helper retained in #3628: 2c655b178f.

Main 031d4da2671e versus 88131eaba8c7, g27 GPU0. All 32 existing flush/strided numerical cases passed with zero skips. Two complete passes, twenty alternating pairs per row; each graph contains sixteen sequential fallback calls with independent identical mutable state. All 2,080 raw whole spans are retained and divided by sixteen without overhead subtraction. Reset copies and warmup are outside the event span; graph/event/submission overhead and inter-node gaps are included. These are not profiler kernel-only times or model throughput.

Table values are microseconds per call: pooled forty-sample medians per arm, their signed difference, and each pass's separate median difference. All per-arm pass drift was below 2%. KDA non-flush differences are below that scale; do not interpret the small negative values as a demonstrated speedup. Every KDA flush row was slower in all forty pairs, including batch 1. GDN's large-batch flush cost is also visible in this method.

Path Batch T Flush Main µs 88131 µs Delta µs Delta % Pass-1/2 delta µs
GDN 64 1 no 20.431 20.882 +0.450 +2.20% +0.424/+0.484
GDN 64 1 yes 31.264 33.115 +1.851 +5.92% +1.944/+1.844
GDN 64 2 no 25.400 25.458 +0.057 +0.23% +0.176/-0.014
GDN 64 2 yes 31.787 32.269 +0.482 +1.52% +0.427/+0.495
GDN 64 4 no 35.784 35.830 +0.046 +0.13% -0.001/-0.020
GDN 64 4 yes 41.805 42.254 +0.449 +1.07% +0.367/+0.548
GDN 256 1 no 55.609 56.993 +1.384 +2.49% +1.400/+1.463
GDN 256 1 yes 83.253 90.932 +7.679 +9.22% +7.655/+7.556
GDN 256 2 no 70.920 70.871 -0.049 -0.07% -0.117/-0.105
GDN 256 2 yes 88.576 93.822 +5.246 +5.92% +4.896/+5.291
GDN 256 4 no 110.196 110.078 -0.119 -0.11% +0.199/-0.075
GDN 256 4 yes 125.815 128.284 +2.469 +1.96% +2.643/+2.105
KDA 1 1 no 7.443 7.325 -0.118 -1.58% -0.107/-0.033
KDA 1 1 yes 7.821 8.461 +0.640 +8.18% +0.671/+0.616
KDA 64 1 no 25.579 25.615 +0.036 +0.14% +0.063/+0.060
KDA 64 1 yes 36.399 37.934 +1.535 +4.22% +1.451/+1.635
KDA 64 2 no 27.890 27.910 +0.020 +0.07% -0.075/+0.132
KDA 64 2 yes 37.762 38.877 +1.115 +2.95% +0.813/+1.314
KDA 64 4 no 32.800 32.938 +0.138 +0.42% -0.016/+0.196
KDA 64 4 yes 42.085 43.333 +1.248 +2.96% +1.013/+1.464
KDA 256 1 no 67.517 67.287 -0.230 -0.34% -0.208/-0.305
KDA 256 1 yes 105.712 123.075 +17.363 +16.42% +17.414/+17.336
KDA 256 2 no 77.317 76.960 -0.358 -0.46% -0.393/-0.328
KDA 256 2 yes 114.021 126.988 +12.966 +11.37% +12.614/+13.098
KDA 256 4 no 97.297 96.856 -0.441 -0.45% -0.450/-0.315
KDA 256 4 yes 131.994 139.850 +7.856 +5.95% +7.864/+7.959

Geometry: GDN H4/HV16, KDA H12/HV12; K=V=128, CAP16; non-flush cursor 16-2T, flush cursor 16-T. BF16 q/k/v and k/u, FP32 g, BF16 GDN checkpoint and FP32 KDA checkpoint; q/k normalization enabled, KDA lower bound -5. Seed103; three eager and three graph warmups per arm. Actual runtime: Torch 2.10.0+rocm7.2.4.git3d3aa833, HIP 7.2.53211, Triton 3.8.0+amd.rocm7.2.0.git7cb7b059, AITER 183a6ce66ebb975223534f3bdeaca4132d2f4530, amdgpu 6.16.13; image ID 72817ab903cf34722c670527a224c3177317fa2f6dc6f87fbd63acad52d623bb.

Evidence archive SHA256: 9b72d7af0933e511761e0999b07bade9f8ce16d55cd3edec0a3ba4171009c75c. The earlier unsupported event-API admission produced zero samples and ran no numerical tests; that failure is retained separately. These earlier timings cover gfx950; no full-model result is claimed.

@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.

⚠️ Action required before merge (1)

Thanks for moving the arrival after the replay dot. KDA non-flush steps are now at parity with main (bs64 +0.02–0.14 µs, bs256 −0.2–0.4 µs), and bs64 flush is +1.1–1.5 µs, in line with GDN. We re-traced the kernel at this head: every record tile is consumed by the dot before the wait + barrier + counted arrival, the last arrival owns the k/g stores and resets the counter, non-flush keeps slice 0 as owner, and every buf_k/buf_g store sits under owns_kg. The ordering is still correct.

  1. KDA bs256 flush is still about 2–3× GDN's cost (fla_ops/replayssm.py:1779). Your table shows +17.4 / +13.0 / +7.9 µs per call at T=1/2/4, while GDN under the same method costs +7.7 / +5.2 / +2.5 µs. A flush happens every few steps on every KDA layer, so this is still above 1 µs per layer per step at bs256. Please do one of these:

    • bring it down close to GDN, or
    • post the head's compiled VGPR count and occupancy for _replayssm_kda_fwd_kernel, plus an ablation (drop only the atomic, or only the wait + barrier) showing that what remains is the cost of the ordering itself. If it is, we will accept it.

    Either way, please add the bs64/256 KDA and GDN rows on gfx942. It runs the same default fallback kernel (the WAIT table covers gfx942), and its codegen and occupancy differ from gfx950.

Prior asks: (1) partly fixed (non-flush done; bs256 flush and gfx942 rows open), (2) _kda_log_decay moved to #3628 and _kda_gate matches main, (3) import rewrap reverted, (4) slot_indexed_caches docstring updated, (5) three-line header added. Both valar-cop threads are resolved.


Reviewed at 88131ea (re-review, Deep; 1 pass, request_changes). Already fixed: KDA non-flush codegen slowdown, _kda_log_decay move, import revert, scratch docstring, test header, open threads; earlier rounds: fused update in #3628, pool-owned counters, CPU guards, squash text. CI: all checks green at head.

@ganyi1996ppo ganyi1996ppo 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.

Thanks. I re-traced the arrival/ownership logic and found no new correctness issue; the open items are the ones already listed in the existing reviews (KDA bs256 flush cost, gfx942 rows). One small non-blocking suggestion inline.

Comment thread atom/model_ops/attentions/gdn_attn.py Resolved
@whx-sjtu

whx-sjtu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Part of review 6058597895, @valarLip: 2a7471e1 fixes the large GDN gfx942 regression. At batch 256 with four tokens, nonflush is -0.39% and flush +0.81% versus main; the same-session parent was approximately 52% slower. Exact output/state checks passed and compiler occupancy returned to 2.

The PR's Testing section contains the full matrix and source scope. Gfx950 short validation and KDA ordering-cost attribution remain in progress.

ganyi1996ppo
ganyi1996ppo previously approved these changes Nov 26, 2026

@ganyi1996ppo ganyi1996ppo 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.

Fresh pass at head e5187fd21 (rebased from 2a7471e1, no content diff in the touched files — verified git diff 2a7471e1 e5187fd21 -- <touched files> is empty).

Previous inline suggestion (gdn_attn.py, self.replayssm_flush_wait not initialized in __init__): fixed. 0ecb85ee5 ("Initialize ReplaySSM flush wait in the shared builder") is an ancestor of the current head and adds self.replayssm_flush_wait = None to GDNStateMixin.__init__, covering both GDN and Kimi builders as confirmed in-thread. No longer an issue.

Correctness re-trace, independent of valarLip's rounds: I checked i_v/i_hv really are tl.program_id(0)/tl.program_id(1) (confirmed at the kernel signatures, replayssm.py:764/:1716), so owns = tl.program_id(0) == 0 in _owns_kg_records is exactly the old non-flush owner (i_v == 0) — no behavior change there. All four owns_kg = _owns_kg_records(...) call sites (GDN main path, GDN T1_FAST, GDN chunked tail, KDA) pass identical arguments, so there's no twin-divergence between the GDN and KDA copies of this pattern. The arrival-counter buffer is sized [num_slots, HV] and addressed flush_arrivals + slot*HV + i_hv consistently between the allocator (sk[0] = num_v_heads in _replayssm_bytes_per_slot/allocate_per_req_cache) and the kernel. The new test_fallback_record_stores_have_an_owns_kg_guard AST check (CPU lane) does correctly catch a store to buf_k/buf_g-derived pointers outside an if owns_kg: guard, including through the p_bk/p_bkt/p_bg2 aliases. I found no new correctness defect.

CI: Run non-GPU unit tests / Check Pre Checkin Signal / ATOM Test Gate were red on the pre-merge head (2a7471e1) solely due to tests/test_lmcache_mp.py::...AssertionError: output.failed_loading == {load_operation} — a file untouched by this diff. The same job fails intermittently on main too, with a different unrelated test each time over the last several runs (e.g. kimi_k3/model.py:1030 AttributeError: 'SimpleNamespace' object has no attribute 'tr_graph' on another recent main run) — baseline flakiness, not a regression from this PR. A fresh CI run is in progress at the current head (e5187fd21, run 45810861239 et al.).

Open items are the ones already tracked in the existing review thread (valarLip, 2026-11-25 13:36): KDA bs256 flush overhead still ~2-3x GDN's, and gfx942 A/B rows requested — nothing to add there from this pass.

@whx-sjtu

Copy link
Copy Markdown
Contributor Author

Part of review 6073409275, @ganyi1996ppo @valarLip: the gfx942 raw matrix, controls, codegen checks and executed timing code are public.

Current e5187fd21 preserves 2a7471e1's kernel exactly. The generic GDN regression is corrected: batch 256/four-token nonflush -0.39%, flush +0.81% versus main, with exact parent/candidate state/output checks. KDA's remaining gfx950 ordering-cost validation is separate and remains pending.

@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.

⚠️ Action required before merge (2)

Thanks for the gfx942 rows and for 2a7471e. Moving the GDN arrival after the replay dot removes the ~52% gfx942 regression (bs256 T=4: −0.39% non-flush, +0.81% flush), and occupancy is back to 2. We re-traced the GDN kernel at this head. In both the T=1 and the multi-token paths, all record tiles are loaded (multi-token: consumed by the dot) before the wait, barrier and counted arrival. owns_kg is set before every use, and every buf_k/buf_g store still sits under it. KDA's arrival (replayssm.py:1780) is in the same place. The ordering is correct.

  1. Close out the KDA flush cost (fla_ops/replayssm.py:1780). It is still 2–6× GDN's on both architectures:

    • gfx950 bs256: +17.4 / +13.0 / +7.9 µs per call at T=1/2/4 (GDN: +7.7 / +5.2 / +2.5)
    • gfx942 bs256: +40.6 / +22.4 / +25.0 µs (GDN at head: +12.7 / +4.0 / +3.9)
    • gfx942 bs64: +8.7 / +6.2 / +4.7 µs (GDN at head: +4.9 / −0.05 / −0.4)
      (gfx942 numbers from the 2a7471e table in your Testing section.)

    VGPRs (236 vs 234) and occupancy (2) on gfx950 match main, and dropping only the wait + barrier saves just 0.4 µs. So ~16.8 µs sits in the counted arrival, winner selection and reset, which nothing has isolated yet. You say this attribution is still pending. Please either:

    • bring KDA flush close to GDN, or
    • post the remaining ablation on gfx950 and gfx942: keep the wait + barrier, drop only the atomic and use a fixed owner (diagnostic only). Also give the KDA VGPR count and occupancy on gfx942, and say why KDA's arrival costs 2–6× GDN's. If what remains is the arrival itself, we will accept it.
  2. Re-post the gfx950 GDN T=2/4 rows at e5187fd (bs64/256, flush and non-flush). 2a7471e changed the codegen of the default GDN multi-token path. On gfx942 that same placement decided occupancy (1 vs 2), but there is no gfx950 data at this head. Your Testing section lists this as still to do.

Prior asks: (1a) KDA flush close to GDN: not fixed. (1b) VGPR/occupancy plus ablation: partly done (gfx950 resources and the wait + barrier half posted; the atomic half is missing). (1c) gfx942 bs64/256 KDA+GDN rows: done; they exposed the GDN regression, now fixed. Earlier nits (_kda_log_decay move, import revert, scratch docstring, test header) still hold at head. ganyi1996ppo's replayssm_flush_wait thread is fixed by 0ecb85e (GDNStateMixin.__init__ covers the GDN and Kimi builders); please resolve it.


Reviewed at e5187fd (re-review vs 88131ea; 1 pass, request_changes). Already fixed: gfx942 GDN multi-token regression (2a7471e), replayssm_flush_wait init, gfx942 rows posted; earlier rounds: KDA non-flush parity, fused update in #3628, pool-owned counters, CPU guards, squash text. CI: light checks green, heavy accuracy jobs still pending.

@whx-sjtu

Copy link
Copy Markdown
Contributor Author

@valarLip Completed the gfx942 follow-up. Part of your latest review is addressed by these raw results. Retaining wait/barrier while removing counted arrival, winner selection and reset reduces batch-256 KDA flush excess from +40.095/+22.878/+25.944 us to -0.473/-0.563/+0.621 us versus main (T=1/2/4). Occupancy remains 1. Fixed ownership is unsafe diagnostic code. This isolates the current arrival path without proving cache serialization. Matching gfx950 KDA ablation and current-head GDN rows remain pending.

gfx942 three-arm results, native resources and attribution

KDA gfx942: main / full head / fixed owner

MI308X/gfx942. Main 031d4da2671e; full head e5187fd21c (kernel identical to 2a7471e1). The fixed-owner variant retains the wait and barrier, removes counted arrival/winner selection/reset, and uses program_id(0) == 0. It is unsafe diagnostic code and is never a production or correctness-qualified variant.

Two passes, 20 balanced triples per case and 16 independent-state calls per event span. Reset/warmup is excluded; graph/event/submission overhead remains. The 1,440 positive spans, normalization, order, percentiles and paired differences were independently recomputed; maximum arm median pass drift is 0.409%. Arm columns are pooled medians in microseconds per call. Delta columns are medians of matched per-sample differences, which need not equal subtraction of the pooled medians.

Batch T Flush Main us Full us Fixed us Full-main paired us Fixed-full paired us Fixed-main paired us
256 1 no 339.783 337.257 339.928 -2.464 +2.701 +0.233
256 1 yes 492.217 532.461 491.368 +40.095 -41.153 -0.473
256 2 no 410.154 406.829 410.391 -3.372 +3.599 +0.206
256 2 yes 563.205 586.049 562.729 +22.878 -23.200 -0.563
256 4 no 553.515 549.246 553.198 -4.286 +4.015 -0.301
256 4 yes 715.685 741.500 716.218 +25.944 -25.383 +0.621
64 1 no 93.017 92.514 93.147 -0.500 +0.639 +0.098
64 1 yes 142.795 151.982 142.965 +9.145 -9.005 +0.247
64 2 no 110.609 109.978 110.812 -0.651 +0.829 +0.171
64 2 yes 160.439 166.481 160.792 +6.119 -5.813 +0.336
64 4 no 147.715 146.390 147.488 -1.337 +1.111 -0.220
64 4 yes 196.428 200.838 196.606 +4.182 -4.334 +0.164

Native KDA gfx942 resources

Arm VGPR AGPR Total vector registers SGPR Compiler occupancy LDS Scratch/spills
Main 256 2 258 74 1 16 KiB 0
Full head 256 1 257 78 1 16 KiB 0
Fixed owner 256 2 258 74 1 16 KiB 0

The diagnostic-disabled native instruction stream matches full head. All variants retain the same load/dot/reduction/scan counts. The fixed-owner change removes the atomic and counter reset while preserving the wait and barrier in IR. It crosses no occupancy tier. Here the single-wave barrier lowers without an s_barrier instruction.

What this isolates

At batch 256, the full-head flush excess is +40.095/+22.878/+25.944 us for T=1/2/4. Removing the current arrival/owner/reset sequence leaves fixed-owner-minus-main paired medians of -0.473/-0.563/+0.621 us. At batch 64, the corresponding residuals are +0.247/+0.336/+0.164 us. The current counted-arrival path, including its scheduling effects, accounts for essentially the observed gfx942 excess.

KDA has four arrivals per counter versus GDN's two, and 48N versus 32N arrivals overall (1.5 times as many). Both use a returning relaxed atomic and conditional reset; KDA does not use a heavier atomic opcode. That geometry differs, but counts alone do not establish a 2-6 times latency ratio. This ablation measures the combined arrival, returned-value winner selection, reset and scheduling cost. It does not separately measure cache serialization or prove a 64-byte cache-line mechanism.

Raw gfx942 result SHA256 before device-identifier redaction: 20dbec6a48709311fcf04b6801f98d4ecc95cd990ee3cd44cc6824d96a52caa6. The public sample arrays are unchanged; public hashes and the transformation are listed with the raw evidence.

@whx-sjtu

Copy link
Copy Markdown
Contributor Author

@whx-sjtu

Copy link
Copy Markdown
Contributor Author

Both gfx950 items are now measured. Raw results, codegen and the executed scripts: https://gist.github.com/whx-sjtu/31ef49dca1c13c8bb30956b8c7ac01e3

Same image digest as the earlier gfx950 table (72817ab903cf), one GPU, unchanged frozen timer. The candidate kernel hash 7fd5aea1... equals the value the gfx942 packet recorded, so both architectures measured the same bytes. Each runner differs from its gfx942 original in one line, the gfx950 admission assert.

2. GDN T=2/4 at e5187fd (bs64/256, flush and non-flush)

Batch T Flush Main µs Head µs Delta µs Delta %
64 2 no 25.545 25.620 +0.075 +0.29%
64 2 yes 31.882 32.424 +0.543 +1.70%
64 4 no 35.688 35.992 +0.304 +0.85%
64 4 yes 41.558 42.312 +0.754 +1.81%
256 2 no 70.886 70.985 +0.099 +0.14%
256 2 yes 89.018 93.936 +4.919 +5.53%
256 4 no 110.400 110.923 +0.522 +0.47%
256 4 yes 126.527 128.787 +2.260 +1.79%

These are within pass drift of the same rows at 88131eaba8, so the placement change does not regress GDN on gfx950. GDN native resources at bs256 flush: main 231 VGPR / occupancy 2, parent f0287a38 228 / 2, head 231 / 2, all zero spills and scratch, LDS 8 KiB. The head's multi-token ISA does differ from the parent's, so the codegen change is real, but occupancy is 2 for all three arms and the head's register total equals main's. The gfx942 occupancy 1 versus 2 effect has no gfx950 counterpart. The single-token path is byte-identical between parent and head.

All 48 strict controls passed: exact parent/head equality on outputs and every mutable state, counters zero, read-only inputs unchanged, independent checkpoint reference on all 24 flush rows. Maximum per-arm pass drift 2.097%, slightly above the 2% quoted for the earlier gfx950 table.

1. Remaining ablation on gfx950: keep wait + barrier, drop only the atomic

KDA flush rows, medians of matched per-sample differences:

Batch T Main µs Full head µs Fixed owner µs full−main fixed−main
64 1 36.654 38.392 36.607 +1.721 −0.024
64 2 37.969 39.371 38.053 +1.440 +0.046
64 4 42.028 43.591 42.022 +1.544 −0.006
256 1 106.848 122.785 106.250 +15.946 −0.668
256 2 114.289 126.911 113.733 +12.708 −0.568
256 4 132.443 139.942 131.380 +7.413 −1.122

Dropping only the counted arrival, winner selection and reset returns KDA flush to main's level on gfx950, reproducing the gfx942 result (−0.473/−0.563/+0.621). Non-flush rows are unaffected. Maximum per-arm pass drift 1.267%.

KDA native resources on gfx950, all occupancy 2, LDS 16 KiB, zero spills and scratch: main 234 VGPR / 70 SGPR, full head 236 / 78, fixed owner 234 / 70. So register pressure and occupancy do not explain the gap. The disabled-diagnostic control passed: with the ablation off, the diagnostic's normalized ISA is byte-identical to the full head.

To your question of why KDA's arrival costs 2–6× GDN's: what remains after this ablation is the arrival itself. KDA runs HV=12 value slices against GDN's HV=16 with a different per-slice record layout, so the same counted arrival, winner selection and reset is paid on a hotter, narrower path; the measurement isolates it to those operations and their scheduling effects, but does not separate atomic, returned-value, reset or cache-serialization contributions and does not prove a particular cache-line mechanism.

The diagnostic is unsafe private code and is not proposed for merge. These are operator timings on one GPU, not profiler kernel-only times and not a model-throughput result.

@whx-sjtu

Copy link
Copy Markdown
Contributor Author

Ready for re-review, @valarLip: the remaining measurements are complete. The gfx950 results cover all eight GDN configurations and the KDA ablation; matching gfx942 evidence is published. With wait/barrier retained, KDA's excess is attributed to arrival/owner/reset. KDA has four arrivals per counter versus GDN's two (1.5× total arrivals); individual cache/scheduling contributions remain unisolated. Fixed ownership is diagnostic only. GDN's 2.097% pass drift is disclosed. Please re-review.

@whx-sjtu

whx-sjtu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Ready for re-review, @valarLip: the requested measurements are supplied. The production KDA flush overhead remains. The fixed-owner ablation diagnoses the arrival/owner/reset cost and is not a production fix. Gfx942 resource counts and the matching ablation are already complete.

Corrected measurements, resources and scope

gfx950 follow-up: both open items are now measured

Raw results, codegen and the executed scripts: https://gist.github.com/whx-sjtu/31ef49dca1c13c8bb30956b8c7ac01e3

Run on one MI355X/gfx950 with the same image digest as the earlier gfx950 table (rocm/atom-dev@sha256:72817ab903cf...), Torch 2.10.0+rocm7.2.4.git3d3aa833, HIP 7.2.53211, Triton 3.8.0+amd.rocm7.2.0.git7cb7b059. The candidate kernel hashes 7fd5aea18d8e0180a33c377e804b9bd96e5155a37df7880d39c2bc15c191f809, the same value the gfx942 packet recorded, so both architectures measured the same bytes. Each runner differs from its gfx942 original in exactly one line, the assert "gfx950" in device admission; the timer, packet_common.py and replayssm_diag.py keep their gfx942 hashes.

Item 2 — GDN T=2/4 at e5187fd (bs64/256, flush and non-flush)

Pooled forty-sample medians, microseconds per call:

Batch T Flush Main Head Delta Delta %
64 2 no 25.545 25.620 +0.075 +0.29%
64 2 yes 31.882 32.424 +0.543 +1.70%
64 4 no 35.688 35.992 +0.304 +0.85%
64 4 yes 41.558 42.312 +0.754 +1.81%
256 2 no 70.886 70.985 +0.099 +0.14%
256 2 yes 89.018 93.936 +4.919 +5.53%
256 4 no 110.400 110.923 +0.522 +0.47%
256 4 yes 126.527 128.787 +2.260 +1.79%

(The bs64 T=2 non-flush row is +0.075 / +0.29%; the full 24-row table including T=1 is in the gist.)

These sit within pass drift of the same rows at 88131eaba8, so the ownership move in 2a7471e1 does not regress GDN on gfx950. GDN native resources at bs256 flush, zero spills and scratch, LDS 8 KiB: main 231 VGPR / occupancy 2, parent f0287a38 228 / 2, head e5187fd21 231 / 2. The head's multi-token normalized ISA does differ from the parent's, so the codegen change is real, but occupancy is 2 on all three arms and the head's register total equals main's — the gfx942 occupancy 1 versus 2 effect has no gfx950 counterpart. The single-token path is byte-identical between parent and head.

All 48 strict controls passed: exact parent/head equality on outputs and on every mutable state, arrival counters zero, read-only inputs unchanged, and the independent checkpoint reference on all 24 flush rows. Maximum per-arm pass drift 2.097%, which I should flag as slightly above the 2% quoted for the earlier gfx950 table.

Item 1 — the remaining ablation on gfx950

Keep the wait and barrier, drop only the counted arrival, winner selection and reset, fixed program_id(0)==0 owner. KDA flush rows, medians of matched per-sample differences:

Batch T Main Full head Fixed owner full−main fixed−main
64 1 36.654 38.392 36.607 +1.721 −0.024
64 2 37.969 39.371 38.053 +1.440 +0.046
64 4 42.028 43.591 42.022 +1.544 −0.006
256 1 106.848 122.785 106.250 +15.946 −0.668
256 2 114.289 126.911 113.733 +12.708 −0.568
256 4 132.443 139.942 131.380 +7.413 −1.122

The fixed-owner diagnostic returns KDA flush to main's level on gfx950, reproducing the gfx942 result (−0.473/−0.563/+0.621 there). Non-flush rows are unaffected. Maximum per-arm pass drift 1.267%.

KDA native resources on gfx950, all occupancy 2, LDS 16 KiB, zero spills and scratch: main 234 VGPR / 70 SGPR, full head 236 / 78, fixed owner 234 / 70. There is no occupancy loss or spill regression between these arms; the counted-arrival path can still affect instruction scheduling. The disabled-diagnostic control passed: with the ablation off, the diagnostic's normalized ISA is byte-identical to the full head.

Together with the earlier wait/barrier ablation, these measurements attribute most of the observed KDA excess to the current counted-arrival, winner-selection and reset path, including its scheduling effects. HV counts value heads, not value partitions: KDA uses HV=12 and NV=4 partitions per head, while GDN uses HV=16 and NV=2. KDA therefore has four arrivals per counter versus two, and 48N versus 32N arrivals overall (1.5 times as many). These counts alone do not establish the 2–6 times latency ratio; individual atomic, returned-value, reset and cache-serialization contributions remain unisolated.

The diagnostic is unsafe private code and is not proposed for merge. These are operator timings on one GPU, not profiler kernel-only times and not a model-throughput result. The gfx942 KDA resource counts and matching ablation are already complete: main/full/fixed-owner use 256 VGPR plus 2/1/2 AGPR, respectively, with occupancy 1 throughout, 16 KiB LDS and zero spills/scratch.

The production full-head path still pays the measured flush overhead: +15.946/+12.708/+7.413 microseconds per call at batch 256 and T=1/2/4. The diagnostic removes correctness-critical coordination, so its timing is not a delivered optimization. These measurements do not prove that the production implementation cannot be optimized further.

@valarLip
valarLip merged commit 2610191 into main Nov 27, 2026
145 of 147 checks passed
@valarLip
valarLip deleted the task-693-main-kda-fused branch November 27, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants