[PR #2247] [CLOSED] --session-state-codec bf16: a saved/parked conversation's running state at half the bytes #3947

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2247
Author: @sumomomomomo
Created: 10/13/2026
Status: ❌ Closed

Base: main ← Head: feat/state-snapshot-bf16


📝 Commits (10+)

  • fe88a54 docs: the plan for a bf16 saved-state codec (parked images and session files)
  • a6def98 --session-state-codec bf16: a saved conversation's running state at half the bytes (the file says which codec it used; the live state stays fp32)
  • 725714a --session-state-codec: the four things a review of a6def98 found
  • d178753 sycl: the migrated SAVE caller for the preflight's new signature
  • aad5df6 state codec: a stored array converts to another codec in one pass
  • 2274c1c docs: the parked-image, 4K and 128K, cold-read and RAM numbers the PR asked for, and the one-pass conversion
  • 09c126f lazy restoration: a resumed conversation keeps its parked snapshots in the codec they were parked in (resuming no longer widens the whole retained chain; only the one checkpoint a rewind selects is decoded into the session's fp32 buffers, and its stored bytes stay as they are)
  • fc0003e conversation report: a restore failure that cannot allocate its own message does not throw
  • c3e25b1 docs: what the code actually does on a park, a SAVE and a restore, and what is still unmeasured
  • 387b9c3 docs: the fp32 comparison is stated as what it is, and a continuation pays the decode too

📊 Changes

23 files changed (+2946 additions, -88 deletions)

View changed files

📝 CMakeLists.txt (+25 -3)
📝 docs/DETAILS.md (+40 -1)
➕ docs/STATE_SNAPSHOT_BF16.md (+316 -0)
📝 include/strata/core/conversation_cache.hpp (+13 -0)
📝 include/strata/core/conversation_file.hpp (+9 -4)
➕ include/strata/core/conversation_report.hpp (+27 -0)
📝 include/strata/core/conversation_snapshot.hpp (+31 -0)
📝 include/strata/core/session_save_reclaim.hpp (+4 -2)
➕ include/strata/core/state_codec.hpp (+62 -0)
📝 src/core/conversation_cache_test.cpp (+54 -0)
➕ src/core/conversation_capture_codec_test.cpp (+409 -0)
📝 src/core/conversation_copy.hpp (+62 -0)
📝 src/core/conversation_file.cpp (+68 -9)
📝 src/core/conversation_file_test.cpp (+74 -10)
➕ src/core/conversation_report_test.cpp (+241 -0)
📝 src/core/conversation_snapshot_test.cpp (+680 -0)
📝 src/core/conversation_state.cpp (+173 -22)
📝 src/core/session_save_reclaim_test.cpp (+38 -9)
➕ src/core/state_codec.cpp (+159 -0)
➕ src/core/state_codec_test.cpp (+247 -0)

...and 3 more files

📄 Description

Closes #2377

Overview

Adds opt-in --session-state-codec bf16 to reduce the RAM and disk needed for conversation checkpoints. For the tested model, checkpoint state is approximately 50% smaller and session files are 5.6–39.3% smaller, providing headroom for more cached conversations or denser resume points.

In the 32K workload, BF16 at 8K checkpoint spacing delivered comparable complete-turn latency to FP32 at the default 16K spacing. Parking was faster across the tested context sizes, while continuing resumes added approximately 2–6 ms.

The benchmark harness, raw results and engine logs are now public.

Architecture

  • Encode at capture: retained checkpoints use the configured codec immediately, including layer-split checkpoint parts.
  • Keep computation FP32: live GPU state and temporary working-state transfers remain FP32.
  • Restore lazily: only the selected checkpoint is decoded; other retained snapshots remain compressed.
  • Copy directly when parking: existing BF16 checkpoints are copied without widening and re-encoding.
  • Preserve per-checkpoint identity: each snapshot records its codec, supporting mixed chains and cross-codec reads.

The codec covers GDN recurrence/convolution history, PLE history, and QSA indexer tails/dead keys. Integer positions and K/V storage are unchanged. Encoding uses round-to-nearest-even and is lossy; widening is exact.

Validation

Benchmarks used Linux, CUDA 12.8, a Tesla V100 32 GB as the single model GPU, a 24-core/32-thread Intel CPU, 93 GB reported RAM, IQ3_S, INT8 K/V, and a Samsung 990 EVO Plus SSD.

Latency comparisons used the same strata.head binary, with runs recorded at e79abfc0: two rounds with reversed arm order, two warm-ups and ten measured repetitions per round. Figures below are medians of round medians. RSS measurements were re-run at 79955461.

Checkpoint spacing and turn latency

A fresh 31,813-token document followed by short turns:

Configuration Fresh prefill Turn prompt phase Complete turn
FP32 / 16K spacing 21.717 s 736.5 ms 1.074 s
BF16 / 16K spacing 21.703 s 687.5 ms 1.027 s
FP32 / 8K spacing 21.796 s 806.0 ms 1.135 s
BF16 / 8K spacing 21.868 s 721.0 ms 1.054 s

Complete-turn timings include parking, resumption and generation; they are not TTFT or isolated capture timings. This sweep measures latency; recall is assessed separately below.

Parked conversation performance

At 16K checkpoint spacing, FP32 → BF16:

Context Continuing resume Parking on rewind Complete rewind request
32K 49.25 → 51.48 ms 142.13 → 90.78 ms 0.329 → 0.283 s
63K 71.15 → 77.05 ms 163.98 → 104.90 ms 0.344 → 0.295 s
121K 121.98 → 127.53 ms 198.33 → 101.25 ms 0.432 → 0.333 s

In a separate 32K run with four parked images, cache-accounted allocation fell from 3.73 GB to 3.08 GB (17.4%). These figures include allocator capacity; they are not serialized payload sizes or a guarantee of proportionally more conversations per cache budget.

SAVE / RESTORE memory

Observed RSS growth, FP32 → BF16:

Context First SAVE after prefill Disk RESTORE
32K 353.2 → 180.5 MiB 350.3 → 406.5 MiB
63K 354.0 → 181.2 MiB 805.1 → 861.3 MiB

First SAVE was measured separately from later saves, which reuse allocations. RESTORE figures are medians of nine repetitions. BF16 RESTORE grew RSS by approximately 56.2 MiB more at both sizes.

RSS was sampled every 20 ms on fresh processes; these are observed increments, not guaranteed peak-memory bounds.

Functional and failure-path checks

  • Explicit rewind needle questions: 20/20 per tested cell for both codecs at 32K, 63K and approximately 121K, including freshly captured BF16 checkpoints.
  • Earlier disk/park recall: 9/9 at 32K; disk recall 3/3 at approximately 121K. Repeated park/resume/generate cycles: 12/12, both codecs.
  • Unit coverage includes rounding and special values, file versions, mixed chains, stage split/merge, validation, memory accounting and SAVE admission.
  • Allocation-failure and reporting coverage: 43 capture checks and 25 reporting checks, including sanitizer runs.
  • CUDA suite: 125/126 passing; ple_parity requires a missing artifact and also fails before this change.

Compatibility and limitations

  • Opt-in; FP32, checkpoint spacing and retention defaults remain unchanged. Default FP32 serialization was checked against the parent build.
  • All-FP32 files remain version 1; BF16 files use version 2. Codec-aware engines read either; older builds reject version 2.
  • HIP and SYCL remain unbuilt; Windows remains untested. The SYCL port does not implement the BF16 option.
  • Stage splitting has unit coverage; real multi-GPU park/restore remains untested.
  • Isolated capture latency, retained RAM before the first park, equivalent-history memory at 8K/16K, and memory-tight admission improvements remain unmeasured.
  • Logits/KL comparisons and broader long-continuation quality evaluation remain outstanding. Needle results establish behavior on the tested workloads.

Implementation and detailed results: docs/STATE_SNAPSHOT_BF16.md.

Public evidence: artifact manifest, harness and reproduction instructions, and raw results. The manifest identifies historical runs, superseded measurements and provenance gaps; earlier session-file timings are not presented as current-build performance.

AI Disclosure

Created with Qwen3.8-Flash-Next-exl3 3.05bpw.


🔄 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/2247 **Author:** [@sumomomomomo](https://github.com/sumomomomomo) **Created:** 10/13/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/state-snapshot-bf16` --- ### 📝 Commits (10+) - [`fe88a54`](https://github.com/Niko1221/Strata/commit/fe88a54d03e9914723f069e27089eb6aa9e35913) docs: the plan for a bf16 saved-state codec (parked images and session files) - [`a6def98`](https://github.com/Niko1221/Strata/commit/a6def98e9a1da6c7fe801371bf14ac71949ff712) --session-state-codec bf16: a saved conversation's running state at half the bytes (the file says which codec it used; the live state stays fp32) - [`725714a`](https://github.com/Niko1221/Strata/commit/725714a82f127c264eb8aab7c6cfb8da65bc3c21) --session-state-codec: the four things a review of a6def98 found - [`d178753`](https://github.com/Niko1221/Strata/commit/d178753d117579ae2824d7db7fcc983513196dfb) sycl: the migrated SAVE caller for the preflight's new signature - [`aad5df6`](https://github.com/Niko1221/Strata/commit/aad5df6f8e40ca9da35451b609425e0218f9579f) state codec: a stored array converts to another codec in one pass - [`2274c1c`](https://github.com/Niko1221/Strata/commit/2274c1c482249cf5ddb9249a230b961e730d3328) docs: the parked-image, 4K and 128K, cold-read and RAM numbers the PR asked for, and the one-pass conversion - [`09c126f`](https://github.com/Niko1221/Strata/commit/09c126f1e9beea64e422a86fdfca4f29acede93d) lazy restoration: a resumed conversation keeps its parked snapshots in the codec they were parked in (resuming no longer widens the whole retained chain; only the one checkpoint a rewind selects is decoded into the session's fp32 buffers, and its stored bytes stay as they are) - [`fc0003e`](https://github.com/Niko1221/Strata/commit/fc0003e21187bcf27c55a2cffcbb78e56399ac15) conversation report: a restore failure that cannot allocate its own message does not throw - [`c3e25b1`](https://github.com/Niko1221/Strata/commit/c3e25b1737f0f9030f2c3fcbd63c9f00c3f3b3b5) docs: what the code actually does on a park, a SAVE and a restore, and what is still unmeasured - [`387b9c3`](https://github.com/Niko1221/Strata/commit/387b9c3b1ad97f09c6c4dfbaafba782e3ac14ce8) docs: the fp32 comparison is stated as what it is, and a continuation pays the decode too ### 📊 Changes **23 files changed** (+2946 additions, -88 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+25 -3) 📝 `docs/DETAILS.md` (+40 -1) ➕ `docs/STATE_SNAPSHOT_BF16.md` (+316 -0) 📝 `include/strata/core/conversation_cache.hpp` (+13 -0) 📝 `include/strata/core/conversation_file.hpp` (+9 -4) ➕ `include/strata/core/conversation_report.hpp` (+27 -0) 📝 `include/strata/core/conversation_snapshot.hpp` (+31 -0) 📝 `include/strata/core/session_save_reclaim.hpp` (+4 -2) ➕ `include/strata/core/state_codec.hpp` (+62 -0) 📝 `src/core/conversation_cache_test.cpp` (+54 -0) ➕ `src/core/conversation_capture_codec_test.cpp` (+409 -0) 📝 `src/core/conversation_copy.hpp` (+62 -0) 📝 `src/core/conversation_file.cpp` (+68 -9) 📝 `src/core/conversation_file_test.cpp` (+74 -10) ➕ `src/core/conversation_report_test.cpp` (+241 -0) 📝 `src/core/conversation_snapshot_test.cpp` (+680 -0) 📝 `src/core/conversation_state.cpp` (+173 -22) 📝 `src/core/session_save_reclaim_test.cpp` (+38 -9) ➕ `src/core/state_codec.cpp` (+159 -0) ➕ `src/core/state_codec_test.cpp` (+247 -0) _...and 3 more files_ </details> ### 📄 Description Closes #2377 ## Overview Adds opt-in `--session-state-codec bf16` to reduce the RAM and disk needed for conversation checkpoints. For the tested model, checkpoint state is approximately **50% smaller** and session files are **5.6–39.3% smaller**, providing headroom for more cached conversations or denser resume points. In the 32K workload, **BF16 at 8K checkpoint spacing delivered comparable complete-turn latency to FP32 at the default 16K spacing**. Parking was faster across the tested context sizes, while continuing resumes added approximately **2–6 ms**. The [benchmark harness, raw results and engine logs](https://github.com/sumomomomomo/strata-bf16-bench-artifacts) are now public. ## Architecture - **Encode at capture:** retained checkpoints use the configured codec immediately, including layer-split checkpoint parts. - **Keep computation FP32:** live GPU state and temporary working-state transfers remain FP32. - **Restore lazily:** only the selected checkpoint is decoded; other retained snapshots remain compressed. - **Copy directly when parking:** existing BF16 checkpoints are copied without widening and re-encoding. - **Preserve per-checkpoint identity:** each snapshot records its codec, supporting mixed chains and cross-codec reads. The codec covers GDN recurrence/convolution history, PLE history, and QSA indexer tails/dead keys. Integer positions and K/V storage are unchanged. Encoding uses round-to-nearest-even and is lossy; widening is exact. ## Validation Benchmarks used Linux, CUDA 12.8, a Tesla V100 32 GB as the single model GPU, a 24-core/32-thread Intel CPU, 93 GB reported RAM, IQ3_S, INT8 K/V, and a Samsung 990 EVO Plus SSD. Latency comparisons used the same `strata.head` binary, with runs recorded at `e79abfc0`: two rounds with reversed arm order, two warm-ups and ten measured repetitions per round. Figures below are medians of round medians. RSS measurements were re-run at `79955461`. ### Checkpoint spacing and turn latency A fresh 31,813-token document followed by short turns: | Configuration | Fresh prefill | Turn prompt phase | Complete turn | | --- | ---: | ---: | ---: | | FP32 / 16K spacing | 21.717 s | 736.5 ms | 1.074 s | | BF16 / 16K spacing | 21.703 s | 687.5 ms | 1.027 s | | FP32 / 8K spacing | 21.796 s | 806.0 ms | 1.135 s | | BF16 / 8K spacing | 21.868 s | 721.0 ms | 1.054 s | Complete-turn timings include parking, resumption and generation; they are not TTFT or isolated capture timings. This sweep measures latency; recall is assessed separately below. ### Parked conversation performance At 16K checkpoint spacing, FP32 → BF16: | Context | Continuing resume | Parking on rewind | Complete rewind request | | --- | ---: | ---: | ---: | | 32K | 49.25 → 51.48 ms | 142.13 → 90.78 ms | 0.329 → 0.283 s | | 63K | 71.15 → 77.05 ms | 163.98 → 104.90 ms | 0.344 → 0.295 s | | 121K | 121.98 → 127.53 ms | 198.33 → 101.25 ms | 0.432 → 0.333 s | In a separate 32K run with four parked images, cache-accounted allocation fell from **3.73 GB to 3.08 GB (17.4%)**. These figures include allocator capacity; they are not serialized payload sizes or a guarantee of proportionally more conversations per cache budget. ### SAVE / RESTORE memory Observed RSS growth, FP32 → BF16: | Context | First SAVE after prefill | Disk RESTORE | | --- | ---: | ---: | | 32K | 353.2 → 180.5 MiB | 350.3 → 406.5 MiB | | 63K | 354.0 → 181.2 MiB | 805.1 → 861.3 MiB | First SAVE was measured separately from later saves, which reuse allocations. RESTORE figures are medians of nine repetitions. BF16 RESTORE grew RSS by approximately **56.2 MiB more** at both sizes. RSS was sampled every 20 ms on fresh processes; these are observed increments, not guaranteed peak-memory bounds. ### Functional and failure-path checks - Explicit rewind needle questions: **20/20 per tested cell for both codecs** at 32K, 63K and approximately 121K, including freshly captured BF16 checkpoints. - Earlier disk/park recall: **9/9 at 32K**; disk recall **3/3 at approximately 121K**. Repeated park/resume/generate cycles: **12/12**, both codecs. - Unit coverage includes rounding and special values, file versions, mixed chains, stage split/merge, validation, memory accounting and SAVE admission. - Allocation-failure and reporting coverage: **43 capture checks and 25 reporting checks**, including sanitizer runs. - CUDA suite: **125/126 passing**; `ple_parity` requires a missing artifact and also fails before this change. ## Compatibility and limitations - Opt-in; FP32, checkpoint spacing and retention defaults remain unchanged. Default FP32 serialization was checked against the parent build. - All-FP32 files remain version 1; BF16 files use version 2. Codec-aware engines read either; older builds reject version 2. - HIP and SYCL remain unbuilt; Windows remains untested. The SYCL port does not implement the BF16 option. - Stage splitting has unit coverage; real multi-GPU park/restore remains untested. - Isolated capture latency, retained RAM before the first park, equivalent-history memory at 8K/16K, and memory-tight admission improvements remain unmeasured. - Logits/KL comparisons and broader long-continuation quality evaluation remain outstanding. Needle results establish behavior on the tested workloads. Implementation and detailed results: `docs/STATE_SNAPSHOT_BF16.md`. Public evidence: [artifact manifest](https://github.com/sumomomomomo/strata-bf16-bench-artifacts/blob/main/MANIFEST.md), [harness and reproduction instructions](https://github.com/sumomomomomo/strata-bf16-bench-artifacts/tree/main/harness), and [raw results](https://github.com/sumomomomomo/strata-bf16-bench-artifacts/tree/main/results). The manifest identifies historical runs, superseded measurements and provenance gaps; earlier session-file timings are not presented as current-build performance. ## AI Disclosure Created with Qwen3.8-Flash-Next-exl3 3.05bpw. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:54 +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#3947
No description provided.