Repository navigation
Fix ReplaySSM flush record ordering - #3618
Conversation
whx-sjtu
left a comment
There was a problem hiding this comment.
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.
valar-cop
left a comment
There was a problem hiding this comment.
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.
whx-sjtu
left a comment
There was a problem hiding this comment.
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.
|
ci triage for e5187fd:
|
whx-sjtu
left a comment
There was a problem hiding this comment.
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.
valarLip
left a comment
There was a problem hiding this comment.
⚠️ 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:
- 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:2290notes. 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'sfused_kda_decode_unified, which already fuses conv1d with the ReplaySSM KDA recurrence. When it moves, also assertconv_weight.dim() == 2(:2341): the kernel readsstride(1)as the tap stride, so annn.Conv1d-shaped[C, 1, 4]weight passes the assert and silently reads the wrong taps. - Remove the per-launch host cost of
_flush_arrivals/_flush_wait. These calls (replayssm.py:437-458, called at:1608and:1950) build a(device, data_ptr, shape)key, look it up in a dict and callget_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-eagerand 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 tobuf_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.
- 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):
- Add a CPU-lane guard for the new ordering wiring. Both
*_gpu.pyfiles skip in CI, so reverting anyif owns_kg:toif i_v == 0:, or droppingflush_arrivals/WAIT from the GDN_replayssm_fwd_kernelcall, still passes. Add the GDN twin of_check_wrapper_layoutplus an AST check that everybuf_k/buf_gstore in the two fallback kernels sits underowns_kg. Put both intests/model_ops/test_replayssm_kda_strides_cpu.py, which runs in the CPU lane. - 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.
|
Fixes the structural requests in this review at Requested source and test changes
The native allocator owns int32 arrival storage shaped Follow-up
Squash message: All fallback timings, source and measurement scopeBase 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.
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 |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ 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.
- 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_recordssits (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_recordsafterb_h += _replay_dot(...), when the records are already consumed, so the wait is nearly free andb_kw/b_ruare not live across the asm and barrier.
Nits (still need a change):
-
Move
_kda_log_decayto #3628.replayssm.py:1654-1670has one caller here; it only served the fused kernel, and your timing note says the KDA A/B includes this factoring. -
Revert the import rewrap in
tests/test_aiter_flydsl_gdn.py:628-630; it changes nothing. -
Update the
slot_indexed_cachesdocstring (gdn_attn.py:85-90). It says anything added to the pool belongs in that list;replayssm_flush_arrivalsis in the pool and correctly left out. Say that per-launch scratch which is zero between launches is excluded. -
Use the three-line header in the new test file.
tests/model_ops/test_replayssm_flush_order_gpu.py:1-2lacks# 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.
|
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 Requested gfx942 KDA/GDN rowsMI308X/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%.
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: Retained gfx950 resources, ordering ablation and timingsPart of review 6058597895, @valarLip: Source-bound gfx950 resources and requested ablationMain
These are static compiler figures. The full-to-diagnostic ISA difference is deletion of the explicit 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.
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 Earlier source fixes and complete gfx950 matrix, including batch 1Fixes the source nits from your review, in 88131eaba8: inline gate, import, scratch docstring and header. Helper retained in #3628: 2c655b178f. Main 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.
Geometry: GDN H4/HV16, KDA H12/HV12; K=V=128, CAP16; non-flush cursor Evidence archive SHA256: |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ 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.
-
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
left a comment
There was a problem hiding this comment.
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.
|
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
left a comment
There was a problem hiding this comment.
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.
|
Part of review 6073409275, @ganyi1996ppo @valarLip: the gfx942 raw matrix, controls, codegen checks and executed timing code are public. Current |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ 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.
-
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.
-
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.
|
@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 attributionKDA gfx942: main / full head / fixed ownerMI308X/gfx942. Main 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.
Native KDA gfx942 resources
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 What this isolatesAt 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: |
|
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 ( 2. GDN T=2/4 at e5187fd (bs64/256, flush and non-flush)
These are within pass drift of the same rows at 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 atomicKDA flush rows, medians of matched per-sample differences:
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. |
|
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. |
|
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 scopegfx950 follow-up: both open items are now measuredRaw 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 ( Item 2 — GDN T=2/4 at e5187fd (bs64/256, flush and non-flush)Pooled forty-sample medians, microseconds per call:
(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 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 gfx950Keep the wait and barrier, drop only the counted arrival, winner selection and reset, fixed
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. |
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.
88131eaba8moves 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_decaywith 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.e5187fd21gfx942 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%.
Sources: main
031d4da2671e, correct parentf0287a38(measured kernel equals88131eaba8), candidate2a7471e1. 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
031d4da2671eversus88131eaba8c7, 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.
Geometry: GDN H4/HV16, KDA H12/HV12; K=V=128, CAP16; non-flush cursor
16-2T, flush cursor16-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: Torch2.10.0+rocm7.2.4.git3d3aa833, HIP7.2.53211, Triton3.8.0+amd.rocm7.2.0.git7cb7b059, AITER183a6ce66ebb975223534f3bdeaca4132d2f4530, amdgpu6.16.13; image digest72817ab903cf34722c670527a224c3177317fa2f6dc6f87fbd63acad52d623bb.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 in88131eaba8.Main
659c3ba49cd5versus0934f5b0e54b: 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.