Skip to content

docs(rfc): codec memory — streaming encode/decode state in codec_context - #8

Draft
hans00 wants to merge 6 commits into
mainfrom
docs/rfc-codec-memory
Draft

hans00 wants to merge 6 commits into
mainfrom
docs/rfc-codec-memory

Conversation

@hans00

@hans00 hans00 commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Proposal only. This adds one document, docs/proposals/codec_memory.md, and changes no code or header. include/ and common/*.h stay untouched until the design is approved.

What it proposes (the smallest possible change)

  • A context can have an encoder memory, a decoder memory, or both. Each is a context cache (sliding-window K/V, conv tails, transposed-conv overlap sums, position) with its own clear and state save/restore.
  • Unchanged: codec_encode and codec_decode handle their input, padding and output exactly as today, and no status code is added. On a causal side, consecutive calls give the batch output.
  • New GGUF keys codec.{encoder,decoder}.{look_back,look_ahead}, in frames:
    • is_causal means look_ahead == 0, and −1 means unbounded;
    • on a causal side, look_back is how many frames the memory caches;
    • on a non-causal side, look_back / look_ahead are the window the host re-decodes, and memory size is 0.
  • Old GGUFs: missing keys fall back to per-arch defaults, so old files still load. feat(audio-lm): streaming through codec memory (causal decoders), look_* windows for the rest, DAC hop fix #6's window table becomes those defaults.
  • Only restriction: codec_decode_batch neither reads nor updates memory, because a batch holds several sequences and memory holds one.
  • Also covered: a rollout section (published GGUFs get the keys in place later, each upload approved separately), the format of the saved state, thread safety, how it relates to feat(audio-lm): streaming through codec memory (causal decoders), look_* windows for the rest, DAC hop fix #6, ABI (codec_context_params grows) and a test plan.

Naming

Earlier drafts Now llama.cpp counterpart
enum codec_memory_type / enum codec_part removed: one handle per side none
codec_context_params.memory bool encoder_memory; bool decoder_memory; llama_context_params KV settings
codec_get_memory(ctx) codec_get_encoder_memory(ctx) / codec_get_decoder_memory(ctx) llama_get_memory(ctx)
codec_memory_clear(mem, which/parts) codec_memory_clear(mem) llama_memory_clear(mem, data)
codec_memory_state_*(mem, which, …) / codec_state_*(ctx, parts, …) codec_memory_state_get_size / get_data / set_data(mem, …) llama_state_get_size / get_data / set_data(ctx, …). We depart on purpose: state lives on the handle, so it is always clear which side is saved
codec_model_has_memory / codec_model_is_causal(model, part) codec_model_encoder_is_causal(model) / codec_model_decoder_is_causal(model) none

Out of scope:

  • the LLM's KV cache;
  • the reference-voice decoder state, which is for a future codec_speaker proposal.

🤖 Generated with Claude Code

hans00 and others added 6 commits November 15, 2026 12:46
Proposal only; no header changes. A context can own encoder and decoder
memory (llama_memory_t-style: codec_get_memory, codec_memory_clear,
codec_memory_state_get_size/get_data/set_data), so codec_encode /
codec_decode continue a stream. Covers per-family semantics (Mimi,
Qwen3-TTS tokenizer, MOSS, DAC, SNAC, WavTokenizer), how #6's windowed
streamer becomes the internal fallback, the state blob format and
versioning, thread safety and open questions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per review: memory caches the context a model needs (sliding-window K/V,
conv tails, convtr overlap partial sums, position) and nothing else.
Removed flush, the ended state, input buffering, held-back output, the
WINDOW kind and the in-library crossfade; each call returns exactly what
a stateless call returns for its input. Encode chunks must be hop-aligned
(the batch tail padding and the measured effect of caller zero-padding
are documented). v1 supports causal models only; #6's host windowing
stays the fallback. codec_model_memory_kind becomes
codec_model_has_memory; codec_memory_n_frames and the speaker question
are dropped (reference-voice state is a future codec_speaker proposal).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per review, minimal change: models with no context to remember have
memory size 0 and enabling it is a valid no-op (no "unsupported");
codec_model_has_memory means "non-zero memory". codec_encode/decode
input handling, padding and output are unchanged; no hop-alignment
rule, no new status codes, no fixed-per-stream parameters. The only
restriction kept: codec_decode_batch neither reads nor updates memory
(several sequences vs one). Removed all open questions (padding,
sample rate, graph cache, non-causal support).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per review: codec_model_has_memory becomes codec_model_is_causal (no
look-ahead; memory then makes streamed output equal batch; non-causal
parts have memory size 0). enum codec_memory_type becomes the bit set
enum codec_part (NONE / ENCODER / DECODER / ALL), shared by the memory
field, clear's `parts` and the state calls. Save/restore moves to the
context as in llama.cpp: codec_state_get_size / get_data / set_data.
The #6 streamer takes the incremental path when the decoder is causal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…keys

Per Hans's approved direction: drop enum codec_part. One memory handle
per side (encoder_memory / decoder_memory params,
codec_get_encoder_memory / codec_get_decoder_memory), clear and state
save/restore on the handle (deliberately unlike llama_state_*(ctx)),
codec_model_encoder_is_causal / codec_model_decoder_is_causal.
New GGUF keys codec.{encoder,decoder}.{look_back,look_ahead} in frames,
written by converters; is_causal = look_ahead == 0; -1 = unbounded;
look_back on a causal side is the cached context length. Missing keys
fall back to per-arch defaults (old GGUFs load); #6's window table
becomes those defaults. Adds a Rollout section (published GGUFs updated
in place later, each upload approved separately).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mimi's transformers (also the Qwen3-TTS tokenizer's encoder) run at
25 Hz, twice the 12.5 Hz codec frame rate, so their 250-step sliding
window is 125 codec frames, not 250. look_back is stated in codec frames
throughout; a layer's cache spans its window at its own rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant