Skip to content

refactor(model): matrix products go through a Products trait - #24

Merged
Defilan merged 4 commits into
mainfrom
agent/i2-t9a-products
Nov 25, 2026
Merged

Defilan merged 4 commits into
mainfrom
agent/i2-t9a-products

Conversation

@defilan-agent

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

Copy link
Copy Markdown
Contributor

Milestone I2, first step of moving the model to the GPU. Nothing about the CPU model's results changes.

Almost every byte a token reads is a weight matrix being multiplied by a vector. The Inkling forward pass now asks a Products object for each of those products, so that another device can take them over while everything else in the model stays written once, in dluth-model.

What is in it

  • inkling::Products: bf16 (the projections and the output table) and experts (a layer's chosen experts, one job each). Matrices are handed over as the slices of the weight file they live in.
  • inkling::CpuProducts: the default, doing what the code did before.
  • InklingCpu::with_products; InklingCpu::new uses the CPU.
  • inkling::ExpertMatrices: a public description of an expert layer's stored matrices (it was a private type).
  • ModelError::Device for a failing device. Functions that make products now return Result.

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).
  • A new test gives the model a counting implementation and checks that the scores are identical and that the number of products is exactly what the configuration implies: none is made past the trait.
  • tools/mutants.sh all with both real models: 70 killed, 0 not killed, 17 skipped (GPU). Seven forward-pass patches no longer applied after the refactor and were regenerated; patch 71 is new (one product made directly, past the trait).

Review

The qwen reviewer asked for changes. Made:

  • The new test only proved that expert products go through the trait: its count of BF16 products was a lower bound, so one made directly would have passed. It is now exact, computed from the configuration, and patch 71 shows it bites.
  • CpuProducts::experts checks its output length; a missing doc comment; the Device error says the model must be restarted at position 0 afterwards.

Declined: a Send bound on the trait object. Nothing moves the model between threads, and a GPU device is tied to its thread by design.

@Defilan
Defilan merged commit 0e2a804 into main Nov 25, 2026
2 checks passed
@Defilan
Defilan deleted the agent/i2-t9a-products branch November 25, 2026 05:22
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