Repository navigation
Conversation
Implements the API of docs/proposals/codec_memory.md (RFC #8): codec_context_params.encoder_memory / decoder_memory, codec_get_encoder_memory / codec_get_decoder_memory, codec_memory_clear, codec_memory_state_get_size / get_data / set_data and codec_model_encoder_is_causal / codec_model_decoder_is_causal, mirrored in the Python bindings (codec_cpp.Memory, Context(encoder_memory=, decoder_memory=), Model.encoder_is_causal / decoder_is_causal). src/runtime/memory.{h,cpp}: a memory's cache slots (conv left tails, ConvTranspose overlap partial sums before the bias, sliding-window K/V) are recorded by building the side's graph once in planning mode at context creation, allocated on the context's backend and zeroed by a clear. A graph reads a slot as an op's left context and writes the context it leaves behind back with ggml_cpy side roots, as llama.cpp writes its KV cache; attention positions and the validity mask are per-call inputs, so one cached graph serves every chunk of a length. The state blob (magic, versions, arch, side, SHA-256 model fingerprint, typed sections) is validated before anything is restored. Causality comes from the new GGUF keys codec.{encoder,decoder}. {look_back,look_ahead} (look_ahead 0 = causal), with per-arch defaults for GGUFs without them. A non-causal side's memory has size 0 and is a no-op; codec_decode_batch neither reads nor updates memory. With memory off, outputs are bit-identical to before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Mimi encoder (also the Qwen3-TTS tokenizer's) and decoder take an optional codec_memory: causal conv tails (the replicate-padded downsample seeded from the first value after a clear), ConvTranspose overlaps and the transformers' 250-step (25 Hz) sliding-window K/V. The batch graphs keep their unbounded causal attention (CODEC_MIMI_BATCH_WINDOW = 0, as HF's eager / sdpa path), so streamed output equals batch only within the first 250 transformer steps (10 s); whether batch applies Mimi's trained 250-step window is pending review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Audio, NeMo The causal graphs take an optional codec_memory: causal convs read their left padding from the cache, causal ConvTransposes carry their overlap, sliding-window attention (Qwen3 decoder: 72 frames; MOSS: each block's context_duration) caches K/V with absolute RoPE positions, and MOSS's padding mask carries over. Each arch's memory_plan builds one frame of its graph to size the slots. MOSS-Audio's look_back defaults to its longest block context. Streamed vs batch on hop-aligned random chunks: NeMo bit-exact; Qwen3 decoder and MOSS within float reassociation of the cached attention rows (rel. RMS 5e-4 / 9e-4, MOSS encoder 0.75 % codes flip in the deep RVQ levels). Memory off: bit-identical to before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In codec frames (docs/proposals/codec_memory.md): Mimi 125 / 0 both sides (a 250-step window at 25 Hz), Qwen3-TTS tokenizer encoder 125 / 0 and decoder sliding_window / 0, MOSS-Audio the longest block context / 0, NeMo decoder 27 / 0; the non-causal decoders get the window a host re-decodes around a chunk: DAC 0.32 s / 0.32 s, WavTokenizer 1.28 s / 0.32 s. GGUFs without the keys load with the same per-arch defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Streamed vs batch on hop-aligned random chunks (one longer than the attention window, several of one frame) for every causal side found under models/, state restore into a fresh context continuing bit-exactly, rejected foreign / corrupted / truncated blobs leaving the cache unchanged, clear == a fresh context, codec_decode_batch bypassing memory, a non-causal (DAC) decoder memory being a size-0 no-op, and the look_ahead key (as a load-time override) deciding causality. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st chunk A chunk that is not a whole number of hops is padded on the right as the batch op pads its clip's end; Mimi's downsample pads by repeating the last value, which the memory path padded with zeros, so the last frame's codes of an unaligned final chunk differed from batch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…evel criterion Adds an encode whose last chunk is not a whole hop (compared with batch on the same clip), a --seconds option, and judges encode flips on the first 8 RVQ levels (<= 0.5 %) and all levels (<= 5 %): the deep levels sit at near-ties that rounding flips (Mimi's batch flips ~1 % between clip lengths). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mimi's transformers (Kyutai's `context: 250`, HF MimiConfig.sliding_window; also the Qwen3-TTS tokenizer's encoder) were trained with a 250-step sliding window, which the batch graphs did not apply (as HF's eager / sdpa path, which ignores sliding_window; only its flash path applies it). The window now comes from the side's look_back (GGUF codec.<side>.look_back, else the per-arch default 125 codec frames) times the transformer's steps per frame (2), the same source codec memory uses, so batch and streamed output agree past 10 s and the memory cache stays bounded. BREAKING CHANGE: batch encode / decode output changes for Mimi-arch codecs (Mimi, CSM, LFM2-Audio, Moshi) and the Qwen3-TTS tokenizer encoder on clips longer than 10 s (250 steps at 25 Hz); clips up to 10 s are bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…levels MOSS-Audio-Nano has 16 levels, so "the first 8" included deep levels where rounding flips codes at near-ties (0.4-0.8 % on a 24 s clip). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hans00
added a commit
that referenced
this pull request
Nov 16, 2026
…he rest from look_* codec_audio_lm_stream_poll, rebuilt on the codec memory API (#9): - Causal decoders (codec_model_decoder_is_causal with memory state: Qwen3-TTS-Tokenizer-12Hz, Mimi, NeMo, MOSS-Audio): each poll decodes only the new frames, in whole chunk_ms pieces, on a second codec context with decoder_memory, created at the first stream. No hold-back, no cross-fade; the stream equals the batch decode to float rounding (Qwen3 ICL rel. RMS 8.2e-4, CSM/Mimi 4.8e-5). - ICL voices: the reference's codes are decoded into the memory once per voice; the memory state after them (codec_memory_state_get_data) is kept in the audio_lm context and restored for the next generation with that voice. Batch decodes are unchanged (they still decode reference + generation on the context's own codec context and cut). - Other decoders: the stateless window of the windowed streamer, with left context and hold-back read from codec.decoder.look_back / look_ahead (GGUF keys, else the per-arch defaults) instead of a per-arch table. An unbounded look_back or look_ahead decodes from the first frame (exact, quadratic) and holds back 0.32 s, as before. Internal only: src/audio_lm_stream.h, src/audio_lm_window.h and src/codec_look.h are in the audio_lm objects' private include dir. No change to include/ or common/*.h. tests/e2e/audio_lm_stream_smoke.py checks the memory path against batch (rel. RMS <= 1e-3, a repeat stream with the restored ICL state identical) and the windowed path (DAC) perceptually. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements the codec memory API approved in RFC #8 (as of e0d6100): a context can cache the context its encoder and/or decoder need from earlier input.
Public headers
include/codec.hgets exactly the additions approved in the RFC. No other file ininclude/orcommon/*.hchanges.codec_cpp.Memory,Context(encoder_memory=, decoder_memory=),Model.encoder_is_causal/decoder_is_causal.How it works
memory_planvtable hook). That records the cache slots, which are then allocated on the context's backend.ggml_cpyside roots, as llama.cpp writes its KV cache.codec.{encoder,decoder}.{look_back,look_ahead}. GGUFs without the keys use per-arch defaults, so old GGUFs load unchanged.codec_decode_batchneither reads nor updates memory.origin/main(checked for Mimi, Qwen3 tokenizer, MOSS-Nano, NeMo and DAC encode + decode).Which sides have memory
Converters: they write the four keys (checked by converting the local Mimi, Qwen3 tokenizer, NeMo, DAC and WavTokenizer checkpoints).
Tests:
tests/e2e/codec_memory_smoke.py [--seconds S]checks:codec_decode_batchbypasses memory;look_aheadkey decides causality.All four models pass every check at the default 24 s:
Pixel 7 Pro (big cores, 4 threads, F32, 10 s of codes, 6-frame = 0.48 s chunks; RTF = decode time ÷ audio length):
Deviations from the RFC / open
origin/mainfor clips ≤ 10 s (Mimi, Qwen3 tokenizer, MOSS-Nano, NeMo, DAC).look_backis 125 codec frames, not 250. The RFC is fixed in docs(rfc): codec memory — streaming encode/decode state in codec_context #8 (e7abd2a).look_*frames use the GGUF hop, so the 16 kHz model gets 10 frames until feat(audio-lm): streaming through codec memory (causal decoders), look_* windows for the rest, DAC hop fix #6's hop fix (320, not 512) lands; it should be 16.freshbyte and per-clock position counters;impl_version.codec_model_decoder_is_causal, and read its window from thelook_*metadata instead ofsrc/audio_lm_window.h.🤖 Generated with Claude Code