Skip to content

lfm metal: a keep that drops nothing skips its copy - #3078

Merged
ashhart merged 5 commits into
mainfrom
lead/lfm-d820
Nov 21, 2026
Merged

ashhart merged 5 commits into
mainfrom
lead/lfm-d820

Conversation

@ashhart

@ashhart ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What this changes

In a shared round, LFM2-MoE and LFM3 on Metal copied each stream's conv state and logits back in Cache.keep even when the keep kept every row of the round. That copy is about 0.5 MB a stream a round on the CPU, inside the GPU's idle gap. commit and run already wrote the same conv row, logits and length, so a keep that drops nothing now returns early. A partial keep still restores, through a new take().

  • Issue: n/a (from a read of the LFM Metal decode path).
  • Stacked on: main.

Checks on this head

  • Lean checker: 345 on the base and on this head, 0 new. zig fmt --check: clean.
  • compile-metal-residency-host and check-metal-prefill-rest-host: 14/14 steps. The two new state tests (a full-path keep leaves conv buffers, logits and length byte-identical with no copy; a partial keep still restores) compile here and run on a Mac with a GPU.
  • Not run here: test-lfm2, zig build test and the LFM3 exactness tool, which need a Metal device. We'll run them on an M5 Mac before landing.

Receipt

  • Main against branch: owed, on an M5 Mac. LFM2-MoE and LFM3 at 1 and 4 streams, greedy and seeded: replies byte-identical, decode within noise or faster.
  • Exactness: by construction, the skipped copy writes the bytes already there; device check owed.

Checklist

  • The title and description match the head commit.
  • No precision traded for speed: same arithmetic per row.
  • Comments and docstrings are one line.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

LFM2-MoE and LFM3's Cache.keep return early when the path keeps every row
of the last round. The recorded call already left that state: commit()
restored the last row's conv state, run() copied its logits, and len is
start + rows. A full path skips about 0.5 MB of copying a stream per
shared round; a partial path still copies, through a private take().
New state tests check both paths against the copy, byte for byte.
@ashhart
ashhart merged commit eeceb11 into main Nov 21, 2026
11 checks passed
ashhart added a commit that referenced this pull request Nov 21, 2026
@ashhart
ashhart deleted the lead/lfm-d820 branch November 21, 2026 07:13
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