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

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2590
Author: @LuckyKo
Created: 10/15/2026
Status: ❌ Closed

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


📝 Commits (1)

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

📊 Changes

7 files changed (+520 additions, -62 deletions)

View changed files

📝 include/strata/core/conversation_file.hpp (+21 -0)
📝 include/strata/core/conversation_snapshot.hpp (+10 -0)
📝 src/core/conversation_file.cpp (+112 -20)
📝 src/core/conversation_file_test.cpp (+166 -3)
📝 src/core/conversation_snapshot_test.cpp (+19 -0)
📝 src/core/conversation_state.cpp (+48 -18)
📝 src/program/generate.cpp (+144 -21)

📄 Description

Problem

When running Strata with --layer-split auto across multiple GPUs, the engine divides model layers into stages (one per GPU). The existing session save/restore (--slot-save-path) only handled a single-stage (single-GPU) layout: it saved/restored one set of running state and K/V. On a multi-GPU 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).

Solution

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.
  • Backward compatible: v1 files read unchanged. A v3 file opened by old code is refused at the version check.

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 (wrong stage count, wrong layer range, oversized K/V) is refused before any allocation — not after a partial read.

Changes by file

File What
include/strata/core/conversation_file.hpp kVersionStages = 3, SessionReadLimits::max_stages, stage_limits, SessionStageLimits struct
include/strata/core/conversation_snapshot.hpp conversation_stage_read_limits() declaration
src/core/conversation_file.cpp v3 write (put_payload), v3 read (get_payload), per-stage validation, explicit v2 rejection
src/core/conversation_state.cpp conversation_stage_read_limits() implementation, conversation_session_read_limits updated to carry stage bounds
src/program/generate.cpp Serve loop: build stage_limits from live stages, set max_stages, pass through to read; save path collects per-stage K/V sources; cs.rest guard; draft_stage_kv helper
src/core/conversation_file_test.cpp Round-trip tests for v1 (no stages) and v3 (multi-stage), v2 rejection, v4 rejection, version-mismatch refusal, oversized-stage refusal
src/core/conversation_snapshot_test.cpp conversation_stage_read_limits unit tests

Environment

Strata built from source, CUDA 13.4, Windows 11 / Debian 13
2× NVIDIA RTX 5060 Ti (16 GB) or 2× NVIDIA A2 (16 GB), 64 GB system RAM
Qwen3.8-Flash-Next Coder IQ3_XXS / UD-Q4_K_XL, up to 128K context

Validation

Revision: 94f55cd6 (rebased onto main e88ee39d, 0.2.0-beta)
Environment: CUDA 13.4, Windows 11, 2× NVIDIA RTX 5060 Ti 16 GB (sm_120), 64 GB RAM

Commands:

build-win-cuda13.bat
build-win-cuda13\conversation_file_test.exe
build-win-cuda13\conversation_snapshot_test.exe
build-win-cuda13\conversation_cache_test.exe
build-win-cuda13\conversation_memory_test.exe
build-win-cuda13\conversation_split_failure_test.exe
build-win-cuda13\session_save_reclaim_test.exe

Passed:

  • conversation_file_test: 208 checks
  • conversation_snapshot_test: 4027 checks
  • conversation_cache_test: 4219 checks
  • conversation_memory_test: 25 checks
  • conversation_split_failure_test: 36 allocation-failure cases (stages 1–3)
  • session_save_reclaim_test: 119 checks
  • Smoke test: engine starts on dual-GPU layer-split, chat completion responds, session save/restore round-trip works

Failed: none

