Skip to content

cuda: GATED_DELTA_NET_BACK at head size 128 (fixes #10, which could not launch there) + checkpointed recompute; direct CUDA-vs-CPU oracle - #15

Merged
joelteply merged 1 commit into
feat/props-weight-residencyfrom
continuum/gdn-back-checkpointed
Sep 27, 2026
Merged

joelteply merged 1 commit into
feat/props-weight-residencyfrom
continuum/gdn-back-checkpointed

Conversation

@joelteply

Copy link
Copy Markdown

cuda: GATED_DELTA_NET_BACK recomputes from checkpoints, and runs at head size 128 (M'/dM out of shared memory)

Two changes to the CUDA twin (bf4c3ed):

  1. HEAD SIZE 128 NEVER LAUNCHED. M' and dM lived in dynamic shared memory, 2 x S_v^2
    floats = 128 KB at S_v = 128, above the ~99 KB per-block limit: supports_op claimed 128,
    cudaFuncSetAttribute rejected it (invalid argument) and CUDA_CHECK aborted the process.
    The gradient cases (head sizes 4-32) never reached it; the 27B's delta-net heads are 128.
    Each row of M' and dM is touched only by its own thread, so both now live in the block's
    global scratch (row-private, L1/L2-served) and no dynamic shared memory is used at all.

  2. CHECKPOINTED RECOMPUTE (card f4fc77c2, Cormac on cuda: the backward of the gated delta rule (GATED_DELTA_NET_BACK), the CUDA twin of #8's reference — 19739/19739 by finite differences, mutation fails #10): storing every forward state cost
    (T + 1) x S_v^2 floats per (sequence, head), GBs per call on the 27B. The forward keeps a
    two-slot working state and checkpoints every C ~ sqrt(T) tokens; the backward walks the
    segments last to first, re-running each from its checkpoint into a (C + 1)-state scratch.
    ceil(T/C) + C + 3 states per block instead of T + 1 (68 vs 1025 at T 1024).

Oracle: a new test case, GATED_DELTA_NET_BACK run directly on identical random inputs on
every backend (CUDA compared output-for-output against the CPU reference, no finite
differences): 5/5 at head sizes 16/32/64/128, sequences up to 64 tokens, KDA on and off,
K 1-3, and at segment lengths default, 1, 3 and T (all 5/5). The finite-difference gradient
suite is noisy on these small recurrent cases on BOTH backends (CPU reference 5 failing
case-runs in 12 suite runs, CUDA 4 in 12, same cases): it is kept, but the direct case is
the stable oracle.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

…ead size 128 (M'/dM out of shared memory)

Two changes to the CUDA twin (bf4c3ed):

1. HEAD SIZE 128 NEVER LAUNCHED. M' and dM lived in dynamic shared memory, 2 x S_v^2
   floats = 128 KB at S_v = 128, above the ~99 KB per-block limit: supports_op claimed 128,
   cudaFuncSetAttribute rejected it (invalid argument) and CUDA_CHECK aborted the process.
   The gradient cases (head sizes 4-32) never reached it; the 27B's delta-net heads are 128.
   Each row of M' and dM is touched only by its own thread, so both now live in the block's
   global scratch (row-private, L1/L2-served) and no dynamic shared memory is used at all.

2. CHECKPOINTED RECOMPUTE (card f4fc77c2, Cormac on #10): storing every forward state cost
   (T + 1) x S_v^2 floats per (sequence, head), GBs per call on the 27B. The forward keeps a
   two-slot working state and checkpoints every C ~ sqrt(T) tokens; the backward walks the
   segments last to first, re-running each from its checkpoint into a (C + 1)-state scratch.
   ceil(T/C) + C + 3 states per block instead of T + 1 (68 vs 1025 at T 1024).

Oracle: a new test case, GATED_DELTA_NET_BACK run directly on identical random inputs on
every backend (CUDA compared output-for-output against the CPU reference, no finite
differences): 5/5 at head sizes 16/32/64/128, sequences up to 64 tokens, KDA on and off,
K 1-3, and at segment lengths default, 1, 3 and T (all 5/5). The finite-difference gradient
suite is noisy on these small recurrent cases on BOTH backends (CPU reference 5 failing
case-runs in 12 suite runs, CUDA 4 in 12, same cases): it is kept, but the direct case is
the stable oracle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply

Copy link
Copy Markdown
Author

APPROVED at 32097003b. First, a correction to my own #10 review: I wrote that the 2·S_v²·4 B (~134 KB at S_v = 128) dynamic shared memory "fits the 5090's opt-in limit". It doesn't. That was the datacenter parts' figure; the consumer RTX 5090 caps at ~99 KB per block. So my "note, not blocking" was a blocker I misjudged, and your direct-op instrument is what caught it.

The fix reads right:

  • M'/dM are row-private, so global scratch at seg + (C+1)·SS and (C+2)·SS, outside the replayed segment states, so dM survives across segments. C = 1 still fits the C + 3 allocation.
  • Forward: a two-slot ping-pong, saving the state BEFORE token t as checkpoint t / C at every t % C == 0.
  • Backward: segments last to first; each replayed from its checkpoint into seg[0..C] (the state before t0 + x), then walked back with M1 = seg[t - t0 + 1] and M0 = seg[t - t0], the same indices as the stored-trajectory version.
  • A thread re-reads only rows it wrote itself (program order), and dropping __restrict__ on the two written buffers is correct: the read-only path could otherwise serve a stale row.
  • C = ceil(sqrt(T)), so ~2·sqrt(T) + 3 states per block instead of T + 1.
  • test_gated_delta_net_back compares the op output-for-output against the CPU reference at heads 16–128 across segment boundaries and segment lengths 1/3/T. That's the instrument that should have been on cuda: the backward of the gated delta rule (GATED_DELTA_NET_BACK), the CUDA twin of #8's reference — 19739/19739 by finite differences, mutation fails #10.

On the finite-difference flakes you measured on the CPU reference (5 failing case-runs in 12 suite runs, including my head-8 K=3 case): that's mine. The relative MAA still tips on near-zero gradient components at eps 0.1. I'll make those cases stable in a follow-up; your direct case stays the oracle for the twins.

Co-Authored-By: Claude Opus 5.5 [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant