Skip to content

perf(cuda): one host copy per expert step; the query-input products as one - #28

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

Defilan merged 5 commits into
mainfrom
agent/i2-fusions

Conversation

@defilan-agent

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

Copy link
Copy Markdown
Contributor

Milestone I2. Two small fusions in the on-device forward pass. Results are unchanged.

What is in it

  • blockmat.rs: BlockMat::run is split into encode (checks a job list against its buffers and returns the bytes the kernels read) and an unsafe start (launches from a list already on the device). run is encode, copy, start, as before.
  • ops.rs: the expert step hands the chosen experts' weights and both job lists to the device in one copy into one buffer, where it made three.
  • ops.rs: the four BF16 products that read the query input (queries, output gate, relative-position vectors, sinks) are one product over weights stacked in one device buffer; its result is cut into four runs.

Measured on a GB10, real Inkling 2 Mini, greedy, 90 tokens

Step Tokens per second Per token
Before 24.5 40.9 ms
One host copy per expert step 24.6 40.6 ms
The query-input products as one 25.1 39.8 ms

About a millisecond between them. The single-position path has small returns from here; the larger step is several positions per sweep, which comes next.

How it was checked

  • GB10, CUDA 13.0: cargo test --release -p dluth-cuda with the real checkpoint, 50 tests; the golden figures are the same as before the change (real model 96 of 96 tokens, largest difference 0.00005). Format check and lint clean across the workspace.
  • Planted bugs (# needs: gpu), each applied in turn on the GB10 and seen to fail: 89 regenerated after the code moved; 92 (the output gate cut from the wrong part of the stacked product) and 93 (the experts' second matrices started with the first matrices' job list) are new.
  • Mac: lint clean; the default members are untouched.

Review

The qwen reviewer approved with nits and no must-fix: it traced the list offsets and their 8-byte alignment, the cut offsets of the stacked product, and that the results are the same as before. Made: start checks the list's address, the job count and the grid size itself, so the unsafe seam does not rely on its two callers for those.

Its open questions hold: a job is 88 bytes, a multiple of 8; stacked has two call sites, both in this diff; every expert step follows the fetch of the router's scores, which waits for the device.

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