Skip to content

spark-model: opt-in GDN deferred commit for the wyN verify (ATLAS_GDN_DEFERRED_COMMIT) - #126

Closed
AzeezIsh wants to merge 2 commits into
mainfrom
perf/gdn-deferred-commit
Closed

AzeezIsh wants to merge 2 commits into
mainfrom
perf/gdn-deferred-commit

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Summary

Opt-in ATLAS_GDN_DEFERRED_COMMIT=1 for the wyN GDN verify (K=5..16, serial and batched). This targets the top kernel in the DFlash2 C=16 profile (gated_delta_rule_wy8, 21.7 % of GPU time in reiner job 596).

The problem. The storing verify writes K-1 full h_state snapshots plus the final H per (seq, v-head, layer), ~64 KB each on qwen3.8-27b. Every accept path consumes only intermediates[a-1].

What the lever does:

  • gated_delta_rule_wy{K}_defer runs the identical gated_delta_rule_wyn_impl arithmetic with every state store removed, so h_state stays at H0.
  • gated_delta_rule_commit replays the accepted prefix 0..a-1 through the same impl body and stores only H_{a-1}.
  • Conv outputs and gates are staged into per-slot commit buffers, because the shared scratch is reused by the next forward.
  • Accept paths (commit_accepted_prefix, rollback_ssm_states, batched DFlash) run the commit whenever a layer's gdn_commit_pending is set. A full accept is no longer a no-op for deferred layers.
  • With the lever off, the legacy gated_delta_rule_wy{K} entries keep main's extern signature and store contract (impl<K, 0>).

Scope limits:

  • wy2/3/4/wy17 and the f16/resident variants are untouched.
  • The strix-hip wyN port has no table form, so its handles resolve to 0 and the lever is inert there.

Commits:

  • cd02041: the lever.
  • 13c02de: makes it build and run.
    • It defines the missing ATLAS_WYN_DEFER_INSTANTIATE and fixes impl<K, 0> arity in ATLAS_WYN_INSTANTIATE.
    • It fixes an eager then_some(arr[k-5]) index that panicked for k<=4 and went out of bounds at k=17.
    • It skips a full-accept conv restore from an unwritten conv_intermediate(k-1) slot.
    • It adds a launcher/kernel arity pin.

Draft: stays opt-in until reiner proves parity and a benefit.

Test plan

  • cargo test -p spark-model --lib: 856 passed. This includes the new gdn_wyn_launcher_arg_count_matches_kernel_param_count (18/18/14; it fails on cd02041) and the r4/r7 dispatch tests that cd02041 broke.
  • CI nvcc -> PTX (all gb10 targets): the first compile of the new entries.
  • reiner job 621, which needs all of the following:
    • 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 and committed state vs the storing oracle);
    • a DFlash2 concurrency A/B, lever off vs on, interleaved ×2;
    • greedy probe hashes identical lever off vs on;
    • lever-off greedy identical to main 10d4ec7 (MODE 0 identity);
    • 0 errors or watchdog events.

Generated with Devin

cognition-team and others added 2 commits September 27, 2026 16:48
…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>
@github-actions

Copy link
Copy Markdown

Thanks for the contribution. Before we can merge, please sign our Contributor License Agreement by replying to this comment with:

I have read the CLA Document and I hereby sign the CLA


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Superseded by #128 (same tree; the lever commit is re-authored so the CLA check passes).

@AzeezIsh AzeezIsh closed this Sep 27, 2026
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.

2 participants