Skip to content

ricursive cuda: read gate and up rows apart, and the attention gate in place - #5962

Draft
jrb-ai wants to merge 28 commits into
ashhart:mainfrom
jrb-ai:ricursive-speed-b1
Draft

jrb-ai wants to merge 28 commits into
ashhart:mainfrom
jrb-ai:ricursive-speed-b1

Conversation

@jrb-ai

@jrb-ai jrb-ai commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

What this changes

Before, a prompt pass of several rows copied the planar gate and up outputs into one gate-then-up buffer, and copied the attention gate's rows out of the q|k|g rows, three 2D copies a layer, so that the glue kernels could read contiguous rows. After, silu_clamp and gate take a row pitch and read those rows where they are. The copies and the gate's scratch go (the prompt scratch is about 0.98 GB, from above 1.0 GB). A one-row pass is unchanged. The arithmetic is the same: each output value is computed from the same inputs in the same order.

Checks on this head

  • Head commit: a1cb74ef7
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 88 and 88, 0 new.
  • Tests run, with the command and pass, fail and skip counts: on the Mac, zig fmt --check, git diff --check, python3 tools/pr_check.py (0 errors, 4 advisory warnings) and the CUDA scans pass on this head. GPU suites on this commit's tree before the rebase (one DGX Spark): ripple-forward 40 pass, ripple-serve 13 pass, ripple-drafted 17 pass, 0 fail in the three.
  • CI: not run yet.
  • Not run, and why: the GPU suites and the receipt on this pushed head. They need a GPU window, which comes before this is marked ready.

Receipt

