Skip to content

feat(model): the operations take a batch of consecutive positions - #29

Merged
Defilan merged 3 commits into
mainfrom
agent/i2-batch
Nov 25, 2026
Merged

Defilan merged 3 commits into
mainfrom
agent/i2-batch

Conversation

@defilan-agent

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

Copy link
Copy Markdown
Contributor

Milestone I2, first step of several positions per sweep of the weights. The CPU model's results for one token at a time are unchanged.

A value of the Ops trait is now a batch: one vector for each of a few consecutive positions, in order. A token at a time is a batch of one. The operations that remember (attention and the two convolutions) take the positions in order, so a later position of a batch sees the earlier ones exactly as it would if they had been fed before it.

What is in it

  • inkling::Ops: count and row; embed takes several tokens; attention's position is that of the batch's first token; scores returns one run of scores per position.
  • inkling::CpuOps loops over the positions. Its value type is CpuVecs, one vector per position.
  • Inkling: forward_tokens (feed a batch, scores for every position), feed (no scores), next_scores (scores after the last token only), set_prompt_batch (how many prompt tokens generate_greedy feeds at once; 1 by default, so nothing changes unless asked).
  • dluth-cuda: the device operations are kept compiling and refuse a batch of more than one token, before anything is computed. Batched kernels come next.

Scoring only the last position matters: the output table is the largest matrix of the model, and a prompt's other positions are scored for nobody.

How it was checked

On the CPU a batch is the same arithmetic in the same order as token by token, so the test is equality bit for bit:

  • Tiny model, 40 tokens (past its window, its reach, the start of late scaling, and several times round its loop): six splits into batches, among them the whole sequence at once, batches that end exactly on the window, straddle it and are longer than it. Every position's scores are identical to the one-at-a-time run.
  • Real Inkling 2 Mini (with DLUTH_INKLING2_MINI set): a recorded prompt of 22 tokens fed at once, and in two uneven batches, scores identically to token by token.
  • Generation gives the same tokens for prompt batches of 2, 5, 23 and 100.
  • A refused batch changes nothing: no tokens, a last position that does not fit, a token outside the vocabulary in the middle of a batch, a batch out of order, and two refusals at position 0. The sequence then continues to identical scores.
  • 216 tests with both real models; golden figures unchanged; format check and lint clean.
  • tools/mutants.sh cpu: 56 killed, 0 not killed. Planted bugs 94 to 97 are new (every token of a batch given the first token's position; the first position scored where the last was asked for; a batch counted as one token; only a batch's first position checked against the room). Patch 51 regenerated.
  • GB10: dluth-cuda builds and its 51 tests pass with the real checkpoint, including the refusal of a batch.

Review

The qwen reviewer asked for changes. It traced the claim (any split, state between tokens, the loop over passes, messages between passes, a refusal leaving state alone) and found nothing wrong with it. Its must-fix was a sentence: the prompt batch setting was documented as giving the same result for any value, which the device operations' refusal in this same change disproves. The doc now says an implementation may refuse batches.

Also made: one split covered 39 of 40 tokens behind a loose assertion; refusals are now also tested at position 0, where an accepted batch would restart the sequence; two doc clauses.

…eding a sequence in batches gives bit for bit what token by token gives
…e batches; a split that covers every token and a refusal at position 0 in the tests; review fixes
@Defilan
Defilan merged commit 6a8c2a1 into main Nov 25, 2026
2 checks passed
@Defilan
Defilan deleted the agent/i2-batch branch November 25, 2026 09:26
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