Skip to content

spark-model: DFlash2 step cuts — async batched propose + opt-in GDN deferred commit (#58) - #127

Merged
AzeezIsh merged 10 commits into
mainfrom
perf/dflash2-async-ctx-copies
Sep 28, 2026
Merged

AzeezIsh merged 10 commits into
mainfrom
perf/dflash2-async-ctx-copies

Conversation

@AzeezIsh

@AzeezIsh AzeezIsh commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cuts the DFlash2 batched-propose step (#58) without touching verify or outputs. At 16 sequences, propose was 249 ms of a 617 ms step on main (reiner job 596's profile: 48.5 % of CUDA API time in cuStreamSynchronize).

Commits:

  • 7d6ed0c: async ctx-precompute copies. The K/V row compaction and the position upload no longer pay a pipeline drain per row (~40 cuStreamSynchronize per sequence). They are stream-ordered async copies from pinned carve-outs, and the overflow path falls back to the old sync copy.
  • 33b181d: one batched ctx_kv_project over Σn_i rows per step instead of one per sequence. The first-fit planner keeps the per-sequence GEMV arm wherever it would have run, so rows stay byte-identical.
  • 0ebedeb: one dflash2_candidate_selector_batched launch (grid = n sequences) instead of n serial single-CTA launches (4.7 ms each), plus drafter LM-head GEMV waves for more than 32 rows.
  • e5f2f56: opt-in ATLAS_DFLASH_DRAFTER_CUBLAS=1 (cuBLASLt for drafter BF16 GEMMs at m>=32). Default off, because cuBLAS algorithm choice can move draft numerics and therefore acceptance, though never outputs.
  • 087c522 / da95e05: fixes found on reiner.
    • Two stale unit tests.
    • 0ebedeb dropped the per-sequence extern "C" dflash2_candidate_selector symbol, so the kernel audit refused boot in job 610.
    • Both selector entries are now pinned by a test.

Evidence (reiner job 611y, 2026-09-27)

Setup: DFlash2 γ=8, bs16, util 0.70, bf16 KV, thinking off, spark benchmark run concurrency-sweep C 1/4/8/16, ISL 512, OSL 320. A = main 10d4ec7, B = this branch @ da95e05, interleaved A/B/A/B.

Aggregate tok/s, C1 / C4 / C8 / C16:

arm C1 C4 C8 C16 propose n=16 verify n=16 accepted/step
A1 main 23.3 46.8 63.9 63.8 249 ms 368 ms 3.03
B1 23.2 50.4 62.9 75.7 163 ms 370 ms 3.08
A2 main 23.1 46.8 58.0 74.2 249 ms 369 ms 3.19
B2 23.2 49.1 59.7 75.8 163 ms 369 ms 3.05
C1 (B + drafter cuBLAS) 23.2 51.0 68.4 79.6 157 ms 369 ms 3.17

Step times (server-side means over ~70 steps per arm) are identical across reps:

  • propose drops 82→63 ms at n=4, 136→97 ms at n=8 and 249→163 ms at n=16;
  • verify is unchanged.

Caveat on the client aggregate: it is noisy at C8/C16 because mean acceptance moves 3.03–3.19 between runs of the same binary (A1 vs A2). Main's C16 has read 61.7–74.2 across six runs today, so the step-time drop is the primary evidence. The C16 aggregate on this branch was 75.7 and 75.8, above the 73.5 floor. Main was below it in 5 of 6 runs; that is being bisected separately in job 611zz.

Parity:

  • Greedy probe hashes A vs B are identical on all 5 prompts, including 7k-token needle retrieval and 256/136-token code/JSON decodes.
  • ATLAS_DFLASH_BATCH_PARITY=1: backbone parity 0/40960 mismatched, max_abs_diff 0.
  • 105/105 dflash_head unit tests pass on reiner.

Test plan

  • reiner job 611y: A/B, probe hashes and parity as above.
  • cargo test -p spark-model --lib dflash_head:: 105/105 (reiner and macOS).
  • CI: fmt, clippy, tests, nvcc -> PTX.
  • Integration-train gates (ST-995 and the perf legs) before merge, per the train policy.

Generated with Devin


Also in this PR: opt-in GDN deferred commit (folded in from #128)

ATLAS_GDN_DEFERRED_COMMIT=1 targets the wyN GDN verify (K=5..16), the top kernel in the DFlash2 C=16 profile. The lever is off by default, and lever-off behaves byte-identically to main.

  • gated_delta_rule_wy{K}_defer runs the same arithmetic but stores nothing: no per-token snapshots and no final H.
  • gated_delta_rule_commit replays the accepted prefix from H0 and stores only H_{a-1}.
  • The pending flag is set at every decode_verify* dispatch entry, outside graph capture. Staging lives in slot-bound pool buffers, so captured verify graphs replay correctly.

Commits (patch-identical to #128's, per git range-diff):

  • 08db26b: the lever.
  • e1d1036: build/run fixes. Undefined _defer macro, impl<K> arity, an eager then_some index, and a full-accept conv restore.
  • 4c13a0a: flag set at dispatch instead of inside the captured forward. This fixes the job-621 output drift.

Evidence (reiner job 625zzz, lever off vs on, interleaved ×2):

  • CUDA oracle gdn_deferred_commit_byte_identical passes.
  • Greedy probes are identical lever off vs on (5/5), and lever-off matches main 10d4ec7 (5/5).
  • Verify at n=16: 366 / 368 ms off, 269 / 269 ms on. At n=8: 240 vs 193 ms. At n=4: 195 vs 172 ms.
  • C16 aggregate: 74.0 / 69.0 off, 76.6 / 80.1 on. There were no vacuity flags and no errors.

Not yet measured: the two halves together on one binary. That's the next reiner A/B.

AzeezIsh and others added 6 commits September 27, 2026 03:02
…rains per sequence (#58)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…#58)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ws (#58)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…TLAS_DFLASH_DRAFTER_CUBLAS)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
plan_ctx_chunks is first-fit: a chunk that overflows the row cap goes
serial and later chunks that still fit keep packing, so [10, 10, 4] at
cap 16 is [Some(0), None, Some(10)] — the test expected the planner to
stop at the first overflow. The structural pin counted its own needle
literals via include_str!; it now counts only the production half.
Both failed on reiner (job 610 unit step); 105/105 dflash_head tests pass.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…#58)

0ebedeb turned the kernel body into df2_selector_body for the new
batched entry but never re-added the extern "C" per-sequence symbol, so
the audited load-time lookup resolved to handle 0 and every async-stack
serve refused to boot (reiner job 610, all B arms). Re-export it as a thin
wrapper over the shared body in the gb10 and strix-hip sources, and pin
both exported entry points in batched_selector_is_one_launch_with_fallback
(fails on 0ebedeb, passes now).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
AzeezIsh and others added 4 commits September 27, 2026 22:11
…#58)

[seq][gamma][width] parsed as intra-doc links and failed the rustdoc CI
job; quote it as code.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…OMMIT)

wyN verify (K=5..16, serial and batched) writes K-1 full h_state
snapshots + the final H per (seq, v-head, layer) — ~64 KB each on
qwen3.8-27b — but every accept path consumes only intermediates[a-1].
Under the opt-in lever the new gated_delta_rule_wy{K}_defer entries
run the identical gated_delta_rule_wyn_impl arithmetic with all state
stores removed (h_state stays H0), and gated_delta_rule_commit replays
the accepted prefix 0..a-1 through the same impl body, storing only
H_{a-1} — bit-identical to intermediates[a-1]/final H.

Conv outputs/gates are staged into per-slot commit buffers at verify
time (the shared ctx.buffers scratch is reused by the next forward).
Accept paths (commit_accepted_prefix, rollback_ssm_states, batched
DFlash) launch the commit kernel whenever a layer's
gdn_commit_pending flag is set — full accept is no longer a no-op for
deferred layers, since h_state was never written. Conv intermediates
are unchanged; wy2/3/4/wy17 and the f16/resident variants are
untouched; the strix-hip wyN port predates the table form so the
lever stays inert there (handles resolve to 0).

Lever off is byte-identical to main.

Test: cargo test -p spark-model --release --features cuda
  gdn_deferred_commit -- --ignored   (K in {5,8,9,12,16}, every
  a in 1..=K, outputs + committed state vs storing oracle)

Devin-Review-Token: gdn-deferred-commit
cd02041 could not reach a GPU:
- ATLAS_WYN_INSTANTIATE still called gated_delta_rule_wyn_impl<K>(...)
  after the impl gained a MODE parameter and an accepted_count argument
  (nvcc error). The legacy wy{K} entries now call impl<K, 0> with an
  unused accepted_count; their extern signature is unchanged from main.
- ATLAS_WYN_DEFER_INSTANTIATE was invoked for K=5..16 but never defined.
  It now emits gated_delta_rule_wy{K}_defer with the same 18-param
  signature (same gdn_decode_wyn launcher) calling impl<K, 1>.
- then_some(self.gdn_wyn_defer_k[k - 5]) evaluated the index eagerly:
  an underflow panic for k <= 4 (the existing r4/r7 dispatch tests hit
  it) and an out-of-bounds index at k = 17. Both sites now branch first.
- Under defer a full accept still runs commit_accepted_prefix, and the
  deferred branch restored conv state from conv_intermediate(k - 1), a
  slot the fused conv path never writes. Skip the conv restore on a full
  accept; the verify's final conv state is already canonical.

gdn_wyn_launcher_arg_count_matches_kernel_param_count pins the wy{K},
wy{K}_defer and commit entries against their launchers (18/18/14); it
fails on cd02041 because the _defer entry does not exist.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… in the captured forward (#58)

Reiner job 621: with ATLAS_GDN_DEFERRED_COMMIT=1 greedy output diverged
after ~20 tokens (json "population" 1250000 -> 2847000, code 256 -> 181
tokens) although the kernel oracle passes. The verify forward is graph-
captured (verify_d logs "Captured CUDA graph for K=gamma verify"), and the
layer set gdn_commit_pending and lazily allocated its staging buffers as
host code inside that forward. On replay the graph still ran the MODE-1
_defer kernel (no state stores) while the flag stayed false, so the
accept path restored h_state from intermediates MODE 1 never wrote.

- mark_gdn_deferred_commit assigns the flag at every decode_verify*
  entry, on the capture pass and on every replay, from
  TransformerLayer::gdn_deferred_wyn (the wyN arm's own gates) plus the
  shared SsmLayerState::h_inter_pool_layout precondition.
- Staging lives in lever-gated SsmStatePool pools, bound at slot bind
  and rebind like h_state; the forward only issues the capturable copies
  and fails fast if the staging is missing.
- decode_verify_batched checks that it has one depth per sequence.

gdn_commit_pending_is_set_at_dispatch_not_in_the_layer fails on
0f5ec00; cargo test -p spark-model --lib: 857 passed.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh AzeezIsh changed the title spark-model: cut DFlash2 batched propose (async ctx copies, batched ctx projection, batched selector) (#58) spark-model: DFlash2 step cuts — async batched propose + opt-in GDN deferred commit (#58) Sep 28, 2026
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Both halves on one binary: passes (reiner job 625zzz1, 4c13a0a).

Setup: job-240 DFlash2 serve, concurrency-sweep C 1/4/8/16, ISL 512, OSL 320. Arms, interleaved ×2:

  • A = main 10d4ec7;
  • B = this PR with the lever off (async propose only);
  • C = this PR with ATLAS_GDN_DEFERRED_COMMIT=1.
arm C1 C4 C8 C16 propose n=16 verify n=16 step n=16
A1 main 23.3 46.0 56.9 69.7 249 ms 367 ms 616 ms
B1 async 23.3 49.8 67.4 77.3 163 ms 369 ms 532 ms
C1 async + defer 23.9 54.6 74.7 85.9 158 ms 269 ms 427 ms
A2 main 23.2 46.0 63.1 65.3 250 ms 369 ms 619 ms
B2 async 23.3 49.8 61.1 82.4 162 ms 368 ms 530 ms
C2 async + defer 23.9 53.8 67.4 89.0 157 ms 269 ms 426 ms

Checks:

  • Greedy probes identical A vs B and A vs C, 5/5 each.
  • ATLAS_DFLASH_BATCH_PARITY on C: 0/40960 mismatched.
  • 0 errors, 0 vacuity flags.
  • Mean acceptance 3.08–3.19 in every arm.

Result: at 16 sequences the step drops from ~617 ms to ~427 ms (−31 %). C16 on C was 85.9 / 89.0 against 73.5 required; lever off (B) was 77.3 / 82.4.

Status: ready for the GB10 train's gates. The deferred-commit lever stays opt-in until ST-995 runs with it on.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Added to the GB10/common train #132 (fae3616d5), merged --no-ff from this head. Gates: GB10 625zzz3 (boot matrix, 27B agentic probe, cross-contamination) plus a Strix boot check (055d) for the candidate-selector kernel.

@AzeezIsh
AzeezIsh merged commit fae3616 into main Sep 28, 2026
25 of 26 checks passed
AzeezIsh added a commit that referenced this pull request Sep 28, 2026
AzeezIsh added a commit that referenced this pull request Sep 29, 2026
One conflict, in dflash_head.rs's module list: #104 adds `mod carry;` and #127
adds `mod batched_ctx;`. Keep both. The two paths compose. #127's batched
propose records ctx chunks from the same `committed = ctx_committed.min(ctx_len)`
watermark as the serial path, so #104's carried prefix is skipped by both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AzeezIsh added a commit that referenced this pull request Sep 29, 2026
#127 added 13 lookups: gated_delta_rule_wy5..16_defer and
gated_delta_rule_commit. Their kernels exist only in
kernels/gb10/common/gated_delta_rule_wyn.cu. strix-hip ships a
gated_delta_rule_wyn module without them, so plain try_kernel resolved
all 13 to handle 0, and the boot kernel gate refused qwen3.8-27b on
gfx1151:
"Error: 13 unresolved kernel lookup(s) for (qwen3.8-27b, gfx1151, nvfp4)"
(winbox, 56b3d6a).

Use try_kernel_gated(!cfg!(atlas_hip), ...), the same fix as #101's
batch8 lookup. gdn_defer_active already requires both handles to be
non-zero, so HIP keeps the eager commit. GB10 behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh
AzeezIsh deleted the perf/dflash2-async-ctx-copies branch September 29, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant