[PR #4086] [CLOSED] [Engine] add lossless REF and RHT+INT16 disk-state codecs #4898

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4086
Author: @G0-0000
Created: 10/25/2026
Status: ❌ Closed

Base: main ← Head: feat/conv-cache-state-ref-rht-20261025


📝 Commits (3)

  • 7c33492 [Engine] add disk conversation cache prerequisites
  • 8a4ca50 [Engine] add state references to prefix disk snapshots
  • 0d689a2 [Engine] add RHT+INT16 codec for GDN disk snapshots

📊 Changes

19 files changed (+8469 additions, -180 deletions)

View changed files

📝 CMakeLists.txt (+8 -1)
📝 docs/DETAILS.md (+169 -12)
📝 include/strata/core/conversation_cache.hpp (+142 -21)
📝 include/strata/core/conversation_file.hpp (+136 -6)
📝 include/strata/core/conversation_snapshot.hpp (+40 -0)
➕ include/strata/core/conversation_spill.hpp (+193 -0)
➕ include/strata/core/rht_state_codec.hpp (+339 -0)
📝 serve/server.py (+56 -2)
📝 serve/test_monitor.py (+44 -0)
📝 serve/web/app.js (+28 -1)
📝 serve/web/index.html (+4 -0)
📝 src/core/conversation_file.cpp (+1349 -67)
📝 src/core/conversation_file_test.cpp (+1648 -3)
📝 src/core/conversation_snapshot.cpp (+61 -0)
➕ src/core/conversation_spill.cpp (+1115 -0)
➕ src/core/conversation_spill_test.cpp (+1791 -0)
📝 src/core/conversation_state.cpp (+45 -6)
➕ src/core/rht_state_codec_test.cpp (+336 -0)
📝 src/program/generate.cpp (+965 -61)

📄 Description

Stacked draft: buildable today, prerequisites not yet merged

This is an opt-in stacked draft for testing and review, not a request to merge the prerequisite port as-is. The branch is based on main at 7dd5cf18e68c639a8773e096c5c79f971ea2a9f5 and includes the disk-cache prerequisites needed to build and use the codecs today.

The new work is in the last two commits:

  1. 8a4ca507 — lossless state references for prefix snapshots (--conversation-cache-disk-state-ref).
  2. 0d689a288 — RHT+INT16 encoding for recurrent GDN state in ordinary base/delta snapshots (--conversation-cache-disk-state-codec-rht).

The first commit, 7c334924, is a rebased port of unmerged prerequisite work. It is included so this branch is self-contained and buildable. It should be dropped or replaced by the canonical prerequisite commits when they land. Please review the last two commits as the codec proposal; the prerequisite port is context, not a competing proposal for those PRs.

Provenance

The prerequisite port is based on:

  • #1271 — --conversation-cache-spill-dir, Aníbal Muñoz Calero, head 4af468f6b.
  • #1269 — streaming restore, pspranger-throw, head d258f1892.
  • #1480 — --conversation-cache-disk-only, Jim Routh, head 3d5b97b84.
  • Delta records and sidecar LRU — Emanon (09d83375d, 1bac6f24c), on top of the #1480 branch.

The RHT+INT16 disk-boundary encoding approach is based on jundot/omlx, specifically omlx/cache/boundary_snapshot_store.py.

This is a rebased/rewritten port across a large upstream interval, not a clean cherry-pick. The original authors have not reviewed this port. Their original PRs remain the canonical review threads for the prerequisite designs. Based-on: attribution is recorded in the commit messages.

Behavior

Both new codec switches are off by default.

  • REF (lossless): inside a prefix .sess, a checkpoint whose five running-state arrays match the file's live state byte-for-byte can reference that live copy instead of storing a second copy. References are local to the same file, not links to another base file. This is exact deduplication, not quantization.
  • RHT+INT16 (lossy, disk only): ordinary base and delta records can encode recurrent GDN state with a deterministic normalized Hadamard transform and per-row INT16 quantization with FP32 scales. The runtime state remains FP32. Encoding is streamed to disk; restoration expands to FP32.
  • Convolution state stays RAW FP32.
  • Prefix snapshots keep the existing FP32/REF path and are not RHT-compressed.
  • New readers accept v1 and v2 records, and v1/v2 delta records can coexist in a chain. Older builds without codec 2 support cannot restore RHT files; rollback compatibility is limited.
  • Restore admission is based on logical restored FP32 sizes, not compressed file sizes.

Disk-space results

These results came from offline experiments and the original local implementation, before this cleanup/rebase, using Qwen3.8-Flash-Next UD-Q4_K_XL with int8 K/V. The original model runs used Linux and a Tesla V100-SXM2-32GB; the offline state comparison ran on CPU over real cache snapshots. They were not rerun as real-model tests on this cleaned branch. Measured files and format-derived sizes are identified separately.

Case Original / baseline Stored with codec Space saved Evidence and scope
REF prefix sample 278,223,720 B no-REF equivalent 160,160,728 B measured v2 file 118,062,992 B (112.59 MiB) The v2 file was measured; the no-REF equivalent is format arithmetic, not a second measured file. REF is lossless.
RHT recurrent state, five copies 566,231,040 B FP32 287,539,200 B INT16 + FP32 scales 278,691,840 B (265.78 MiB), 49.21875% Codec-size arithmetic over the accepted real-state samples, not a measured on-disk file; excludes metadata/alignment and convolution state.
One complete GDN state copy, including RAW convolution 117,669,888 B 61,931,520 B 55,738,368 B (53.16 MiB), 47.3684% Format/layout accounting checked against file metadata; this is not a whole-cache-file percentage.

On the original local build, the observed RHT base .sess was 218,849,020 B (208.71 MiB) and the observed delta .dlog was 125,250,924 B (119.45 MiB). The base+delta chain was also restored after a same-version restart. These file sizes are recorded measurements from that build, not new measurements of this rebased branch.

REF and RHT apply to different state/cache cases; their percentages must not be added into a single whole-cache saving claim.

State-fidelity evidence, not a generation-quality claim

On the same three real cache files (five independent recurrent-state copies, 141,557,760 FP32 values), the offline comparison measured relative L2 error of approximately 1.913e-5 for RHT+INT16 versus 2.056e-4 for FP16.

These are state-fidelity and storage measurements only. They are not a generation-quality A/B and do not establish that RHT+INT16 is lossless.

Validation on this branch

Passed on Linux with CUDA 12.9, sm_70, Release, host-only tests:

  • Full requested build, including strata, rht_state_codec_test, and the conversation test targets.
  • CTest: 7/7 passed:
    • rht_state_codec_test
    • conversation_file_test
    • conversation_spill_test
    • session_save_reclaim_test
    • conversation_cache_test
    • conversation_snapshot_test
    • conversation_validation_test
  • PYTHONPATH=. python3 serve/test_monitor.py: 12/12 passed.
  • strata --version: 0.1.49.2.

The prerequisite commit was also built and tested separately before REF was applied; the REF commit was built and tested separately before RHT was applied.

Not run / limits

  • HIP and SYCL builds were not run.
  • No real-model or GPU-execution test was run on this cleaned/rebased branch.
  • No generation-quality or performance benchmark was run on this branch.
  • Existing default/v1 and opt-in codec tests pass; a separate cross-build byte-for-byte comparison of default-off output was not run.
  • The prerequisite port is intentionally included for a self-contained draft and still needs to be reconciled with the canonical prerequisite PRs before this can become a small standalone merge PR.

Feedback on the final two codec commits and the preferred unstacking order is welcome.


🔄 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/4086 **Author:** [@G0-0000](https://github.com/G0-0000) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/conv-cache-state-ref-rht-20261025` --- ### 📝 Commits (3) - [`7c33492`](https://github.com/Niko1221/Strata/commit/7c3349243b9e6bccc3357ca36711ba11d5a8c7c0) [Engine] add disk conversation cache prerequisites - [`8a4ca50`](https://github.com/Niko1221/Strata/commit/8a4ca50733de9074389d6a8a719de029b9a40850) [Engine] add state references to prefix disk snapshots - [`0d689a2`](https://github.com/Niko1221/Strata/commit/0d689a2883f92d42caf9dd799f66a22e59b34129) [Engine] add RHT+INT16 codec for GDN disk snapshots ### 📊 Changes **19 files changed** (+8469 additions, -180 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+8 -1) 📝 `docs/DETAILS.md` (+169 -12) 📝 `include/strata/core/conversation_cache.hpp` (+142 -21) 📝 `include/strata/core/conversation_file.hpp` (+136 -6) 📝 `include/strata/core/conversation_snapshot.hpp` (+40 -0) ➕ `include/strata/core/conversation_spill.hpp` (+193 -0) ➕ `include/strata/core/rht_state_codec.hpp` (+339 -0) 📝 `serve/server.py` (+56 -2) 📝 `serve/test_monitor.py` (+44 -0) 📝 `serve/web/app.js` (+28 -1) 📝 `serve/web/index.html` (+4 -0) 📝 `src/core/conversation_file.cpp` (+1349 -67) 📝 `src/core/conversation_file_test.cpp` (+1648 -3) 📝 `src/core/conversation_snapshot.cpp` (+61 -0) ➕ `src/core/conversation_spill.cpp` (+1115 -0) ➕ `src/core/conversation_spill_test.cpp` (+1791 -0) 📝 `src/core/conversation_state.cpp` (+45 -6) ➕ `src/core/rht_state_codec_test.cpp` (+336 -0) 📝 `src/program/generate.cpp` (+965 -61) </details> ### 📄 Description ## Stacked draft: buildable today, prerequisites not yet merged This is an **opt-in stacked draft for testing and review**, not a request to merge the prerequisite port as-is. The branch is based on `main` at `7dd5cf18e68c639a8773e096c5c79f971ea2a9f5` and includes the disk-cache prerequisites needed to build and use the codecs today. **The new work is in the last two commits:** 1. `8a4ca507` — lossless state references for prefix snapshots (`--conversation-cache-disk-state-ref`). 2. `0d689a288` — RHT+INT16 encoding for recurrent GDN state in ordinary base/delta snapshots (`--conversation-cache-disk-state-codec-rht`). The first commit, `7c334924`, is a rebased port of unmerged prerequisite work. It is included so this branch is self-contained and buildable. It should be dropped or replaced by the canonical prerequisite commits when they land. Please review the last two commits as the codec proposal; the prerequisite port is context, not a competing proposal for those PRs. ### Provenance The prerequisite port is based on: - #1271 — `--conversation-cache-spill-dir`, Aníbal Muñoz Calero, head `4af468f6b`. - #1269 — streaming restore, pspranger-throw, head `d258f1892`. - #1480 — `--conversation-cache-disk-only`, Jim Routh, head `3d5b97b84`. - Delta records and sidecar LRU — Emanon (`09d83375d`, `1bac6f24c`), on top of the #1480 branch. The RHT+INT16 disk-boundary encoding approach is based on [jundot/omlx](https://github.com/jundot/omlx), specifically `omlx/cache/boundary_snapshot_store.py`. This is a rebased/rewritten port across a large upstream interval, not a clean cherry-pick. The original authors have not reviewed this port. Their original PRs remain the canonical review threads for the prerequisite designs. `Based-on:` attribution is recorded in the commit messages. ### Behavior Both new codec switches are **off by default**. - **REF (lossless):** inside a prefix `.sess`, a checkpoint whose five running-state arrays match the file's live state byte-for-byte can reference that live copy instead of storing a second copy. References are local to the same file, not links to another base file. This is exact deduplication, not quantization. - **RHT+INT16 (lossy, disk only):** ordinary base and delta records can encode recurrent GDN state with a deterministic normalized Hadamard transform and per-row INT16 quantization with FP32 scales. The runtime state remains FP32. Encoding is streamed to disk; restoration expands to FP32. - Convolution state stays RAW FP32. - Prefix snapshots keep the existing FP32/REF path and are not RHT-compressed. - New readers accept v1 and v2 records, and v1/v2 delta records can coexist in a chain. Older builds without codec 2 support cannot restore RHT files; rollback compatibility is limited. - Restore admission is based on logical restored FP32 sizes, not compressed file sizes. ### Disk-space results These results came from offline experiments and the original local implementation, before this cleanup/rebase, using Qwen3.8-Flash-Next UD-Q4_K_XL with int8 K/V. The original model runs used Linux and a Tesla V100-SXM2-32GB; the offline state comparison ran on CPU over real cache snapshots. They were **not rerun as real-model tests on this cleaned branch**. Measured files and format-derived sizes are identified separately. | Case | Original / baseline | Stored with codec | Space saved | Evidence and scope | |---|---:|---:|---:|---| | REF prefix sample | 278,223,720 B no-REF equivalent | **160,160,728 B measured v2 file** | **118,062,992 B (112.59 MiB)** | The v2 file was measured; the no-REF equivalent is format arithmetic, not a second measured file. REF is lossless. | | RHT recurrent state, five copies | 566,231,040 B FP32 | 287,539,200 B INT16 + FP32 scales | **278,691,840 B (265.78 MiB), 49.21875%** | Codec-size arithmetic over the accepted real-state samples, not a measured on-disk file; excludes metadata/alignment and convolution state. | | One complete GDN state copy, including RAW convolution | 117,669,888 B | 61,931,520 B | **55,738,368 B (53.16 MiB), 47.3684%** | Format/layout accounting checked against file metadata; this is not a whole-cache-file percentage. | On the original local build, the observed RHT base `.sess` was **218,849,020 B (208.71 MiB)** and the observed delta `.dlog` was **125,250,924 B (119.45 MiB)**. The base+delta chain was also restored after a same-version restart. These file sizes are recorded measurements from that build, not new measurements of this rebased branch. REF and RHT apply to different state/cache cases; their percentages must not be added into a single whole-cache saving claim. ### State-fidelity evidence, not a generation-quality claim On the same three real cache files (five independent recurrent-state copies, 141,557,760 FP32 values), the offline comparison measured relative L2 error of approximately `1.913e-5` for RHT+INT16 versus `2.056e-4` for FP16. These are **state-fidelity and storage measurements only**. They are not a generation-quality A/B and do not establish that RHT+INT16 is lossless. ### Validation on this branch Passed on Linux with CUDA 12.9, `sm_70`, Release, host-only tests: - Full requested build, including `strata`, `rht_state_codec_test`, and the conversation test targets. - CTest: **7/7 passed**: - `rht_state_codec_test` - `conversation_file_test` - `conversation_spill_test` - `session_save_reclaim_test` - `conversation_cache_test` - `conversation_snapshot_test` - `conversation_validation_test` - `PYTHONPATH=. python3 serve/test_monitor.py`: **12/12 passed**. - `strata --version`: `0.1.49.2`. The prerequisite commit was also built and tested separately before REF was applied; the REF commit was built and tested separately before RHT was applied. ### Not run / limits - HIP and SYCL builds were not run. - No real-model or GPU-execution test was run on this cleaned/rebased branch. - No generation-quality or performance benchmark was run on this branch. - Existing default/v1 and opt-in codec tests pass; a separate cross-build byte-for-byte comparison of default-off output was not run. - The prerequisite port is intentionally included for a self-contained draft and still needs to be reconciled with the canonical prerequisite PRs before this can become a small standalone merge PR. Feedback on the final two codec commits and the preferred unstacking order is welcome. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:11 +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#4898
No description provided.