Repository navigation
Flash Next: --learn keeps shared prompt prefixes on disk, on one Mac - #519
Conversation
The native server's Flash Next host writes the prompt cache's shared cuts to disk under --learn-dir and reads them back in later sessions and servers, as GLM does. learned.zig holds a kept state's file format (header, then the pool buffer's bytes), the kernel source hash and a startup probe (one prompt pass over fixed tokens, two marks' states hashed) that keys this build's bits; the imprint identity also takes the checkpoint identity text pack_io computes, the xnew / hc_up / tensor-unit modes, the OS build and the chip. A speed-up pair refuses --learn with a message: rank 1's halves are not persisted yet. M5 Ultra, Flash Next 4-bit MTP, a 4,985-token system prompt: a fresh server read the 4,455-token learned state back in 33 ms and computed the remaining 530 tokens in 287 ms; every reply equals the cache-off server's. A rebuilt binary keyed to the same states. Startup 19.6 s with --learn against 19.1 s without.
bffd5b3 to
be6293f
Compare
|
Thank you, @BobClawblaw, and sorry it waited. Main had moved 368 commits since 1.0.2, so we rebased it for you: merge Our gate, on one M5 Ultra with
Every reply on every server equalled the cache-off server's, all four turns. We didn't run the speed-up pair; its refusal is from reading the code. |
…n disk, on one Mac Thanks @BobClawblaw. Rebased onto 1.0.6's candidate by the merge: packs stay in main's cache folder with the identity hash beside them, open() takes --learn with main's error mapping plus the pair refusal, and the docs list Flash Next beside GLM and Nemotron. The PR's commit lands with its AI co-author line left out.
…rves Nemotron; the served list names the 27B
…n disk, on one Mac Thanks @BobClawblaw. Rebased onto 1.0.6's candidate by the merge: packs stay in main's cache folder with the identity hash beside them, open() takes --learn with main's error mapping plus the pair refusal, and the docs list Flash Next beside GLM and Nemotron. The PR's commit lands with its AI co-author line left out.
The author rebased ashhart#519 onto main after our merge; this keeps the PR's current head in the history with no change to the tree.
…rves Nemotron; the served list names the 27B
--learnfor Flash Next on the native server, as GLM has it: shared prompt prefixes (a system prompt and its tools) go to disk, and a fresh server, or an upgrade that computes the same bits, resumes them without reading them again. ZIG-PREVIEW's known gap "Nemotron and Flash Next keep theirs in memory", the Flash Next half.What changes
zig/src/families/flashnext/learned.zig(new, 123 lines): a kept state's file (<key>.bin: header with position, layout, size and the n-gram history, then the bytes; written to a.partand renamed), read back into a buffer from the engine's snapshot pool;sourceHash()over the checked-in kernel sources and roles; andprobe(), a prompt pass over fixed tokens (a full call, a middle and a short one) with two marks whose kept states are hashed.zig/src/families/flashnext/snapshot.zig:blank(), an empty state in a pool buffer for a file to fill;layoutOfpublic.zig/src/families/flashnext/engine.zig:identity_hash, the checkpoint identity textpack_ioalready computes, hashed and kept.zig/src/native/flashnext_host.zig:write/read/forgeton the store's vtable (a read-back state is named by the request's tokens as a saved one is, soh.promptis set beforestore.begin),learnedStates()opening the imprint under--learn-dirkeyed by checkpoint identity, kernel sources, the xnew / hc_up / tensor-unit modes, the probe's bits, OS build and chip;opentakeslearnandlearn_capand refuses--learnon a speed-up pair with a message.zig/src/native/metal.zig: passes--learnthrough, as for GLM.One Mac for now. A speed-up pair keeps rank 1's halves of each state under the same key over the link (
peer_kept); persisting those on rank 1 and loading them back in step with rank 0 is the GLMmirror .persist/.load/.forgetpattern, and I have one Mac here, so the pair refuses--learnplainly rather than half-working.Measured
M5 Ultra (256 GB, macOS 27.0.1), Zig 0.17.0, Metal Toolchain 27A266a,
TensorFold/Qwen3.8-Flash-Next-MLX-4bit-MTPat 2b170fa6, checked-in kernels (no dump), greedy, 96-token replies, a four-turn chat on a 4,985-token system prompt (the repo README):--learn, first chat--learn--prompt-cache-gib 0--learn, 19.6 s with it (the probe is one 4,143-token pass with two marks).Checks
zig build test -Dcpu=apple_m1: passes.zig/src/cudaor the Python engine is touched.Docs
README's
--learnrow (GLM and Flash Next on one Mac), ZIG-PREVIEW's Flash Next paragraph and known gaps.Independent of #497, #499, #502 and #518 (no overlapping hunks; #499 is the Nemotron half of the same gap and edits the same README cell, a one-line merge either way).
🤖 Generated with Claude Code