Skip to content

refactor(model): the Inkling forward pass is written against an Ops trait - #26

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

Defilan merged 3 commits into
mainfrom
agent/i2-ops

Conversation

@defilan-agent

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

Copy link
Copy Markdown
Contributor

Milestone I2. The step that lets the whole forward pass run on a device without a second copy of it. Nothing about the CPU model's results changes.

The forward pass called CPU functions on Vec<f32> values. It now calls a set of operations on values of a type it does not know: embed, normalize, mix, merge, rmsnorm, attention, attn_conv, expert_conv, add, experts, scores. That is the trait Ops. What stays written once is the part that is easiest to get wrong: which layers run how often, what a block is, where a pass starts again, which blend feeds which sublayer, where messages come from.

What is in it

  • inkling::Ops, with associated types for a value, for candidates normalized for a blend, and for what one layer pass remembers between tokens.
  • inkling::CpuOps: the reference. Its operations are the functions that were there before, and it holds the Products from the earlier step.
  • inkling::Inkling<O: Ops>; InklingCpu is Inkling<CpuOps>, with new and with_products as before, and with_ops for another implementation.
  • Layer, Gate and KvConv are public descriptions, so that another implementation can read a layer's weights.

How it was checked

  • 211 tests with both real models; format check and lint clean. The golden figures are the same to the last digit as before the change (tiny model 0.00054, 0.00075, 0.00268; real model 0.000036, 0.000053, 0.000042).
  • tools/mutants.sh all with both real models: 70 killed, 0 not killed, 23 skipped (GPU). Seven forward-pass patches no longer applied after the code moved and were regenerated.
  • A device implementation of this trait exists on a branch that follows this one. With it the real model matches the 32-bit reference recording at 96 of 96 tokens on a GB10.

Two things that changed place

  • Before any token has been fed, the private scoring step now returns an error where it used to score a vector of zeros. No public function reaches it in that state.
  • Planted bugs 43 (the window) and 51 (the output cap) now sit in CpuOps. Those two rules are properties of an implementation, so each implementation needs its own; the device one has them on its branch.

Review

The qwen reviewer approved with nits. It could not see outside the diff and asked for three things to be verified; all hold: the old single blend call was "normalize, then mix" in the kernels crate, the inline tests build, and nothing is left unused.

Made: the trait's docs now say what a second implementation must do (not that one exists), state the order the two convolutions rely on (read the earlier tokens, then add this one), and say that Layer and Gate are built by the model from checked weights.

Declined:

  • &self for five operations. A device implementation keeps a cache of uploaded weights and a pool of buffers, and needs &mut.
  • Avoiding a clone in CpuOps::add. Two vectors of 2,304 floats per layer pass on the reference path.
  • A shorter wording for planted bug 43. It leaves a parameter unused.

@Defilan
Defilan merged commit c2eec92 into main Nov 25, 2026
2 checks passed
@Defilan
Defilan deleted the agent/i2-ops branch November 25, 2026 07:04
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