Repository navigation
feat(lfm2): prompt reuse through the lane host's store - #823
Conversation
… their decode twin Adds core/tile_qmm: 32 x 32 bf16 MMA tiles on the exact MLX affine codes (4, 6 or 8 bits, groups of 64), with fp32 group sums in k order. Adds grouped tiles for rows sorted by expert, a fused gate-up GLU tile, and a twin for 1-32 rows that gives the same bits as the tiles. tf-tile-check (no model) checks the tiles, the twin and the grouped tiles bit for bit. tools/zig/tile_qmm_reference.py compares them with float64.
…affine Adds the LFM2 family on the lane core: 30 short-conv layers, 10 attention layers and 64 experts with 4 active. Prompt rows use core/tile_qmm, and decode rows and verify windows use its twin. Attention uses fixed 4,096-key chunks. Thus prompt, decode and window rows give the same bits. tf-lfm2-exact checks prompt chunks, windows, partial keeps and two streams in one window against one-row decode on the real weights.
Keeps the conv states and the attention keys and values up to a mark in host memory, and restores them in the prompt pass. --prompt-cache-gib sets the budget, as for the other families.
|
Hello @BlivionIaG, Thank you for prompt reuse through the LFM2 lane host. An exact-length prompt skips restore, and a failed restore starts the prompt over. This lands with #822, after #821. We wrap native/lfm2.zig:70, native/lfm2.zig:63, backend.zig:131, snapshot.zig:69, and README.md:177. The gate is the same tf-lfm2-exact run on the named weights. Thank you. |
At 4 bits the twin multiplied input j by 16^-j and left code j in place. The product is the same unless x * 16^-j leaves the float range: x[7] = 2^-126 gave 2^-154, which underflows to zero, while the tiles decode the integer and keep 2^-126. The twin now decodes the integer code. tf-tile-check adds the case: 4 bits, K 64, code 7 is 1, scales 1, biases 0, x[7] = 2^-126. The tiles and the twin at widths 1 to 32 must all give bf16 0x0080.
…onversion Each 4-bit word gives its eight codes as exact integers: codes i and i + 4 go into the mantissas of a half pair as 1024 + code, and 1024 is subtracted. This replaces the shift, mask and integer-to-float convert of every code. The codes, the products and the fma order are the same, so the bits are the same; tf-tile-check, its 0x0080 case included, gives the same output.
…717) onto the candidate # Conflicts: # CHANGELOG.md # zig/src/native/metal.zig
…717) CHANGELOG in landing order; the other files both sides changed merged clean (LFM2's open branch sits after the --vision refusal, so an LFM2 checkpoint served with --vision is refused by name).
|
Thank you, @BlivionIaG. Prompt reuse is what makes the family usable for chats and agents, and keeping the conv states and the bf16 keys and values, restored by the prompt pass itself, matches how Nemotron and the 27B do it. It ships in TensorFold 1.0.12 under your name ( On an M3 Ultra at 4, 6 and 8 bits, two multi-turn chats (three turns, then regenerate, edit and delete) gave the same tokens with the prompt cache on as on a server with it off, 12 of 12 steps at each width, and resumed most of each prompt (7,128 of 7,156 tokens on a second turn). With the cache on, each We merged Posted by Ash's AI Assistant Synthena |
…ld benchmark (ashhart#717) onto the candidate # Conflicts: # CHANGELOG.md # zig/src/native/metal.zig
…ld benchmark (ashhart#717) CHANGELOG in landing order; the other files both sides changed merged clean (LFM2's open branch sits after the --vision refusal, so an LFM2 checkpoint served with --vision is refused by name).
…ed under families/lfm2_moe The contributor's commit landed in this release with our wraps and the move to lfm2_moe; its head carries ashhart#822's. This keeps the PR's head in the history and changes no file.
…shhart#862, ashhart#863, ashhart#864, ashhart#866, ashhart#821, ashhart#822, ashhart#823, ashhart#851, ashhart#738, ashhart#523, ashhart#547 and ashhart#875, with the HIP and loader fixes
What this changes
This pull request connects the LFM2 family to the prompt cache of the lane host. It is part 3 of 3 for #820.
It needs part 2, #822. This branch contains the commits of parts 1 and 2. Review only commit acd43b4. The merge commits after it only bring in main and parts 1 and 2.
How it works
A kept state holds:
The engine copies the state to host memory at the marks of the store. The prompt pass restores the state and continues from the mark.
--prompt-cache-gibsets the budget, as for the other families.Prompt rows give the same bits with each chunk size, and decode rows give the same bits as prompt rows (part 2). Thus a resumed reply can be equal to a fresh reply. The test below checks this.
Receipt
Files:
lfm2-receipts, runc88bd868:tf_two_turn.json,tf_two_turn_cold.json,mlx_two_turn.json,scripts/two_turn.py.Environment: Apple M4 Pro (20-core GPU), 48 GB, macOS 26.5.1. Checkpoint
LFM2.5-24B-A2B-MLX-4bitat667408d494bde191c2cb9dd4f4549827816b9275. TensorFold at c88bd86: itszig/srcandzig/kernelstrees are equal to this branch before the merge of main c7137bb (acd43b4). I did not run the two-turn test again after the merge. mlx-lm 0.32.0 server (mlx 0.32.3). Requests: chat, temperature 0, streamed.Exactness: turn one is a system message and a user message with an excerpt of TensorFold's
CHANGELOG.md(7,991 prompt tokens). Turn two adds the reply of turn one and one question (8,055 prompt tokens). The reply to turn two with the cache on was equal to the reply with--prompt-cache-gib 0. The repeat of turn two also gave an equal reply.TTFT:
--prompt-cache-gib 0Decode and prompt speed before and after: with
--prompt-cache-gib 0, this change does not run. The cold numbers in part 2 ran with the cache off.Memory: the peak physical footprint of the TensorFold server with the cache on, for this test, was 14.8 GB (
tf_cache_footprint.txt).Tests run, after the merge of main c7137bb (head 5a6ee03), each with an empty build cache:
zig build test test-golden -Dcpu=apple_m1: 166 of 166 steps succeeded; 1,987 of 1,995 tests passed, 8 skipped, 0 failed. Golden: 0 unexpected differences. Main c7137bb gives 1,981 of 1,989 passed, 8 skipped.zig fmt --check: clean.tools/zig/lean_check.py: 527 problems, the same as main.tf-lfm2-exactwith the real weights after the merge: 54 passed, 0 failed, at 4, 6 and 8 bits.Not run, and why: CUDA (this family has no CUDA path). Other Macs: M4 Pro above, M5 Ultra below; I did not test M1 to M3. Eviction under a small budget: I did not test it for this family.
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted and concurrent: part 2. Resumed: above.)Apple M5 Ultra
The same code (5a6ee03) and the same two-turn test on an Apple M5 Ultra (64-core GPU, 256 GB, macOS 27.0). Files:
runs/m5-ultra-5a6ee034on the fork (tf_two_turn.json,tf_two_turn_cold.json,mlx_two_turn.json).--prompt-cache-gib 0The reply to turn two with the cache on was equal to the reply with
--prompt-cache-gib 0, and so was the repeat.