Skip to content

lanes/recorder: --record writes each stream's committed rows and tapped features for drafter training; Nemotron CUDA gives its final norm's rows - #848

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jschmied:drafter-recorder
Oct 16, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jschmied:drafter-recorder

Conversation

@jschmied

@jschmied jschmied commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Item 2 of #620: a recorder in the core that writes what serving computes, for training drafters. It records with drafts on or off. Nemotron on CUDA is the first family to give it rows.

  • zig/src/core/lanes/recorder.zig: Recorded sits in front of any lanes.Backend that gives features. It forwards every entry the target gives.
    • After a prompt pass it writes the rows the pass computed (from cached on).
    • A prompt filled in chunks (prefill_step) is written when its last chunk completes.
    • Before each verify it writes the rows the stream's last verify kept. At release it writes the stream's last ones.
    • Each recorder makes its own new folder <dir>/<pid>-<k>: the first k that no file, folder or link has. It opens it without following links and keeps it open.
    • Every file is created exclusively in that folder. A link or an earlier recording is refused, never written through or overwritten.
    • Recorder.initTries gives up after a number of taken names; init allows 65,536.
    • Per stream it appends to <n>.tok (u32 tokens), .pos (u32 cache rows), .kind (u8, 1 for a reply's row) and .st (the tapped rows, as features gives them).
    • At release it writes <n>.json: rows, first row, prompt length, taps, row bytes, dtype, top-k, and the gap if one stopped the stream.
    • With logprobs it also writes .top: each reply token's ids and logprobs.
    • A stream that runs a one-token (queue) round stops there and its .json says so.
    • Background prompt passes are not recorded.
    • Below 25 GiB of free disk a stream starts no files.
    • A failed write ends that stream's files, never the request.
  • zig/src/families/nemotron/cuda_lanes.zig: prepare_features / features for one tap, the final norm's rows (tap = layer count). These are the rows its head and MTP head read.
    • Prompt chunks copy theirs to the host as each chunk ends, through a new Engine.taps hook. The hook is called in serialChunks. Staggered segments are skipped while it is set.
    • A verify's rows are read from the stream's own hidden buffer before the next verify.
  • --record DIR (server/cli.zig, native/cuda.zig): the CUDA server puts Recorded in front of a family that names taps (Loaded.taps).
    • DIR must exist. The log names the recorder's folder in it.
    • With recording on, the lone driver is off, so every token goes through the lane rounds.
    • Other backends, and families without taps, refuse the flag at startup.

Receipt

  • Environment: TensorFold 2984ea01 plus these three commits (head e5e03baa). One DGX Spark (GB10, sm_121, CUDA 13). Nemotron 3.5 Lightning MLX 4-bit.
    • main is now c7137bb3; its two new commits touch only app/. The branch merges without conflicts.
  • Exactness:
    • Server with and without --record: six completions give identical reply shas: code drafted, prose drafted, code "draft": false, code sampled (seed 7), and code + prose concurrent, 128 tokens each.
    • Repeat set: a further set (code drafted 3x and plain 2x at 256 tokens, a 2,048-token prompt and its follow-up, a logprobs request) gives identical replies.
    • Recorded rows: for the same prompt, the .tok and .st files of the drafted, plain and concurrent streams are byte-identical (code: 163 rows x 5,376 bytes; prose: 165 rows).
    • Chunked prompt: a 5,000-token prompt (two passes of up to 4,096 rows), drafted and plain, 32 tokens:
      • same reply; .tok and .st byte-identical; 5,031 rows, positions 0 to 5,030, 31 reply rows;
      • its first 4,096 rows equal those of the 4,096-token prompt alone.
    • Folders: each server wrote <dir>/<pid>-0. A second server on the same DIR made its own folder next to the first, which it left as it was.
    • Positions: each recorded sequence was sent back as a prompt.
      • The prompt rows come back byte-identical.
      • Reply rows recomputed by the prompt pass differ from the decode rows at the same position by 1.1 to 4.8 % (relative L2), against 58 to 108 % one row off. The prompt pass and verify windows are different kernels.
      • Training data from a resubmitted conversation therefore differs slightly from what decode wrote.
    • Prompt cache: a two-turn chat with the cache on writes turn 2's files from row 738, its cached_tokens.
  • Speed, Nemotron on GB10, 256 tokens, median:
    • drafted: 1.44 s recorded / 1.49 s not;
    • plain: 2.50 s / 2.52 s.
    • The lone driver being off cost nothing measurable here.
    • Positions and speed were measured at the first commit. The two later ones change only file creation and when a chunked prompt is written.
  • Tests: zig build test (46/46 steps, 753/758 tests, 5 skipped) and zig build test-cuda-host (27/27 steps, 475/475 tests); tf-cuda-test glue 1,242/1,242. zig fmt --check clean. lean_check.py: 527 findings, as on main.
    • recorder_test.zig runs the fake target with and without the recorder: drafted, plain, shared (batched or not), greedy and sampled, a restored prompt, logprob rows, and one-token rounds.
    • It also fills prompts of one and three chunks, puts two recorders in one folder and a link where a folder would go, plants links as a stream's files and summary, and runs initTries out of names.
    • The fake's row state is its token, so each .st must equal its .tok.
  • Mutations: each fails the tests:
    • a verify's start one row late;
    • a restored prompt written from row 0;
    • the reply-row kind off by one;
    • no write at release;
    • a one-token round not marked;
    • a chunked prompt recorded on a chunk that is not its last;
    • stream files created without exclusive;
    • a taken folder name reused.
    • Not caught: opening the folder with follow_symlinks = true. A link planted before mkdir already fails there, so the flag only guards the moment between mkdir and opening.
  • Not run, and why: Metal (refuses the flag; no Metal family gives features). A CUDA family other than Nemotron (none on main).

core/lanes/drafted.zig is unchanged: a drafter behind Drafted and the recorder can share a target. Item 1 (the release format) and item 5 (the recipe) follow as their own PRs.

Checklist

  • 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. (No bits change.)
  • Prompt processing is no slower than the last release. (Recording turns staggered segments off for its own passes; off by default.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

…ed features for drafter training; Nemotron CUDA gives its final norm's rows
@jschmied
jschmied marked this pull request as draft October 14, 2026 17:57
@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, @jschmied. The recorder's forwarding and the Nemotron row checks are useful, but this needs two changes at b0af8d5.

zig/src/core/lanes/recorder.zig:99 creates predictable <pid>-<counter> files with default truncate/follow behavior. A pre-existing symlink can redirect writes outside --record; the .json and .top writes at lines 169 and 183 have the same issue. Two recorder instances sharing a PID and directory can also overwrite earlier records. Please retain the directory handle, choose a fresh recording namespace and create every output exclusively, including summaries.

recorder.zig:216 also reverses prefill_step completion. False means more chunks remain, but that is when it opens the recording and requests the complete prompt's features. A one-chunk prompt returning true records nothing; a longer one can acquire a permanent gap before completion. Trigger prompt recording on true and cover both cases. Nemotron's whole-prefill receipt does not exercise this generic wrapper arm.

These are source findings; we have not rerun the CUDA receipt.

…lder; a chunked prompt is recorded when its last chunk completes

- Recorder.init creates <dir>/<pid>-<k> with mkdir (the first k no file, folder or link has), opens it without
  following links and keeps the handle; every stream file and summary is created exclusively inside it, so a link
  or an earlier recording is refused, never written through or overwritten.
- Recorded.prefillStep records the prompt when prefill_step returns true (done); it did so on false.
- Tests: one-chunk and three-chunk prompts through fillStream, two recorders in one folder, a link where the
  folder would go, and links planted as a stream's files and summary.
@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart, thank you. Both are fixed in 617f8ee5.

  • Files. Recorder.init now makes its own new folder <dir>/<pid>-<k>. It takes the first k that no file, folder or link already has, because mkdir refuses existing names. It opens that folder without following links and keeps the handle. Every stream file and every summary (.json, .top) is created exclusively inside that handle, so a link or an earlier recording is refused (and logged), never written through or overwritten. Two recorders with the same PID and folder each get their own folder.
  • prefill_step. The prompt is now recorded when the step returns true, i.e. when its last chunk is done. The tests now drive one-chunk and three-chunk prompts through fillStream, with and without a restored prefix. With the old condition these fail with no files.

New tests, all on the fake target:

  • two recorders in one folder;
  • a link planted where the recorder's folder would go;
  • links planted as a stream's .tok, .st and .json.

In each case, nothing reaches the link's target and the replies are unchanged. Each of these mutations fails a test: the old prefill_step condition, non-exclusive stream files, non-exclusive summaries, and reusing an existing folder name. Opening the folder with links followed passes, since it only matters in a race between mkdir and open.

CUDA receipt rerun (Nemotron, GB10, the same six requests as before: drafted, plain, sampled, two concurrent). All six replies match the earlier receipt and the run without --record byte for byte. The files land under <dir>/<pid>-0/. Each stream's tokens and features match the earlier recording row for row. Two drafted streams have one row more at the end because their last round kept one more row, and drafting rounds vary between runs. zig build test passes, zig fmt is clean and lean_check.py stays at 527.

@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied, for the exclusive-folder changes and the one- and three-chunk completion tests; both original findings are closed.

One cleanup error remains at 617f8ee. zig/src/core/lanes/recorder.zig:46 frees the folder name on a collision, then the terminal collision returns an error and runs the earlier errdefer, freeing the name again.

Please move the terminal-limit check before the manual free and cover that branch with a small injectable collision limit. That gives the error path one owner without needing 65,536 collisions in the test.

Posted by Ash's AI Assistant Synthena

… so the errdefer is its one owner; initTries tests that branch
@jschmied

Copy link
Copy Markdown
Contributor Author

Thank you. Fixed in e5e03baa: the terminal collision now returns before the loop's manual free, so the errdefer is the name's one owner. Recorder.initTries takes the collision limit (init passes 65,536), and a new test pre-creates three names with a limit of 3, expects error.PathAlreadyExists under std.testing.allocator, then takes the fourth name with a limit of 4. With the old order back, that test aborts on the double free.

@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied, for adding the three name collision regression in recorder_test.zig:215.

We checked e5e03ba. At recorder.zig:51, the terminal collision now returns before the manual free, so the error defer releases the name exactly once. The new test covers refusal after three occupied names and successful creation of the next free name. That closes the double free, and the earlier exclusive file creation and prefill completion fixes remain intact.

This is ready for the landing batch after 1.0.12.

Posted by Ash's AI Assistant Synthena

@jschmied
jschmied marked this pull request as ready for review October 15, 2026 20:51
@jschmied

Copy link
Copy Markdown
Contributor Author

Thank you. It's out of draft now, and the description's receipt is rerun at e5e03baa: the same reply shas with and without --record, byte-identical recordings for drafted, plain and concurrent streams, and a new chunked 5,000-token prompt check. It merges cleanly with main (c7137bb3). The format and recipe PRs from #620 follow separately.

@ashhart
ashhart merged commit ad42024 into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
…he host is made

After #848 met this tree's three CUDA families, openWith read `loaded.taps` for every family, and only
Nemotron's Loaded has the field: the GLM instantiation would not compile. Taps now come from the family when it
gives them and are empty otherwise, so --record is refused by name for GLM-5.3-Flash and Super VL. The two
refusals (no rows to record, a folder that cannot be made) now return before the host, its store and its learner
are made, where a null return released none of them. The recorder's parts move to cuda_record.zig so
native/cuda.zig stays under 600 lines.
ashhart added a commit that referenced this pull request Oct 16, 2026
…VIEW names the refused GLM pair requests rightly

One line each for #881, #882, #883, #889, #890, #709, #848, #892, #867, #868, #871 and #873, crediting their
authors. ZIG-PREVIEW said a two-Mac GLM pair refuses "temperature-1" requests; it refuses any temperature above 0
(backend.zig and engine.zig both test temperature > 0).
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied, for the recorder's terminal-collision fix and ownership checks.

#848 is included in 1.0.12 as merge ad42024, at e5e03ba. --record DIR writes committed tokens and target rows into a fresh recording folder; Nemotron CUDA records its final norm rows.

The merge combines recording with the existing image path. In 8e90bef we read taps only from families that provide them, so GLM and Super VL refuse --record by name before allocating the host or prompt store. The recorder code moved to native/cuda_record.zig.

On GB10, all 17 Nemotron recorded cells equal their unrecorded controls, and drafted replies equal plain ones. The run wrote 170 files, 113 MB.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…he host is made

After ashhart#848 met this tree's three CUDA families, openWith read `loaded.taps` for every family, and only
Nemotron's Loaded has the field: the GLM instantiation would not compile. Taps now come from the family when it
gives them and are empty otherwise, so --record is refused by name for GLM-5.3-Flash and Super VL. The two
refusals (no rows to record, a folder that cannot be made) now return before the host, its store and its learner
are made, where a null return released none of them. The recorder's parts move to cuda_record.zig so
native/cuda.zig stays under 600 lines.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…VIEW names the refused GLM pair requests rightly

One line each for ashhart#881, ashhart#882, ashhart#883, ashhart#889, ashhart#890, ashhart#709, ashhart#848, ashhart#892, ashhart#867, ashhart#868, ashhart#871 and ashhart#873, crediting their
authors. ZIG-PREVIEW said a two-Mac GLM pair refuses "temperature-1" requests; it refuses any temperature above 0
(backend.zig and engine.zig both test temperature > 0).
@jschmied
jschmied deleted the drafter-recorder branch October 23, 2026 21:02
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