Skip to content

feat(model): guessed tokens checked in one sweep, and undone when wrong - #31

Merged
Defilan merged 5 commits into
mainfrom
agent/i2-drafter
Nov 25, 2026
Merged

Defilan merged 5 commits into
mainfrom
agent/i2-drafter

Conversation

@defilan-agent

@defilan-agent defilan-agent Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Milestone I2, the first use of several positions per sweep: guess the next few tokens, let one sweep check them.

What is in it

  • Inkling::undo(n): takes back the last n tokens of the last batch (never its first; at most 16, 15 on the device). Ops gains undo for a layer pass.
    • CPU: a history is shortened, and keeps window - 1 + 16 tokens when it drops old ones; a convolution memory keeps what it was when the last batch started and what the batch fed, and rebuilds itself.
    • Device: nothing to do. The convolution memories get a batch more slots than a convolution reads (as windowed histories got spare rows for batches), so what undone tokens wrote is never read before it is written again.
  • Inkling::generate_greedy_drafted: after each token chosen, a Drafter proposes up to 15 tokens; they are fed in one batch behind the chosen token; guesses are kept while they are the model's own choice, and the rest are undone. The tokens are those of generate_greedy.
  • LookupDrafter: proposes what followed the most recent earlier occurrence of the last few tokens. No weights.
  • examples/generate.rs draft [guesses] [match] measures it. Learning note 23.

Measured (Inkling 2 Mini on the GB10)

At most 200 new tokens, up to 4 guesses per sweep after a match of the last 4, 3 or 2 tokens:

Prompt Tokens counted Without guesses With Sweeps Guessed Right
A Rust function and three tests 199 23.9 tok/s 24.6 175 96 24
Three paragraphs of explanation 199 24.0 25.3 175 69 24
A sentence repeated five times (ends early) 168 24.2 33.0 107 94 61

The tokens were the same with and without guesses in every run. The mechanism costs what the batch measurements predicted; the lookup is a weak guesser for ordinary text. The checkpoint's own draft head is not loaded yet and would plug into the same trait.

How it was checked

  • CPU, tiny model: 100 tokens fed in sweeps of true tokens followed by wrong ones that are then undone; every true position's scores are bit for bit those of the true tokens fed alone. The tightest case separately: a full local history, the last token of a batch of 17 makes it drop old tokens, then 16 are undone.
  • Generation with guesses that are all right, all wrong, a third wrong, looked up, and from a drafter that returns too many tokens and tokens that do not exist: the tokens are those of plain generation, and sweeps and accepted guesses are what they must be. The end token reached as an accepted guess in the middle of a sweep stops generation there.
  • Real model on the CPU: 12 tokens with half the guesses wrong are the tokens of plain generation.
  • Device: the undo test against the CPU model at the bar of the recordings; a convolution with spare slots against the CPU with wrong tokens fed and dropped; generation with guesses gives the tokens of generation without.
  • Mac: format check, clippy, 225 tests (223 plus two added in review; the real-model tests ran before the review fixes and again for the model crate after them). GB10: format check, clippy on the workspace, 59 dluth-cuda tests with the real checkpoint.
  • Planted bugs 111 to 118 are new, six regenerated. tools/mutants.sh cpu: all killed. All 57 that need the GPU applied by hand on the GB10: each caught. One planted bug survived its first run ("the whole last batch can be undone": the CPU operations refuse it a second time); its test moved to the device, where only the model's check stands.

Review

The qwen reviewer asked for changes. It traced the position arithmetic, the identity of the tokens with plain generation for any drafter, the undo of histories and convolution memories, and the device argument with numbers, and found them correct.

Made: the note's table said 200 new tokens for a run that ended at 168 (now counted per row); a guard no public call reaches had no test and a comment that claimed one (now a unit test); the trait's doc on how much can be undone; a sentence about drawn tokens that ran ahead of the code; the tightest undo case as a test; the device comment names its numbers; a sweep without scores is an error.

Declined: "sweeps plus right guesses equal tokens minus one only for some drafters" (it holds for any: each sweep gives one token plus its right guesses); "ring_slots can divide by zero" (both callers check the channel count first).

@Defilan
Defilan merged commit 7ff6e8c into main Nov 25, 2026
2 checks passed
@Defilan
Defilan deleted the agent/i2-drafter branch November 25, 2026 16:14
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