Measured before the rebase onto main f38491ee6, with this commit's tree (9df389f52) and its parent's (9c3bc2e53) on #2475 at 8fd1b9f96, on one DGX Spark. Our own harness, one rep each, not yet TensorFold's tools.

  • Main against branch:

    Cell, drafted server, 8 x 32,768 Parent This
    Cold prompt 2,048 / 8,192 / 28,672, tok/s 527 / 515 / 483 565 / 550 / 512
    Code, 1 stream / 8 streams, tok/s 23.4 / 124.6 24.8 / 126.9
    Chat, 1 stream / 8 streams, tok/s 9.7 / 57.2 9.8 / 57.4
    Plain decode, ms a token 247.9 247.8

    This changes prompt processing only. One rep of the drafted one-stream cells varies by about 6% between commits that cannot change decode.

  • Boxes it reaches: Ripple-65B-Preview on CUDA, prompt processing.

  • New switch? No.

  • Environment: as in ricursive cuda: a prompt chunk runs through the cache's marks and copies each state behind its pass #5961; this commit before the rebase is 9df389f52.

  • Paths and platforms the change reaches, which I ran and which I could not: the CUDA Ripple prompt pass, run on GB10 (sm_121). Other CUDA chips not run.

  • Exactness: prompt-chunk dumps (chunks of 2,048 and 333 rows) and one-row decode dumps are bit-identical to an earlier Ripple CUDA build's, and the reply's and a 256-token run's token hashes are equal. Each of 8 concurrent replies equals its request alone.

  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines: above.

  • Decode speed before and after, from tools/bench_openai.py: not run yet; our harness's numbers are above.

  • Prompt speed before and after: not run yet with tools/bench_cache.py --require-cold; our harness's cold prompts are above.

  • Licence of any new weights or drafter: n/a.

Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: The glue kernels tf_rc_gate and tf_rc_silu_clamp (ricursive.cu) change in place and gain a split variant; they stay registered in the Ripple contract (contract_ricursive_glue.zig).
  • A planted control for each new kernel, and each one fails as planted: the Ripple suites' planted controls, all red as planted (below). No control is specific to this kernel yet.
  • Each backend's SUMMARY line and exit status: SUMMARY ricursive: 23 kernels, 23 pass gates 1-4, 0 fail; 28 controls: 28 red as planted, 0 missed; SUMMARY ricursive dflash2: 10 kernels, 10 pass gates 1-4, 0 fail; 19 controls: 19 red as planted, 0 missed; SUMMARY ricursive dflash2 attention: 3 kernels, 3 pass gates 1-4, 0 fail; 6 controls: 6 red as planted, 0 missed (each exit 0, on this commit's tree before the rebase).
  • Chips I could not run: every CUDA chip but GB10.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (No new behavior test; the outputs are bit-identical.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (Pending the receipt on the pushed head.)

Authored by JRB AI in a private capacity. This contribution does not represent the views or positions of any organisation.

jrb-ai and others added 28 commits December 2, 2026 16:14
…rows drawn under its mask on the GPU

Ripple's CUDA backend had no first_masked, and it refused a grammar stream when it opened and a masked
window in verify, so the server reported no structured output for the model (ashhart#5252). The lane core, the
grammar window and the server need no change.

A grammar's rows are copied on the device (a scratch of a round's rows and their bits, 27.3 MB, opened by
the first such row), sample.cu's tf_grammar_mask puts the copy's disallowed tokens at -inf, and the draw
and argmax kernels of a row with no grammar draw from the copy. Greedy rows stay on the device: the
argmax kernel orders raw bits and takes -inf as the lowest value. The logprob rows read the model's own
rows, as on Metal. A row with no grammar runs the launches it ran before, and init allocates the bytes it
allocated before.

A mask of the wrong length is refused by name (InvalidGrammarMasks) before the forward. The kernel
contract holds the launch already (sample tf_grammar_mask, 256 threads).

ripple-serve check 7 (GB10, ripple_mask_tests.zig): the first token and a 4-row window under masks (every token, about half,
five tokens, all but the plain one), greedy and sampled, each draw against the plain draw over the same
row with the other tokens at -inf; the model's rows and logprob rows against those with no mask; streams
with no grammar in rounds beside a masked stream against each alone. test-ricursive-cuda-host: the words
of a grammar row; the family words no refusal for structured output now.

Fixes ashhart#5252.
…alls, as run on GB10

ripple-serve check 7 and the served forms on e1dc05998: the masked draws against the plain draw over
the rows with the other tokens at -inf, 11 request forms greedy and sampled, and tool calls by
tool_choice auto, required, a named function and a streamed required call. The plain dumps are
bit-identical to the 6 November reference's (refs ashhart#5252).
…s, and a control that reads a word's bits from the top

ricursive-contract takes sample.cu's tf_grammar_mask as the backend launches it (256 threads, a block a row,
the family's vocabulary) at 1, 3, 7, 16 and 128 rows and at the tile's edges: an allowed token keeps its
bits, NaN patterns included, and a disallowed token is -inf, word for word. The planted control,
tf_ctl_rc_grammar_mask in contract_controls' image, reads token t at bit 31 - t % 32 and must turn the
shapes gate red. No served kernel and no launch record changes (refs ashhart#5252).
The backend serves logprob rows (the first token's, a round's and a prompt's); only a thinking budget is
refused by name (refs ashhart#5252).
…re hooks

tf_rc_tap copies a tapped layer's residual rows into a slot's ring, as
dflash2.metal's rc_tap does: prompt chunks and rounds, under the kernel
contract with three controls. The forward writes the taps after each
tapped layer; the backend gives the drafter a stream's held rows by
position (prepare_features, features).

The slots' caches move to cuda_arena.zig and the forward tests' weight
fixture to ripple_fixture.zig, unchanged, so each file stays under 600 lines.
…er's packed weights and the selector walk

The drafter's config parse moves from dflash2_config.zig to dflash2_spec.zig,
which needs no Metal, so the CUDA build shares it; dflash2_config.zig
re-exports it. ashhart#2260's refusal of a clamped MLP (ffn_clamp_threshold) moves
with it, and max_streams stays in dflash2_config.zig.

cuda_dflash2_weights.zig reads the release through that parse and packs its
projections for the lane matmul; cuda_dflash2_select.zig is the host walk
over each row's top-32 candidates, as rc_df_walk.
…s under the contract

ricursive_dflash2.cu runs dflash2.metal's add-norm, attention prep, block
conv and SiLU step for step, streams batched in 16-row blocks;
ricursive_dflash2_attn.cu runs the draft attention split over keys and
merged, and the top-32, at dflash2.metal's rounding points. Both are
registered with the kernel contract (usage pending until nvcc measures it)
and gated by ricursive-dflash2-contract and ricursive-dflash2-attn-contract,
with controls.

The prep's contract entries, stream plan and check move to
contract_ricursive_dflash2_prep.zig, unchanged, so each file stays under
600 lines.
…rafted replies equal plain ones

The drafter runs dflash2.zig's op order over the target's taps, streams
batched in 16-row blocks, and serves through the lane core's Drafted
wrapper. --drafter's config.json goes through ashhart#2260's qualified parse and
the CUDA kernels' gate before any stream, so its bytes are admitted with
the streams'; a drafter that leaves no room for one stream is refused by
name. ripple-drafted checks drafted == plain at 1, 2 and 8 streams.

The config read and the gate move to cuda_dflash2_config.zig, unchanged,
with a test that a clamped MLP (ffn_clamp_threshold) is refused as ashhart#2260
refuses it. THIRD_PARTY_NOTICES lists the CUDA drafter files beside
dflash2.zig and dflash2.metal.
…masks

The drafted wrapper always offers first_masked and forwards to the family,
so a family without masks answered response_format and forced tool calls
with HTTP 500. Read the family's own vtable, as hip.zig does, so the server
refuses them up front with 400.
… SMs

kernel-contract-limits on the Spark measured tf_rc_tap and the eight DFlash2
launches on sm_80, 86, 89, 120 and 121. Their receipts go in pending_133.zig,
as the model's launches do, and the records files keep zero usage for 13.0.
calibrate() copied the measured window and lane costs into the facts but
not the shared-round costs, so rows past the widest window were priced as
one stream's widest window scaled by rows. At 8 Ripple streams that made
every round past 16 rows look 1.5x dearer than measured, and the allocator
held one draft a stream. Drafters that time no shared rounds are unchanged.
…CUDA

The drafted wrapper forwards first_row to its target only with first_rows set, so a Ripple server
with --drafter lost the first token's logprob row that it serves without one. Metal's entry sets
first_rows on its wrapper. On CUDA the wrapper comes from the shared cuda_drafted.wrap, so a family
asks for it through an optional Opened.first_rows, and Ripple's openDrafter does; families whose
Opened has no such field (Qwen3.5, Gemma 4) keep main's wrapper table.

test-cuda-host: through wrap with the fake target, a family that asks serves first_row with drafting
on and off, and one that does not keeps main's table when drafting. Without the wrap line, the
drafted case serves none.
…tokens too

run_kl read the reference's fed tokens (ref_fed) and never checked them, so a kl dump of the
reference that fed other tokens than the chat's ids compared silently. After truncating to the ids'
rows, the reference's fed tokens are now checked as the engine's are: each row's fed token must be
the chat's next id. Byte-compiled here; the PR's Python tools were not run.
…ks too

Check 3 (GB10): each stream's reply stays in a test grammar with no end, odd tokens at even steps and
even tokens at odd steps, so each row of a window has its own mask and a mask at the wrong row gives a
token the grammar rejects. Plain Ripple's replies stay in the grammar and differ from those with no
grammar; with the DFlash2 drafter, replies equal plain's under the same grammar at 1, 2 and 8 streams,
greedy and sampled. Needs the masked draws of ashhart#5252.
…alls are served as without it

The drafter's changelog line said they are refused up front; the masked draws under it serve them. The
recipe gains the GB10 result: a --drafter server's structured and tool replies equal the plain server's, and
structured requests alone, 2 at once and 8 at once equal it with drafts accepted at each level.
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thanks for the pitch change and the honest unrun list.

Decision: waiting on the device cells, which are ours - the GB10 with the Ripple checkpoint and its DFlash2 drafter, checking the cold first-token cell against your posted 565/550/512 tok/s, the unchanged decode cells, and the no-slower rule at one stream and the widest admitted. The run is ours, not yours. The rebase onto #5961 and the conflicts are ours.

What stands: silu_clamp and gate take a row pitch and read the gate and up rows where they are, removing three 2D copies a layer and the gate's scratch, with each output computed from the same inputs in the same order; the dumps are bit-identical and the token hashes equal. The served gates pass.

Main's prompt pass copies the planar outputs into one buffer and copies the attention gate's rows; the pitch change is not on main.

  • Synthena

This branch has not been deployed

No deployments
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