[PR #3541] [Engine] Session files on the Mac: the drafter's GGUF in the fingerprint, and no draft layer without a drafter #4677

Open
opened 2026-11-07 15:38:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3541
Author: @oceanio
Created: 10/21/2026
Status: 🔄 Open

Base: main ← Head: pr/metal-window-snapshots-solo


📝 Commits (3)

  • 3d226dc metal: a session file's model fingerprint reads the MTP GGUF the window loads
  • f21ee3a session files: an engine without a drafter saves and restores them without a draft layer
  • 6a5e562 tools: session_restart_test.py and metal_snapshot_test.py; parking_test.py reads the engine's own log

📊 Changes

8 files changed (+272 additions, -12 deletions)

View changed files

📝 include/strata/core/conversation_snapshot.hpp (+9 -0)
📝 metal/src/engine/window.cpp (+2 -0)
📝 src/core/conversation_snapshot_test.cpp (+12 -0)
📝 src/core/conversation_state.cpp (+18 -6)
📝 src/program/generate.cpp (+18 -5)
➕ tools/metal_snapshot_test.py (+112 -0)
📝 tools/parking_test.py (+1 -1)
➕ tools/session_restart_test.py (+100 -0)

📄 Description

Problem and result

On the Mac (Metal) engine of 0.2.10, parking works, but a session file cannot be saved, with or without MTP:

  1. With --mtp, SAVE and RESTORE answer SERR io 0 session fingerprint: mtp <rt>/dense.bin: No such file or directory. The model fingerprint samples the drafter's CUDA pack files (<rt>/dense.bin, dense.txt, experts.bin). A Mac install's rt directory holds only draft_vocab.bin, because the window loads the drafter from the MTP GGUF beside it (window.cpp mtp_load: <rt>/../mtp-q2_0.gguf, or STRATA_METAL_MTP_GGUF). The same refusal was there on 0.2.6 through 0.2.9.
  2. Without a drafter, SAVE answers SERR io 0 conversation snapshot: invalid K/V extent. The file's K/V sources always end with the drafter's layer, and with no drafter its state is empty (Mtp::st_ = QsaState{}, max_cells 0), so the extent check refuses any conversation. Parking does not hit this, because its context passes no draft state when there is no drafter.

With this PR a session file is saved and restored in a new engine process, with or without MTP. Measured on an M5 Max with Qwen3.8-Flash-Next IQ3_S: a 28,785-token conversation is a 676 MB file, saved in 0.12 s and restored in 0.12 s. Its follow-up decodes the same 95 tokens as the conversation that never left.

  • This PR used to carry the whole of parking and session files on the Mac (#2502). 0.2.10 parks on the Mac by itself: the window binds the session's QSA states to its own K/V. It also has its own macOS RAM reading and keeps the PLE residency policy off on the Mac (#4421). So the branch is now reduced to the two fixes above and the test tools; the earlier description is in this PR's edit history.
  • #3536 (the session's QSA states without K/V pools on Metal): session files work on it with these two commits on top (Validation).

Approach

  • metal/src/engine/window.cpp: mtp_gguf_path() returns the GGUF path that mtp_load keeps.
  • src/program/generate.cpp, the session identity: under STRATA_GPU_METAL, the drafter's model input is that GGUF, and the pack's dense.txt and experts.bin are not asked for. draft_vocab.bin stays (optional, as before). Other backends are unchanged.
  • src/core/conversation_state.cpp and conversation_snapshot.hpp: conversation_snapshot_sources and conversation_session_read_limits take draft == nullptr, which means no draft layer (the read limits allow one layer fewer). The reference forms keep their meaning. This matches what the header already describes for snapshots ("an image is validated and restored with the same kind of call it was saved with").
  • src/program/generate.cpp, SAVE and RESTORE: they pass use_mtp ? &mtp.kv_state() : nullptr, as the park context does. The SAVE RAM preflight counts the draft layer only when there is one.
  • This second fix is in shared code, so it also changes CUDA: an engine without --mtp can now save a session file instead of being refused. An engine with a drafter writes and reads exactly what it did before.
  • A file saved without a drafter is refused by an engine with one: first by the config fingerprint (mtp_window is -1 without --mtp), then by the K/V layer count. The reverse is refused the same way.
  • conversation_snapshot_test.cpp: the no-drafter sources, the file round trip and the validation, with and without a draft state.
  • Tools: tools/metal_snapshot_test.py and tools/session_restart_test.py are new. tools/parking_test.py reads the engine's own log under tempfile.gettempdir(); on macOS /tmp is not the temp folder, so it read a stale file there.

Validation

Environment: Apple M5 Max (128 GB), macOS 26.7.1. Revision: this branch, 6a5e562a = 0.2.10 (ffa80d73) + 3 commits, engine 0.1.56-metal. Model: Qwen3.8-Flash-Next GSQ-RCO IQ3_S (SC117's abliterated build), resident, --expert-cache 64 --prefill auto --mmap-experts. "MTP" is --spec 2 --mtp <rt>; "no MTP" is the same config without --spec and --mtp. The tools drive the engine directly (--serve protocol), greedy.

Passed:

  • Metal build: 0 errors, the same warnings as 0.2.10. The first commit also builds alone.

  • metal_snapshot_test.py (8K context), with MTP and without: the cache parks; SAVE writes a file; RESTORE of a non-session file answers SERR invalid and the engine stays in step; RESTORE of the saved file restores it. 0.2.10 fails 4 of these checks with MTP and 3 without, for the two reasons above.

  • session_restart_test.py (64K context). One engine saves the conversation, and a new engine process restores it and decodes the follow-up:

    conversation file save restore follow-up
    3,785 tokens, MTP 294 MB 62 ms 45 ms identical (99/99), reuses 3,785
    3,784 tokens, no MTP 290 MB 66 ms 39 ms identical (99/99), reuses 3,784
    28,785 tokens, MTP 676 MB 123 ms 120 ms identical (95/95), reuses 28,785
    28,784 tokens, no MTP 645 MB 109 ms 96 ms identical (95/95), reuses 28,784
  • parking_test.py at 28,692 tokens, with MTP and without: the follow-up after A, B, A is identical to the one that never parked (95/95), as on 0.2.10.

  • The same checks on #3536 + these two commits: all pass, with the same file sizes.

Failed:
None observed.

Not run:

  • conversation_snapshot_test with the new checks: it is a CUDA test (STRATA_BUILD_CONVERSATION_TESTS). It compiles against the Metal runtime, but stops at an entry point the Metal build does not have (kv_stream_reset).
  • CUDA, HIP and SYCL builds and runs: no such toolchains here. The no-drafter change is in code that every backend compiles. My evidence for CUDA is reading the code: the same QsaState{} reaches the same extent check there.
  • A file restored across engines with and without a drafter (refused by the fingerprint, as above). Batch slots (--batch): session files are refused there, unchanged.

Limits

  • Session files still refuse --batch, --layer-split and --peer-device, as before.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3541 **Author:** [@oceanio](https://github.com/oceanio) **Created:** 10/21/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/metal-window-snapshots-solo` --- ### 📝 Commits (3) - [`3d226dc`](https://github.com/Niko1221/Strata/commit/3d226dcc5eec904d90eb92193697c233a3aa432f) metal: a session file's model fingerprint reads the MTP GGUF the window loads - [`f21ee3a`](https://github.com/Niko1221/Strata/commit/f21ee3a4b1db5184335efd49b2d3600213d16df3) session files: an engine without a drafter saves and restores them without a draft layer - [`6a5e562`](https://github.com/Niko1221/Strata/commit/6a5e562a021df087895579229fdc8433362c51d6) tools: session_restart_test.py and metal_snapshot_test.py; parking_test.py reads the engine's own log ### 📊 Changes **8 files changed** (+272 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/conversation_snapshot.hpp` (+9 -0) 📝 `metal/src/engine/window.cpp` (+2 -0) 📝 `src/core/conversation_snapshot_test.cpp` (+12 -0) 📝 `src/core/conversation_state.cpp` (+18 -6) 📝 `src/program/generate.cpp` (+18 -5) ➕ `tools/metal_snapshot_test.py` (+112 -0) 📝 `tools/parking_test.py` (+1 -1) ➕ `tools/session_restart_test.py` (+100 -0) </details> ### 📄 Description ## Problem and result On the Mac (Metal) engine of 0.2.10, parking works, but a session file cannot be saved, with or without MTP: 1. With `--mtp`, SAVE and RESTORE answer `SERR io 0 session fingerprint: mtp <rt>/dense.bin: No such file or directory`. The model fingerprint samples the drafter's CUDA pack files (`<rt>/dense.bin`, `dense.txt`, `experts.bin`). A Mac install's rt directory holds only `draft_vocab.bin`, because the window loads the drafter from the MTP GGUF beside it (`window.cpp` `mtp_load`: `<rt>/../mtp-q2_0.gguf`, or `STRATA_METAL_MTP_GGUF`). The same refusal was there on 0.2.6 through 0.2.9. 2. Without a drafter, SAVE answers `SERR io 0 conversation snapshot: invalid K/V extent`. The file's K/V sources always end with the drafter's layer, and with no drafter its state is empty (`Mtp::st_ = QsaState{}`, `max_cells` 0), so the extent check refuses any conversation. Parking does not hit this, because its context passes no draft state when there is no drafter. With this PR a session file is saved and restored in a new engine process, with or without MTP. Measured on an M5 Max with Qwen3.8-Flash-Next IQ3_S: a 28,785-token conversation is a 676 MB file, saved in 0.12 s and restored in 0.12 s. Its follow-up decodes the same 95 tokens as the conversation that never left. ## Related discussion - This PR used to carry the whole of parking and session files on the Mac (#2502). 0.2.10 parks on the Mac by itself: the window binds the session's QSA states to its own K/V. It also has its own macOS RAM reading and keeps the PLE residency policy off on the Mac (#4421). So the branch is now reduced to the two fixes above and the test tools; the earlier description is in this PR's edit history. - #3536 (the session's QSA states without K/V pools on Metal): session files work on it with these two commits on top (Validation). ## Approach - `metal/src/engine/window.cpp`: `mtp_gguf_path()` returns the GGUF path that `mtp_load` keeps. - `src/program/generate.cpp`, the session identity: under `STRATA_GPU_METAL`, the drafter's model input is that GGUF, and the pack's `dense.txt` and `experts.bin` are not asked for. `draft_vocab.bin` stays (optional, as before). Other backends are unchanged. - `src/core/conversation_state.cpp` and `conversation_snapshot.hpp`: `conversation_snapshot_sources` and `conversation_session_read_limits` take `draft == nullptr`, which means no draft layer (the read limits allow one layer fewer). The reference forms keep their meaning. This matches what the header already describes for snapshots ("an image is validated and restored with the same kind of call it was saved with"). - `src/program/generate.cpp`, SAVE and RESTORE: they pass `use_mtp ? &mtp.kv_state() : nullptr`, as the park context does. The SAVE RAM preflight counts the draft layer only when there is one. - This second fix is in shared code, so it also changes CUDA: an engine without `--mtp` can now save a session file instead of being refused. An engine with a drafter writes and reads exactly what it did before. - A file saved without a drafter is refused by an engine with one: first by the config fingerprint (`mtp_window` is -1 without `--mtp`), then by the K/V layer count. The reverse is refused the same way. - `conversation_snapshot_test.cpp`: the no-drafter sources, the file round trip and the validation, with and without a draft state. - Tools: `tools/metal_snapshot_test.py` and `tools/session_restart_test.py` are new. `tools/parking_test.py` reads the engine's own log under `tempfile.gettempdir()`; on macOS `/tmp` is not the temp folder, so it read a stale file there. ## Validation Environment: Apple M5 Max (128 GB), macOS 26.7.1. Revision: this branch, `6a5e562a` = 0.2.10 (`ffa80d73`) + 3 commits, engine 0.1.56-metal. Model: Qwen3.8-Flash-Next GSQ-RCO IQ3_S (SC117's abliterated build), resident, `--expert-cache 64 --prefill auto --mmap-experts`. "MTP" is `--spec 2 --mtp <rt>`; "no MTP" is the same config without `--spec` and `--mtp`. The tools drive the engine directly (`--serve` protocol), greedy. **Passed:** - Metal build: 0 errors, the same warnings as 0.2.10. The first commit also builds alone. - `metal_snapshot_test.py` (8K context), with MTP and without: the cache parks; SAVE writes a file; RESTORE of a non-session file answers `SERR invalid` and the engine stays in step; RESTORE of the saved file restores it. 0.2.10 fails 4 of these checks with MTP and 3 without, for the two reasons above. - `session_restart_test.py` (64K context). One engine saves the conversation, and a new engine process restores it and decodes the follow-up: | conversation | file | save | restore | follow-up | |---|---:|---:|---:|---| | 3,785 tokens, MTP | 294 MB | 62 ms | 45 ms | identical (99/99), reuses 3,785 | | 3,784 tokens, no MTP | 290 MB | 66 ms | 39 ms | identical (99/99), reuses 3,784 | | 28,785 tokens, MTP | 676 MB | 123 ms | 120 ms | identical (95/95), reuses 28,785 | | 28,784 tokens, no MTP | 645 MB | 109 ms | 96 ms | identical (95/95), reuses 28,784 | - `parking_test.py` at 28,692 tokens, with MTP and without: the follow-up after A, B, A is identical to the one that never parked (95/95), as on 0.2.10. - The same checks on #3536 + these two commits: all pass, with the same file sizes. **Failed:** None observed. **Not run:** - `conversation_snapshot_test` with the new checks: it is a CUDA test (`STRATA_BUILD_CONVERSATION_TESTS`). It compiles against the Metal runtime, but stops at an entry point the Metal build does not have (`kv_stream_reset`). - CUDA, HIP and SYCL builds and runs: no such toolchains here. The no-drafter change is in code that every backend compiles. My evidence for CUDA is reading the code: the same `QsaState{}` reaches the same extent check there. - A file restored across engines with and without a drafter (refused by the fingerprint, as above). Batch slots (`--batch`): session files are refused there, unchanged. ## Limits - Session files still refuse `--batch`, `--layer-split` and `--peer-device`, as before. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4677
No description provided.