You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(kvarn): group-range state serialization for prompt-cache compression
KVarN cache types with >4 bit widths (kvarn5, kvarn5/5, kvarn4/4 etc.)
wrote full pre-allocated records tensors on state save, making checkpoints
~5-7x larger than needed. This caused the checkpoint RAM budget to evict
all but one checkpoint at typical 18k+ token positions, leaving no viable
restore point for prompt-cache reuse.
Fix: bump KVAR_N_STATE_VERSION to 3 and serialize only the used portion
of the records tensors, computed as n_groups_used = ceil((pos_max+1)/128)
groups from metadata seq_pos_max. Stages are still written in full (only
384 tokens per stream per layer, negligible). On read, the unused tail is
zero-filled via ggml_backend_tensor_memset (GPU-safe, no host allocation).
The wire format change is additive: v3 writes n_groups_used after the
stream list, v2 reads skip it. V2 readers reject v3 data via the version
check; v3 readers handle v1 and v2 transparently.
Other fixes in the same change:
- write_kvarn_tensor_slice uses uint64_t for the size field on the wire
(was size_t, which would be 4 bytes on 32-bit, breaking portability)
- ggml_backend_tensor_memset replaces the host-allocated std::vector zero
buffer, eliminating per-layer heap allocations on checkpoint restore
Measured impact: kvarn5/5 checkpoint at 18k tokens drops from ~1992 MiB
to ~658 MiB (3x reduction). Multiple checkpoints now fit in the default
--cache-ram budget, enabling prompt-cache reuse for KVarN >4 types.
0 commit comments