mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4730] [Engine] Metal 0.1.54 regression: conversation cache never parks a mid-sized conversation - the checkpoint's indexer-tail width and block_pos disagree with the Metal ring #2169
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2169
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @theBigGavin on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4730
Environment
0.1.54-metal, built from source at upstreammain870aedd9(2026-10-30), the tree the 0.2.8 notes describe--serve --pack ... --native ... --ple-gguf ... --expert-profile ... --expert-cache 64 --prefill auto --spec 2 --mtp ... --max-context 131072 --mmap-experts --conversation-cache-mib 16384 --conversation-cache-slots 4 --conversation-cache-min-tokens 20000 --vision --vram-reserve-mib 3072What happens
On 0.1.54 the conversation cache no longer parks a mid-sized conversation. Every park attempt over a ~24k-token conversation logs:
The same conversation on engine
0.1.44.1parks and restores in milliseconds, so this is a regression inside 0.1.45–0.1.54, not a property of the model or the machine.A larger conversation did park on 0.1.54 (
parked 66674 tokens in 57.5 ms,restored 66077 tokens ... in 28.9 ms), so the cache is not broken outright — the checkpoint payload check refuses the smaller one.The failing check, and what disagrees
With a temporary
STRATA_KV_DIAGprint inconversation_checkpoint_validate(src/core/conversation_state.cpp), the payload sizes are:Two fields disagree, both from the same source: Metal's indexer ring layout is wider than the contract the checkpoint layer validates against, and Metal has no
block_posat all.tails: the session holds 24576 bytes, the check expects 18432 (layers * z.tail = 12 * 1536).z.tail = (idx_block - 1) * idx_dim * sizeof(float)=3 * 128 * 4= 1536 —conversation_state.cpp,conversation_state_sizes()metal/src/engine/window.cppline 563tail_.push_back(A(4 * 4 * 128)), line 1511const size_t ts = 4 * 4 * 128, line 1518c.tails.resize(tail_.size() * ts)idx_dim-wide cell per layer.block_pos: the session holds 0, the check expects 48 (layers * sizeof(int32_t)).metal/src/engine/window.cpp,Window::checkpoint_saveends withc.block_pos.clear();block_posin the whole Metal tree.Why: three different contracts for the same ring
The raw-tail ring is backend-owned, and the two backends legitimately lay it out differently.
CUDA (
src/kernels/cuda/native_qsa_indexer.cu) keepsidx_block - 1rows and passes the completing cell in a register:Metal (
metal/kernels/qsa.metal,qsa_prep) keeps allidx_blockand reads them back:The two means are identical — only the saved ring differs.
conversation_state.cppvalidates against the CUDA width, so Metal's image is refused.block_posexists for a CUDA-only reason, and the header says so: it is a device-side record of the rotation position because a CUDA graph bakes kernel arguments in at capture time (include/strata/kernels/qsa.hpp, theQsaIndexerBuffersandrope_neoxnotes). Metal replays no graphs:window.cppbuilds a freshQsaArgsper dispatch and passespos_baseas a value argument, so itsblock_posis never needed — and was never implemented.Blast radius
Every Metal user who serves with
--mtp --conversation-cache*hits this on conversations below whatever size the 66k case was above. It costs the whole prompt read on every conversation switch — 50.6 s against 0.3 s on the same conversation and machine.What I did not do
I tried relaxing the check to the session's own ring width and stopped:
z.tailis also the serialization stride, not only the check.conversation_state.cppuses it as the per-layer stride at line 258 (copy(s + ple + j * z.tail, st.idx_tail, z.tail, ...)), line 302 (c.tails.resize(layers * z.tail)), and line 374 in the restore direction. Widening only the comparison would pass the check and then copy 1536 of 2048 bytes per layer, droppingblock_posand cropping the ring — a silent wrong-attention, worse than the refusal. So the three places that must agree are the two kernels and the serializer, and I do not have a CUDA box to validate a change to their shared contract.Options as I see them
idx_block - 1, ring-sum over three rows plus the completing cell in a register, and a realblock_posbuffer filled per completed block. Cleanest for the on-disk format; touches the Metal indexer's arithmetic, so it wantsqsa_parityat a context above the selection threshold.geometry_keyso an image is never read back by a backend with a different ring. Keeps both kernels as they are; changes the shared format and rules out cross-backend session files for this state.window_checkpoint_savereturns false and the image carries no checkpoints. Cheap, but I have not measured what parking still does without them.I have the
0.1.44.1engine still built and can re-test any of these on this machine; what I cannot do is a CUDA/HIP build or run. Happy to follow whichever direction is correct here.Reproduction status: reproduced locally, on the hardware and build above.
@hyspace commented on GitHub (Nov 2, 2026):
Confirming on stock engine
0.1.55-macos-arm64-metal(Apple M5 Ultra 96 GB, Qwen3.8-Flash-Next IQ3_S,--mtp --spec 2 --kv k8v4 --mmap-experts --conversation-cache-mib 8192): every park attempt on ~12K-token conversations logsso this is not limited to one model or one machine. I did not add a diagnostic print to our build, but reading the source agrees with your analysis:
Window::checkpoint_saveuses a per-layer tail stride of4 * 4 * 128and ends withc.block_pos.clear(), whileconversation_checkpoint_validateexpects(idx_block - 1) * idx_key_dim * sizeof(float)per layer andlayers * sizeof(int32_t)forblock_pos.A small repro that alternates two growing conversations (A1, B1, A2 reuses 0 tokens; A1, A2 reuses 11,944 of 11,965) is in #4144. On this build the memory-guard gap is independent: with
--memory-limit-miband--conversation-cache-min-free-mib 0set, the park still fails with the same payload error, so fixing only the macOS RAM reading would not make parking work.@hyspace commented on GitHub (Nov 3, 2026):
Correction to my comment above: this was already fixed on
mainind01b1817("Metal: conversations park and restore (#4730, #4144)"), which shipped in 0.2.10 / engine 0.1.56.Verified on engine
0.1.56-macos-arm64-metal(M5 Ultra 96 GB, Qwen3.8-Flash-Next IQ3_S,--mtp --spec 2 --kv k8v4): theinvalid checkpoint running-state payloadline is gone. In the A1, B1, A2 test (~12K tokens each), A2 now reuses 11,949 of 11,970 tokens after B ran in between; on 0.1.55 it reused 0. The log showsparked 11949 tokens in 24.4 msandrestored 11949 tokens (live) in 20.3 ms. Details in #4144.