mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3536] [Engine] metal: the session no longer holds unused QSA K/V pools (6.4 GiB resident at 262K context) #4673
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#4673
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?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3536
Author: @oceanio
Created: 10/21/2026
Status: 🔄 Open
Base:
main← Head:pr/metal-session-kv-solo📝 Commits (2)
98efff3metal: the session's QSA states carry no K/V pools or pooled indexer keys (the decode window keeps its own)036d07adocs (Mac): the engine's own memory grows with --max-context; what it was before the session K/V change📊 Changes
2 files changed (+21 additions, -0 deletions)
View changed files
📝
docs/MAC.md(+1 -0)📝
src/core/layer.cpp(+20 -0)📄 Description
Problem and result
On the Mac (Metal) engine the decode window (
metal/src/engine/window.cpp) keeps its own K/V and pooled indexer keys for the 12 QSA layers, sized by--max-context. It never reads or writes the session's QSA K/V pools, butkv_planstill sizes them for the whole context. On Metal a session buffer is one sharedMTLBufferin the residency set, so those pools are resident in full whether anything touches them or not: about 24.6 KB per context token.Measured first on main 0.2.1.4 (phys_footprint of the engine 5 s after it is loaded, Qwen3.8-Flash-Next IQ3_S, M5 Max):
--max-contextThe same 6.4 GiB is still saved after 9 requests (24.91 → 18.53 GiB at 262K). Output and speed do not change (Validation).
Since v0.2.9 each Metal batch slot has its own session, and the saving applies to each: with 2 slots at 262K the engine holds 18.15 GiB instead of 37.28. On v0.2.10 the numbers are the same (Validation).
Related discussion
None. This is a focused fix. Context: since v0.2.10 the Metal engine parks conversations, through session QSA states that the window binds to its own K/V (
Window::bind_session/bind_draft), so they need no pools of their own. Parking works the same with this PR. Session files fail on v0.2.10 on a Mac for two other reasons, with or without this PR; #3541 fixes those, and with it on top they work with this PR too (Validation).Approach
src/core/layer.cpp,kv_plan: under#if defined(STRATA_GPU_METAL)a QSA state gets 0 K/V slots and 0 pooled indexer rows.qsa_state_initthen leaves the pool pointers andidx_poolednull, so they do not alias the page table orblock_posthat follow. The page table, the indexer tail and dead rows,block_posand the RoPE tables are carved as before.Window::bind_session/bind_draft, v0.2.10), so parking and session files read the window's K/V. Until a state is bound,n_slots == 0makes a conversation snapshot refuse it (conversation_snapshot.cppvalid) instead of reading pools that are not there.docs/MAC.md: one line saying that the engine's own memory grows with--max-context, with the numbers before and after.unifdef -USTRATA_GPU_METAL src/core/layer.cppgives the same file before and after.Validation
Re-run on v0.2.10 (2026-11-03). Rebased onto main
ffa80d73(v0.2.10). The code lines are the same; thekv_plancomment now names the window's binding (Approach). At the new tip036d07ac, one round per setting against v0.2.10's own build, the same procedure as below:--max-context"parallel": 2)tools/parking_test.pywith #3541's log-path fix, 28,692 tokens, with MTP): the follow-up after A, B, A is identical to the one that never parked (95/95), as on v0.2.10.session_restart_test.pyat 3,785 and 28,785 tokens, with and without MTP: restored in a new engine, follow-up identical, the whole conversation reused. Without them they fail as on v0.2.10.unifdef -USTRATA_GPU_METAL src/core/layer.cpp: identical to v0.2.10's.Re-run on v0.2.9 (2026-11-01). Rebased onto main
c62d5e3a(v0.2.9) with no conflicts; the commits are the same lines. v0.2.9 gives the Metal engine batch slots, each with its own session, andkv_plansizes their QSA pools as it does the main session's, so this PR now drops theirs too. At the new tip30ec0885, one round per setting against v0.2.9's own build, the same procedure as below (the batch round adds two requests sent 1 s apart, which run in the two slots):--max-context"parallel": 2)two requests that ran side by side (10 of 10).
93.6 94.0 92.1 95.4 and 93.6 94.0 92.1 95.2; with 2 slots, 93.7 94.4 92.1 95.3 and 92.5 94.1 92.4 95.9. (One round.)
unifdef -USTRATA_GPU_METAL src/core/layer.cpp: identical to v0.2.9's.The rest of this section is the first run, on
9de04cd4.Environment: Apple M5 Max (128 GB), macOS 26.7.1, Apple clang 21.0.0. Both builds from the same checkout procedure (
cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release, targetstrata): main9de04cd4and this branch (9de04cd4+ 2 commits). Model: Qwen3.8-Flash-Next GSQ-RCO IQ3_S (SC117's abliterated build, two-file layout), resident,--expert-cache 64 --prefill auto --spec 2 --mtp <rt> --mmap-experts, through each tree's ownserve/server.py. Runs alternate main / PR / main / PR at each context, 30 s apart.Passed:
layer.cpp.unifdef -USTRATA_GPU_METAL src/core/layer.cpp: identical to main's (cmp).Failed:
None observed.
Not run:
layer.cppis compiled by every backend, so this stays a draft. Could someone build it on one of them? The change is entirely inside#if defined(STRATA_GPU_METAL), and the unifdef check above is my only evidence for the other backends.--max-contextabove 262K.Limits
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.