Skip to content

LFM2.5-24B-A2B on CUDA: one helper for every prompt-stream write a keep reads, and a test that fails if a writer skips the wait - #2989

Merged
ashhart merged 9 commits into
ashhart:mainfrom
jschmied:lfm2-side-waits
Nov 16, 2026
Merged

ashhart merged 9 commits into
ashhart:mainfrom
jschmied:lfm2-side-waits

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

Stacked on #1503 (head 550690618); base main. Follows Synthena's suggestion on #1503 (comment 6806587680): one helper all five prompt-stream writes go through, and a host test that fails if a writer skips the wait. The head is ccd047085, one commit; it touches only zig/src/families/lfm2_moe/cuda_backend.zig. Once #1503 lands, this diff is that one file.

What

  • Lfm.fenced() (cuda_backend.zig:180) returns the prompt stream after it waits on the device for the keeps' done (cuda_snap.Pages.fence, unchanged).
    • The five writes take their stream from it as an argument, so none can be queued before the wait: the slot clear (opening), a chunk (chunk), a one-row step (queue), a verify round (verify) and a commit (keep).
    • Before, each called Lfm.settle() on the line above and then passed x.s. That helper is gone.
  • The test (cuda_backend.zig:532) reads the backend's own source, up to its tests.
    • It finds every fwd.forward(, fwd.commit( and .clearSlot( call and requires the stream argument to be try x.fenced().
    • It also requires exactly five such calls, so a sixth write names itself there.
    • Planted in the same test: each of the five, in turn, put back on x.s without the wait. Each is caught (one unfenced write) and all five are counted.
  • fenced() test (cuda_backend.zig:564), with a fake driver:
    • Without a prompt cache it issues no wait.
    • With a keep pending it issues exactly one wait, the prompt stream on done.
    • A second call issues none until the next keep.
  • The restore fence stays in snap.restore. lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's ordering test (cuda_snap.zig:340) and its three planted orders are unchanged; cuda_snap.zig isn't touched.

Shared core or LFM2 only: LFM2 only. Every other side stream joins inside the same pass: FlashNext's shared expert (flashnext/cuda_batch_side.zig fork/join), GLM's L2 prefetch (glm/cuda_l2pf.zig), Nemotron's side, and DeepSeek-V4.1's L2 prefetch and overlapped ingests (deepseek_v41/l2pf.zig, dspark_slots_ingest.zig). None leaves work pending for later writers to fence. The other families' keeps (Dory, Gemma 4, FlashNext, GLM, Qwen3.5) copy on the prompt stream. So no second caller exists to share a helper with. If another family moves its keeps to a side stream, Side and fenced would move to core together.

Hot path: no change to launches or kernels.

  • Each writer issues the same driver calls in the same order: the wait (only if a keep is pending), then the write. In Zig, the stream argument is evaluated before the call, and the arguments before it are field loads.
  • No .cu, .cuh or build file changes, so every fatbin and its SASS is the same build output.
  • No speed A/B, per the brief for a hot path that doesn't change.

Proposed CHANGELOG line, under Unreleased: "LFM2.5-24B-A2B on CUDA: every prompt-stream write that a keep reads takes its stream from one helper that waits for the keeps, and a host test fails on a write that doesn't (#NNNN, stacked on #1503)."

Verification (on ccd047085)

  • Host tests, GB10: zig build test-lfm2-moe-cuda-host 20/20. zig fmt --check clean.
  • Planted control on the real source: in a separate worktree, the verify round is put back on x.s (try fwd.forward(x.m, x.k, x.s, chains, ...)). The test fails at cuda_backend.zig:536 (expected 0, found 1, 19/20). Restored, the head is green as above.
  • x86 (10.0.0.8, tfci): zig build -Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths, check-native-cuda-host compile-cuda-tests, zig fmt --check, pr_check with lean: 694/694 steps, 3629 tests (2 more than lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's 3627), lean 386 vs 386 on the base (0 new), pr_check 0 errors (1 warning: the CHANGELOG line is in this body).
  • Served gates, GB10, real weights (LFM2.5-24B-A2B MLX4): this head's native ReleaseFast build against main 673a34b3b (lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's base), keeps on. GATES_OK.
    • Multi-turn chats (8 conversations × 4 turns): the cold first turn plus warm turns resumed from keeps (24 hits). Every reply equals main's, greedy and seeded (32 seeded hits); concurrent equals solo; drafted equals plain.
    • The same holds with the cache off, with fixed pages (TENSORFOLD_LFM2_KV_PAGES=0), under pool pressure (8 long concurrent prompts) and with a 0.1 GiB cache. A restarted server's replies are equal too.
    • The after-drain census is clean on every arm.
    • The reply hash d3c46363c6bb8d5d is identical on all five arms to lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's run on 550690618.
  • A refusal doesn't apply: no new refusal. Concurrency and seeded rows are in the served gates above. Resume is the warm turns (a restored keep).

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, this is the follow-up we suggested on #1503, and it's done well.

  • Lfm.fenced() (zig/src/families/lfm2_moe/cuda_backend.zig:180) is now where all five writes get their stream: the slot clear, a prompt chunk, a one-row step, a verify round and a commit. Each one issues the same driver calls in the same order as before.
  • The source test (:532) requires each of those calls to take try x.fenced() and counts them, so a new fwd.forward, fwd.commit or clearSlot call fails it until it's fenced and counted. Putting any one of the five back on x.s is caught.
  • The fake-driver test (:564) pins the wait down: no wait without a prompt cache, exactly one on done after a keep, and none again until the next keep.

No kernel or build change, and the served replies hash the same as #1503's run. CI is green and it merges cleanly with main. It lands right after #1503, as one file on top of it.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@jschmied main moved under this and it conflicted with main in docs/environment.md zig/src/platform/environment.zig zig/src/platform/environment_test.zig (it builds on #1503, rebased first), so the landing train left it out. To save you a round trip we rebased it onto current main and pushed it to your branch: each conflict keeps main's change and yours, and your commits and authorship are otherwise unchanged. The host tests for its files, the serving-pin check and our privacy gate pass on the new head. It goes back in the landing queue once its CI is green. No other asks.

  • Synthena (Ash's Agent)

jschmied and others added 9 commits November 16, 2026 00:42
…m leasing

The kernels already read keys and values through a slot's page table, so the pool changes only what the
table holds and how large the arena is; no kernel changes. A page is 512 positions of the ten attention
layers' keys and values (10 MiB, 20 KiB a token); the conv states stay a fixed part a slot (240 KiB).

- Loaded.layout with engine_paged, as Dory's: the plan sets a window of pages aside for the first stream;
  each stream leases its prompt, its reply and one verify window at its prompt pass and gives them back
  when it ends. A request that cannot lease waits (LaneMemory); fits is the host's admission.
- Model.attach makes the arena and the tables and conv states of the slots the plan names; forward refuses
  rows past a slot's pages. The idle server logs the pool's census.
- TENSORFOLD_LFM2_KV_PAGES=0 keeps every stream's own window of pages, made at open.

Served on the GB10 at --parallel 8, 16k: drafted == plain and concurrent == solo, also with 8 long prompts
on a 52-page pool where the last waits for pages; the replies equal the fixed pages' ones.
…the pages' rows through its position

A state at `at` is the slot's conv states and its keys and values at positions [0, at) of the ten attention
layers: one copy a run of consecutive whole pages, then the last page's rows a layer's keys and values. It is
copied behind the chunk that ends at the mark and restored into the new stream's leased pages before its next
chunk, so a later turn's pass starts at its history. Lookahead 0, as the other headless families.

States live in 2 MiB snapshot pages allocated once at startup inside the prompt-cache budget (`snap_ready`), as
GLM's: a keep or a restore leases or reads pages and allocates nothing, and a dropped state's pages go back to the
pool at once (every copy that reads or writes them is queued on the backend's one stream). The store counts held
and spare pages through `snap_charged` / `snap_spare` / `snap_reuses`.
…dds no pass

A chat mark inside a prompt chunk ended the chunk there, and every extra prompt pass reads the weights once more: a
cold 10k chat turn, whose two marks sit in its last chunk, ran 12 passes instead of 10. Now up to four marks inside a
chunk are tapped instead: the conv kernel runs once more on each mark's last row alone, writing the same y and that
row's conv states into the model's tap buffer, and the keep copies those states with the K/V rows before the mark.
The pass goes on to its grid line; a fifth mark still ends it. The kernel is unchanged.
…hich waits for the keeps

A clear, a chunk, a one-row step, a verify round and a commit each queue on the stream fenced() hands back,
after the keeps' copies queued so far. A host test reads the backend's writes and fails on one queued on
the prompt stream without the wait; each of the five planted that way goes red.
@ashhart
ashhart merged commit b4f1bf2 into ashhart:main Nov 16, 2026
12 of 20 checks passed
@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart A correction, now that this has merged. The served-equality rows in this PR and in #1503 rest on a vacuous hash. The gate script compared message.content only. With thinking on by default, the short gate turns produce only reasoning_content, so every arm hashed 32 empty strings (d3c46363c6bb8d5d). "Equal to main" was therefore not shown for replies.

The kernel contract, the planted controls, the host tests and the timings are unaffected.

I'm rerunning the served gates now with a fixed script that hashes reasoning and content together and fails on any empty reply. The runs compare LFM2.5 on main at this merge against main before #1503, greedy and seeded, resumed, concurrency 4 and 8, drafted, and across a restart. I'll post the result here. If any reply differs, I'll open a fix right away.

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Here are the corrected served-equality rows for #2989 and #1503. The rerun used the fixed gate, which hashes reasoning_content, content, the reply's token ids (return_token_ids) and token_sha256 together, and fails on any empty reply. Every reply was equal and none was empty.

The run compares main at this merge, b4f1bf263c (native md5 a2869110), against main just before #1503's commits, 4bf995ce31 (md5 8bc2af4c). That is the parent of 83ad23d88c, the first of #1503's eight commits on main. The checkpoint was LFM2.5-24B-A2B MLX 4-bit, with --parallel 8 and the same arms as the earlier run.

arm replies compared non-empty equal hash prefix
4bf995ce31 fresh, greedy + seeded multi-turn 64 64 reference ef6ea8ecf5f099c0
b4f1bf263c prompt cache (24 of 32 turns hit) 136 136 yes ef6ea8ecf5f099c0
b4f1bf263c no prompt cache 120 120 yes ef6ea8ecf5f099c0
b4f1bf263c fixed caches (TENSORFOLD_LFM2_KV_PAGES=0) 120 120 yes ef6ea8ecf5f099c0
b4f1bf263c small pool (memory limit 14 GB) 136 136 yes ef6ea8ecf5f099c0
b4f1bf263c 0.1 GiB prompt cache 120 120 yes ef6ea8ecf5f099c0
4bf995ce31 solo, concurrency 4 and 8, seeded, draft off 56 56 yes, to b4f1bf263c 466d480531e50d4c
b4f1bf263c after a restart 32 32 yes ef6ea8ecf5f099c0

Each b4f1bf263c arm checks four things. Resumed multi-turn replies, greedy and seeded, equal the fresh replies on 4bf995ce31. Concurrency 4 and 8 equal solo, greedy and seeded. Drafted replies (copy drafts on) equal plain replies (draft: false). The pool census is clean after every drain. The cache and small-pool arms also run eight ~6k-token prompts at once against solo. The hash prefix covers the 32 greedy multi-turn replies, or the eight solo replies in the concurrency row.

In all, 784 replies were compared, all 784 non-empty, carrying 43,520 tokens with ids. These short turns are still all reasoning, so content is empty on every reply. The equality rests on the reasoning text and the token ids.

These rows replace the vacuous ones I flagged earlier on this thread.

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.

2 participants