Skip to content

Drafter: kernel sweep of the fold's ring-writing GDN verify by value tile and batch (follow-up to #167; run pending) - #180

Merged
SamMausberg merged 1 commit into
mainfrom
drafter/ring-tile-sweep
Oct 2, 2026
Merged

SamMausberg merged 1 commit into
mainfrom
drafter/ring-tile-sweep

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

Follow-up to #167. The exact GDN fold verifies with SGLang's recurrent kernel writing a ring (cache_ring=True), and the kernel's value tile decides how many programs it launches: one per (value tile, sequence, value head). At the pin, on sm_90, the ring verify uses tiles of 32. Patch drafter/0005 gave it the tiles of 4 that the stock per-position-state verify uses for at most 64 sequences. In #167's served A/B that removed the fold's loss at c ≤ 4 but cost it about 4% at c = 8 on block 16, and c ≥ 16 was not timed. This PR times the ring verify directly, by tile and batch, to find the batch above which the narrow tiles stop paying. That threshold is what a restricted version of 0005 would use. The GPU run is queued (normal lane); results will be added here.

What it measures. experiments/drafter/gdn_ring_tile_sweep.py covers value tiles 4, 8, 16 and 32 (forced through the launch-config selection), batches 1, 2, 3, 4, 5, 6, 8, 12, 16, 24, 32, 48 and 64, and blocks of 16 and 8 tokens, at the Qwen3.5-4B GDN shape.

  • For each point it calls the ring verify once per layer for 24 layers, with distinct FP32 states and rings per layer and shared activations, and captures the calls in one CUDA graph.
  • It records the median replay time per layer over 50 replays. The whole grid is repeated three times, with the tiles interleaved within each point, and the report gives the median and the range over repeats.
  • The stock per-position-state verify, at the tile the engine selects, is timed the same way as the reference the fold replaces.
  • Before timing, each tile's verify output and ring contents are compared bitwise with tile 32's. The run fails if a tile changes the arithmetic, because a restricted 0005 needs the tiles to stay interchangeable.

What it does not decide. It is a kernel microbenchmark at random inputs, not served throughput. A batch threshold chosen from it still needs kernel parity and a served session (stock, fold with 0001-0004, fold with the restricted rule) before any claim. Main has deferred those sessions until the end-to-end campaigns are done.

Run. scripts/gpu_lock.sh -x experiments/drafter/run_ring_tile_sweep.sh (one exclusive hold, about 10 minutes, no server). It runs from a detached worktree at aeaa3b1 with engine engine/drafter 9292abd874. The forced tiles make the engine's own rule irrelevant to the ring rows; the stock reference uses the engine's tile, 4 for at most 64 sequences. The hold records the repository and engine commits and the foreign CPU load (bench.hostload) alongside sweep.json.

Testing. pre-commit on the changed files; --help runs in the SGLang venv; hold_lint.sh reports no errors. The script has not run on the GPU yet.

…rify at forced value tiles 4-32 for batches 1-64 (blocks 16 and 8), stock verify as reference, tiles checked bitwise against 32
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T03:36:45.060223Z aeaa3b1 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: aeaa3b10dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE at aeaa3b1

This is code for a hold that has not run, so I reviewed the hold script, the bitwise gate and the analysis plan. The results commit will need its own review.

Hold script (run_ring_tile_sweep.sh):

  • set -euo pipefail, it sources sglang_env.sh with the drafter engine worktree, and it starts no server.
  • It refuses to overwrite an earlier sweep.json.
  • It records the repository and engine commits with modified-file counts and the start and end times.
  • It wraps the sweep in bench.hostload record, which writes the foreign CPU load and exits with the child's status (hostload.py:16, 226-232), so a failed sweep fails the hold.
  • hold_lint.sh on the script reports no errors. Run on the .py it flags its docstring, which is a false positive.

Bitwise gate against tile 32:

  • Tile 32 runs first, and its output plus the four ring buffers are cloned as the reference.
  • For every (T, N), each tile's ring buffers are zeroed before its layer-0 call, and its output and rings are compared with torch.equal.
  • disable_state_update=True keeps the states fixed between calls.
  • The patched _select_recurrent_launch_config is checked to have applied the forced tile (selected[-1]), and the run stops otherwise.
  • Any mismatch is listed in bitwise_failures and exits non-zero.

Timing:

  • One CUDA graph holds 24 layer calls with distinct per-layer states and rings, warmed up outside the graph, timed with CUDA events as the median of 50 replays divided by 24.
  • Three repeats of the whole grid; the stock per-position-state verify at the engine's own tile serves as the reference.
  • GPU state is recorded before and after.
  • Memory at N = 64, T = 16 is about 3.3 GB of states plus 2.2 GB of shared per-position buffer, which fits.

Analysis plan. The body is clear about what this decides and what it doesn't: a kernel microbenchmark on random inputs, with any threshold still needing kernel parity and a served session before a claim.

Codex found no major issues. Host identity is clean, and the one commit is Sam's.

Optional, before the hold runs:

  1. Within every point and every repeat the order is fixed: tile 32, 16, 8, 4, then stock. Reversing the tile order on odd repeats, or rotating it, would cancel any drift within a point (clock or thermal) instead of folding it into the tile comparison. The body's "tiles interleaved" would then also be accurate.
  2. Declare in the body, before the data exist, how the threshold will be read. For example: the largest N at which tile 4's median is below tile 32's with non-overlapping repeat ranges, on both blocks, or "the fastest tile per (T, N)" as fastest already computes. Then the later restricted 0005 can't be tuned on noise.
  3. sweep.json is written before the bitwise-failure exit. The exit status and bitwise_failures carry the failure, but writing to sweep.failed.json on failure would keep a later analysis from reading a failed sweep by mistake.

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