Repository navigation
GLM: a kept state copies its prefixes out of its slot before the slot writes below it - #644
BobClawblaw wants to merge 1 commit into
Conversation
… writes below it A resident prompt state holds only its KDA states; its MLA prefixes stay in the slot that made it. Once every slot holds a stream, a new prompt pass can still write over one, and the state goes stale (ashhart#622 picks a slot that avoids this while one is free). Now Slots.overwrite first asks the prompt cache for the prefix bytes (Store.grow: only from the budget's room, never evicting during a pass), copies the slot's MLA rows into a whole-state buffer beside the KDA states, and the state no longer has a home slot. Without the room it goes stale as before. A whole state restored into a slot now protects that slot's resident states the same way another slot's state does. A pair keeps its states resident as before. Six conversations on four slots (GLM_LAYERS=8, --parallel 4), turns in order, then four at once, then in order: 34,872 of 47,150 prompt tokens cached against main's 18,162, failed restores 9 to 0, about 18 KB a prompt token copied out, and all 24 replies equal main's.
06a56b7 to
da70538
Compare
|
Thank you, @BobClawblaw. This landed in 1.0.8 as your own commit ( Our commit on top ( After #639 this applies to one Mac with We measured it on one M5 Ultra with
The pair followed in 1.0.8 too. Its first Mac sends each slot command before running it, so the copy is decided before the send: the first Mac picks the states the budget has room for and sends their ids, and the second copies its half of the same states ( Copying only from the budget's free room, and never evicting in the middle of a pass, made this an easy change to trust. |
GLM's kept prompt states move from slots.zig (631 lines with ashhart#644) into kept.zig: save, restore, the overwrite that copies a resident state's prefixes out of its slot or marks it stale, the probe, the learned-state reads and writes, and the pick of a new stream's slot. Slots keeps their names as aliases, so no caller changes. ashhart#644's comments are one line each, its write-only spill counter goes (the log line records each copy), and the unused Slots.free goes. No behaviour changes. Co-authored-by: BobClawblaw <[email protected]>
The change landed rebased over ashhart#639 as 3e02e29d4 with its author kept; this keeps the PR's head in the history with no change to the tree.
… the slot writes below them ashhart#644 made one Mac's slot mode copy a resident kept state's MLA prefixes into a whole state, when the prompt cache's budget has room, before a new stream writes over its slot. A pair could not: rank 0 sends each slot command before it runs it, so the copy has to be decided before the send. The backend now decides before a restore that writes a slot's rows and before each prompt chunk. The states it makes whole (Store.grow, from free room, never evicting during a pass) go to rank 1 as one copy_out command with their ids, and rank 1 makes the same states whole from its own slot: its share of the KDA heads, and the MLA prefix, which TP does not split. The overwrite inside the chunk or restore then marks stale only what was not copied, on both Macs alike. If a copy fails, the ids already copied are sent before the error returns, so the Macs never disagree. One Mac takes the same path with nothing to send, so its copies are ashhart#644's. Co-authored-by: BobClawblaw <[email protected]>
…nd the least-recently-used GLM slot pick (extends ashhart#622)
GLM's kept prompt states move from slots.zig (631 lines with ashhart#644) into kept.zig: save, restore, the overwrite that copies a resident state's prefixes out of its slot or marks it stale, the probe, the learned-state reads and writes, and the pick of a new stream's slot. Slots keeps their names as aliases, so no caller changes. ashhart#644's comments are one line each, its write-only spill counter goes (the log line records each copy), and the unused Slots.free goes. No behaviour changes. Co-authored-by: BobClawblaw <[email protected]>
The change landed rebased over ashhart#639 as 3e02e29d4 with its author kept; this keeps the PR's head in the history with no change to the tree.
… the slot writes below them ashhart#644 made one Mac's slot mode copy a resident kept state's MLA prefixes into a whole state, when the prompt cache's budget has room, before a new stream writes over its slot. A pair could not: rank 0 sends each slot command before it runs it, so the copy has to be decided before the send. The backend now decides before a restore that writes a slot's rows and before each prompt chunk. The states it makes whole (Store.grow, from free room, never evicting during a pass) go to rank 1 as one copy_out command with their ids, and rank 1 makes the same states whole from its own slot: its share of the KDA heads, and the MLA prefix, which TP does not split. The overwrite inside the chunk or restore then marks stale only what was not copied, on both Macs alike. If a copy fails, the ids already copied are sent before the error returns, so the Macs never disagree. One Mac takes the same path with nothing to send, so its copies are ashhart#644's. Co-authored-by: BobClawblaw <[email protected]>
…nd the least-recently-used GLM slot pick (extends ashhart#622)
The follow-up #622 left open: once every slot holds a stream, a new prompt pass can still write over a slot that a kept state's MLA prefix lives in, and that state goes stale. This copies the prefix out of the slot first, when the prompt cache has room for it.
The change
A resident prompt state holds only its KDA states. Its MLA prefixes stay in the slot that made it (
Snap.home).Slots.overwritenow asks the prompt cache for the prefix bytes before the slot writes below a resident state.Store.growgrants them only from the budget's free room and never evicts during a pass.The copy is about 18 KB a prompt token (
(kv_lora + 2 * index_head_dim) * 2bytes across 12 MLA caches, the MTP head's among them).Measured
GLM_LAYERS=8 --parallel 4, six conversations on four slots: turns in order, then four at once, then in order again.All 24 replies equal main's.
zig build testpasses, with a newprompt_cache_test.zigcase forStore.grow.