[PR #3286] [Engine] session: support multi-GPU layer-split save/restore (format v3) #4546

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3286
Author: @LuckyKo
Created: 10/19/2026
Status: 🔄 Open

Base: main ← Head: feature/multigpu-session-save


📝 Commits (1)

  • 170e1a3 session: support multi-GPU layer-split save/restore (format v3)

📊 Changes

9 files changed (+566 additions, -76 deletions)

View changed files

📝 docs/DETAILS.md (+10 -3)
📝 include/strata/core/conversation_cache.hpp (+1 -1)
📝 include/strata/core/conversation_file.hpp (+24 -3)
📝 include/strata/core/conversation_snapshot.hpp (+10 -0)
📝 src/core/conversation_file.cpp (+124 -25)
📝 src/core/conversation_file_test.cpp (+185 -3)
📝 src/core/conversation_snapshot_test.cpp (+19 -0)
📝 src/core/conversation_state.cpp (+48 -18)
📝 src/program/generate.cpp (+145 -23)

📄 Description

Problem and result

When running Strata with --layer-split auto across multiple GPUs, POST /slots/0?action=save answers 400: "session files do not support --layer-split". The save was either refused or produced an incomplete file that couldn't be restored. This made --slot-save-path unusable for the most common multi-GPU configuration, which is exactly where long-context session persistence matters most (the RAM cost of re-reading a 30K+ token prompt).

After this PR: save and restore work on multi-GPU layer splits. A 94K-token session saves in ~5.5 s and restores in ~3.7 s after an engine restart (vs. 147 s to re-read the prompt from scratch).

none

Approach

Introduce format v3 for session files that carries per-stage data. Version 2 is reserved for PR #2247's BF16 state codec; this build rejects it explicitly at the version gate.

  • Write: put_payload serializes stage 0 (as before), then — only when stage_images is non-empty — a count followed by one block per later stage. Each block holds that stage's running state, K/V parts, and checkpoint. The file header version is set to kVersionStages = 3.
  • Read: get_payload reads stage 0 identically to v1, then checks the version. For v3 files it reads the stage count (bounded by limits.max_stages) and each subsequent stage block, validating geometry and layer range per stage. A v1 file has no stage section; a v2 file is refused at the version gate (not silently misparsed as v1).
  • Save guard: if conversation_checkpoints_split routes any checkpoint to cs.rest (incomplete for the split), the save is refused rather than silently dropping it.
  • Read-limit hardening: SessionReadLimits gains max_stages and a per-stage stage_limits vector. The serve loop populates these from the live engine's stage carves before calling session_file_read, so a file from a different split is refused before any allocation.
  • Backward compatible: v1 files read unchanged. A v3 file opened by old code is refused at the version check.

Supersedes #2590 (closed by mass-cleanup, same branch).

Validation

Passed:

  • build-win-cuda13\conversation_file_test.exe — 209 checks (rev f22b66ef, CUDA 13.4, Windows 11, 2× RTX 5060 Ti sm_120)
  • build-win-cuda13\conversation_snapshot_test.exe — 4321 checks
  • build-win-cuda13\conversation_cache_test.exe — 4842 checks
  • build-win-cuda13\conversation_memory_test.exe — 33 checks
  • build-win-cuda13\conversation_split_failure_test.exe — 36 allocation-failure cases (stages 1–3)
  • build-win-cuda13\session_save_reclaim_test.exe — 119 checks
  • End-to-end A→save→evict→restore→A+ cycle on the freshly built binary (strata_aba_test.py, dual-GPU q2_0 + 27B dflash2 sibling): A 36-msg prefill → save → sibling evict → restore → A+ hit 99.1% cache (34979/35293 prompt tokens, 2.8 s)
  • Smoke test: engine starts on dual-GPU layer-split, chat completion responds, session save/restore round-trip works
  • Independent test on Linux (2× NVIDIA A2, sm_86, Debian 13): 23K and 94K token sessions, save/restore verified, invalid files properly refused (by @Eranicus30666, rev 75e7df6b)

Failed:

  • none observed

Not run:

  • --batch / parallel slots (no multi-slot test harness)
  • Restore with a different GPU split than the save (unit tests cover the refusal path)
  • Full-disk / near-full-VRAM restore (see #2409)
  • HIP, SYCL, Metal builds (CUDA-only development environment)

Limits

  • Does not support --batch (parallel slots) — the stage layout is per-slot and the save format assumes a single active slot.
  • A v3 file is not readable by pre-0.2.0 engines (refused at the version check, no data loss).
  • The one-clause reply difference observed at 94K tokens by @Eranicus30666 is decode non-determinism (floating-point accumulation order between a fresh prompt pass and an incrementally-built restored state), not a serialization bug.

🔄 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/3286 **Author:** [@LuckyKo](https://github.com/LuckyKo) **Created:** 10/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/multigpu-session-save` --- ### 📝 Commits (1) - [`170e1a3`](https://github.com/Niko1221/Strata/commit/170e1a3b0fda2f66fd22ad9cf084c81ce37db665) session: support multi-GPU layer-split save/restore (format v3) ### 📊 Changes **9 files changed** (+566 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+10 -3) 📝 `include/strata/core/conversation_cache.hpp` (+1 -1) 📝 `include/strata/core/conversation_file.hpp` (+24 -3) 📝 `include/strata/core/conversation_snapshot.hpp` (+10 -0) 📝 `src/core/conversation_file.cpp` (+124 -25) 📝 `src/core/conversation_file_test.cpp` (+185 -3) 📝 `src/core/conversation_snapshot_test.cpp` (+19 -0) 📝 `src/core/conversation_state.cpp` (+48 -18) 📝 `src/program/generate.cpp` (+145 -23) </details> ### 📄 Description ## Problem and result When running Strata with `--layer-split auto` across multiple GPUs, `POST /slots/0?action=save` answers 400: "session files do not support --layer-split". The save was either refused or produced an incomplete file that couldn't be restored. This made `--slot-save-path` unusable for the most common multi-GPU configuration, which is exactly where long-context session persistence matters most (the RAM cost of re-reading a 30K+ token prompt). After this PR: save and restore work on multi-GPU layer splits. A 94K-token session saves in ~5.5 s and restores in ~3.7 s after an engine restart (vs. 147 s to re-read the prompt from scratch). ## Related discussion none ## Approach Introduce **format v3** for session files that carries per-stage data. Version 2 is reserved for PR #2247's BF16 state codec; this build rejects it explicitly at the version gate. - **Write:** `put_payload` serializes stage 0 (as before), then — only when `stage_images` is non-empty — a count followed by one block per later stage. Each block holds that stage's running state, K/V parts, and checkpoint. The file header version is set to `kVersionStages = 3`. - **Read:** `get_payload` reads stage 0 identically to v1, then checks the version. For v3 files it reads the stage count (bounded by `limits.max_stages`) and each subsequent stage block, validating geometry and layer range per stage. A v1 file has no stage section; a v2 file is refused at the version gate (not silently misparsed as v1). - **Save guard:** if `conversation_checkpoints_split` routes any checkpoint to `cs.rest` (incomplete for the split), the save is refused rather than silently dropping it. - **Read-limit hardening:** `SessionReadLimits` gains `max_stages` and a per-stage `stage_limits` vector. The serve loop populates these from the live engine's stage carves before calling `session_file_read`, so a file from a different split is refused before any allocation. - **Backward compatible:** v1 files read unchanged. A v3 file opened by old code is refused at the version check. Supersedes #2590 (closed by mass-cleanup, same branch). ## Validation **Passed:** - `build-win-cuda13\conversation_file_test.exe` — 209 checks (rev `f22b66ef`, CUDA 13.4, Windows 11, 2× RTX 5060 Ti sm_120) - `build-win-cuda13\conversation_snapshot_test.exe` — 4321 checks - `build-win-cuda13\conversation_cache_test.exe` — 4842 checks - `build-win-cuda13\conversation_memory_test.exe` — 33 checks - `build-win-cuda13\conversation_split_failure_test.exe` — 36 allocation-failure cases (stages 1–3) - `build-win-cuda13\session_save_reclaim_test.exe` — 119 checks - End-to-end A→save→evict→restore→A+ cycle on the freshly built binary (`strata_aba_test.py`, dual-GPU q2_0 + 27B dflash2 sibling): A 36-msg prefill → save → sibling evict → restore → A+ hit 99.1% cache (34979/35293 prompt tokens, 2.8 s) - Smoke test: engine starts on dual-GPU layer-split, chat completion responds, session save/restore round-trip works - Independent test on Linux (2× NVIDIA A2, sm_86, Debian 13): 23K and 94K token sessions, save/restore verified, invalid files properly refused (by @Eranicus30666, rev `75e7df6b`) **Failed:** - none observed **Not run:** - `--batch` / parallel slots (no multi-slot test harness) - Restore with a different GPU split than the save (unit tests cover the refusal path) - Full-disk / near-full-VRAM restore (see #2409) - HIP, SYCL, Metal builds (CUDA-only development environment) ## Limits - Does not support `--batch` (parallel slots) — the stage layout is per-slot and the save format assumes a single active slot. - A v3 file is not readable by pre-0.2.0 engines (refused at the version check, no data loss). - The one-clause reply difference observed at 94K tokens by @Eranicus30666 is decode non-determinism (floating-point accumulation order between a fresh prompt pass and an incrementally-built restored state), not a serialization bug. --- <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#4546
No description provided.