Skip to content

feat(audio-lm): streaming through codec memory (causal decoders), look_* windows for the rest, DAC hop fix - #6

Draft
hans00 wants to merge 2 commits into
feat/codec-memoryfrom
fix/streaming-incremental-decode
Draft

hans00 wants to merge 2 commits into
feat/codec-memoryfrom
fix/streaming-incremental-decode

Conversation

@hans00

@hans00 hans00 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Reworked on top of #9 (codec memory); base is now feat/codec-memory, so the diff shows only this PR. The earlier versions (stateful Qwen3 stream graph, then windowed stateless streaming) are replaced.

codec_audio_lm_stream_poll / _finish:

  • 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. There is no hold-back and no cross-fade, and the stream equals the batch decode to float rounding.
  • ICL reference state: an ICL voice's reference codes are decoded into the memory once per voice. The state after them (codec_memory_state_get_data) is kept in the audio_lm context and restored with set_data 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, so batch output is bit-identical.
  • Other decoders (DAC, WavTokenizer, ...) use the stateless window. Its left context and hold-back come from codec.decoder.look_back / look_ahead (the GGUF keys, else the per-arch defaults) instead of a per-arch table. An unbounded look (-1) decodes from the first frame and holds back 0.32 s, as before.
  • DAC hop fix (unchanged from the earlier version): the hop is the product of the decoder's upsampling strides, so a GGUF converted from HF dac_16khz's config (hop_length 512, real hop 320) now loads with hop 320 (with a warning). Its default look_back / look_ahead is therefore 16 / 16 frames (0.32 s), not 10. The converter writes the strides' product. The published 24 kHz DAC files already have hop 320; their default is 24 / 24.

Public headers (include/, common/*.h): no changes (gh pr diff --name-only lists none). The new headers src/audio_lm_stream.h, src/audio_lm_window.h and src/codec_look.h sit in the audio_lm objects' private include dir and are not installed. Note: the codec_audio_lm_stream_poll comment in include/codec_audio_lm.h still says "re-decodes the generation from its first frame". Updating it is a public-header change, so I left it alone; it can go into a later proposal.

Tests:

  • tests/e2e/audio_lm_stream_smoke.py:
    • Qwen3-TTS ICL (memory): rel. RMS vs batch 8.2e-4; a repeat stream with the restored reference state is identical.
    • CSM / Mimi (memory): rel. RMS 4.8e-5.
    • OuteTTS 1.0 / DAC (window 0.32 / 0.32 s): identical to batch.
    • All runs: same length as batch, log-mel distance 0.00 dB.
  • codec_memory_smoke.py OK, audio_lm_host_smoke.py OK, python_tts_smoke.py OK.
  • ttsserver_smoke.py fails one check, "two paragraphs did not run as two segments". It fails the same way on feat/codec-memory without this PR (KittenTTS, no streaming involved).

Phone (Pixel 7 Pro, live-translate 0.3.13 vendoring this branch at bf5f788; Qwen3-TTS-12Hz-0.6B Base, x-vector voice, 6 zh-TW lines, 960 ms pieces):

  • The first streamed piece arrives after ~0.75 s. Batch decode delivers nothing before the whole line is done (13.7–35.5 s).
  • Total RTF is 4.43–4.59, against 4.17–4.30 for batch. Chunked decode costs ~5–10 % more than one batch decode. With 480 ms pieces it was worse.
  • At RTF ~4.4, gapless playback can only start once ~80 % of a line exists, so time-to-sound improves only on long lines (35.5 → 29.9 s).
  • The bigger gain would come from running the decode on its own thread while the backbone generates: the decode is ~43 % of the wall time. That needs the runner to snapshot the codes, and it is not in this PR.

🤖 Generated with Claude Code

hans00 added a commit that referenced this pull request Nov 15, 2026
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>
hans00 added a commit that referenced this pull request Nov 15, 2026
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>
hans00 added a commit that referenced this pull request Nov 15, 2026
…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>
hans00 and others added 2 commits November 16, 2026 10:43
HF descript/dac_16khz's config says hop_length 512, but its ratios (2*4*5*8)
give 320, and the converter wrote the config value: codec_model_hop_size
reported 512 for a 320-sample hop. The loader now takes the product of the
decoder blocks' ConvTranspose strides when the weights disagree with
codec.hop_size (with a warning, so existing GGUFs are right without
re-converting), and the converter writes the product of downsampling_ratios.
Decoded audio is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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>
@hans00
hans00 force-pushed the fix/streaming-incremental-decode branch from ae35a74 to bf5f788 Compare November 16, 2026 03:29
@hans00
hans00 changed the base branch from main to feat/codec-memory November 16, 2026 03:29
@hans00 hans00 changed the title feat: exact incremental decode for streaming (Qwen3-TTS-Tokenizer), cached ICL reference state feat(audio-lm): streaming through codec memory (causal decoders), look_* windows for the rest, DAC hop fix Nov 16, 2026
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