Not run:

  • --batch / parallel slots
  • Restore with a different GPU split than the save
  • Full-disk / near-full-VRAM restore (#2409)
  • Linux (previously validated on 2× A2 sm_86 by @Eranicus30666, 23K and 94K tokens)

🔄 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/2590 **Author:** [@LuckyKo](https://github.com/LuckyKo) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feature/multigpu-session-save` --- ### 📝 Commits (1) - [`5e1ec82`](https://github.com/Niko1221/Strata/commit/5e1ec82e1ad61bf8d336a7986ab92a1fe5b6753d) session: support multi-GPU layer-split save/restore (format v3) ### 📊 Changes **7 files changed** (+520 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/conversation_file.hpp` (+21 -0) 📝 `include/strata/core/conversation_snapshot.hpp` (+10 -0) 📝 `src/core/conversation_file.cpp` (+112 -20) 📝 `src/core/conversation_file_test.cpp` (+166 -3) 📝 `src/core/conversation_snapshot_test.cpp` (+19 -0) 📝 `src/core/conversation_state.cpp` (+48 -18) 📝 `src/program/generate.cpp` (+144 -21) </details> ### 📄 Description ## Problem When running Strata with `--layer-split auto` across multiple GPUs, the engine divides model layers into stages (one per GPU). The existing session save/restore (`--slot-save-path`) only handled a single-stage (single-GPU) layout: it saved/restored one set of running state and K/V. On a multi-GPU 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). ## Solution 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. - **Backward compatible:** v1 files read unchanged. A v3 file opened by old code is refused at the version check. ## 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 (wrong stage count, wrong layer range, oversized K/V) is refused before any allocation — not after a partial read. ## Changes by file | File | What | |------|------| | `include/strata/core/conversation_file.hpp` | `kVersionStages = 3`, `SessionReadLimits::max_stages`, `stage_limits`, `SessionStageLimits` struct | | `include/strata/core/conversation_snapshot.hpp` | `conversation_stage_read_limits()` declaration | | `src/core/conversation_file.cpp` | v3 write (`put_payload`), v3 read (`get_payload`), per-stage validation, explicit v2 rejection | | `src/core/conversation_state.cpp` | `conversation_stage_read_limits()` implementation, `conversation_session_read_limits` updated to carry stage bounds | | `src/program/generate.cpp` | Serve loop: build `stage_limits` from live stages, set `max_stages`, pass through to read; save path collects per-stage K/V sources; `cs.rest` guard; `draft_stage_kv` helper | | `src/core/conversation_file_test.cpp` | Round-trip tests for v1 (no stages) and v3 (multi-stage), v2 rejection, v4 rejection, version-mismatch refusal, oversized-stage refusal | | `src/core/conversation_snapshot_test.cpp` | `conversation_stage_read_limits` unit tests | ## Environment Strata built from source, CUDA 13.4, Windows 11 / Debian 13 2× NVIDIA RTX 5060 Ti (16 GB) or 2× NVIDIA A2 (16 GB), 64 GB system RAM Qwen3.8-Flash-Next Coder IQ3_XXS / UD-Q4_K_XL, up to 128K context ## Validation **Revision:** `94f55cd6` (rebased onto main `e88ee39d`, 0.2.0-beta) **Environment:** CUDA 13.4, Windows 11, 2× NVIDIA RTX 5060 Ti 16 GB (sm_120), 64 GB RAM **Commands:** ``` build-win-cuda13.bat build-win-cuda13\conversation_file_test.exe build-win-cuda13\conversation_snapshot_test.exe build-win-cuda13\conversation_cache_test.exe build-win-cuda13\conversation_memory_test.exe build-win-cuda13\conversation_split_failure_test.exe build-win-cuda13\session_save_reclaim_test.exe ``` **Passed:** - conversation_file_test: 208 checks - conversation_snapshot_test: 4027 checks - conversation_cache_test: 4219 checks - conversation_memory_test: 25 checks - conversation_split_failure_test: 36 allocation-failure cases (stages 1–3) - session_save_reclaim_test: 119 checks - Smoke test: engine starts on dual-GPU layer-split, chat completion responds, session save/restore round-trip works **Failed:** none **Not run:** - `--batch` / parallel slots - Restore with a different GPU split than the save - Full-disk / near-full-VRAM restore (#2409) - Linux (previously validated on 2× A2 sm_86 by @Eranicus30666, 23K and 94K tokens) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:33:37 +07:00
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#4150
No description provided.