Skip to content

fish_drama3: keep several encoded reference voices (LRU) - #1345

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
grogroningem-code:pr/drama3-voice-cache
Nov 19, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
grogroningem-code:pr/drama3-voice-cache

Conversation

@grogroningem-code

@grogroningem-code grogroningem-code commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Every time a Drama 3 request switches reference voice, the engine encodes the reference clip again, because it only remembers the encoding of the last waveform it saw. For a client that alternates between two speakers (a dialogue between two characters, say), that's 0.45-0.57 s of extra wait on every request on an RTX 2080 Ti.

With this change the generator keeps up to N encoded references in host memory and drops the least recently used one when it's full. Lookups match on the exact waveform (sample rate, channel count and every sample), so a hit hands back the same codes the encoder would have produced and the audio doesn't change by a single byte.

The new session option fish_drama3.reference_cache_slots takes 0 to 64 and defaults to 8. Set it to 0 and every request encodes; 1 behaves like the current code. Anything else stops the server at startup with an error that names the option.

A few smaller points:

  • Clips over 30 s at 44.1 kHz still get encoded but aren't stored, and they no longer push the cached voices out.
  • --log prints drama3.reference_cache hit|miss|skip <used>/<slots> for each lookup.
  • Each entry holds its waveform (5.3 MB at most, for a 30 s clip) next to its codes, so 8 slots cost at most about 42 MB of host RAM.
  • The logic lives in a small Drama3ReferenceCache class built on runtime::CacheSlots, with its own unit test; Drama3Generator::encode_reference calls into it. I added the option to model_specs/fish_drama3.json, to the loader's accepted options and to the table in docs/models/fish_drama3.md.

Measurements

I ran both builds on an RTX 2080 Ti 22 GB with CUDA 13.5 on Linux: Q3_K_S backbone, 8-bit experts, streaming, seed 42. Upstream is df60b9d compiled with the same options as this branch. A and B are two reference WAVs, and each number is time to first audio.

Request upstream this PR
A and B alternating, after each was used once 1.10 s / 0.92 s 0.53 s / 0.47 s
The same voice repeated 0.53 s / 0.47 s 0.53 s / 0.47 s
A voice's first use 1.12 s / 0.94 s 1.13 s / 0.94 s
Two-speaker request (multi_reference_cond with A and B), after both were used 1.77 s 0.74 s

The WAVs match byte for byte across the two builds (one md5 per voice, plus one for the two-speaker request). With reference_cache_slots: 1 the patched server reproduces upstream's timings and logs a miss on every voice change; at the default of 8 it logs one miss per new voice and hits after that.

The new fish_drama3_reference_cache_test checks alternating voices, eviction order, exact matching (an equal waveform in a fresh buffer still hits), long clips, and which option values the loader accepts or refuses. The existing fish_drama3 sampler, tokenizer (with the tokenizer files present), expert quantization, backbone allocation and codec source tests also pass. One I couldn't run: fish_drama3_codec_source_test --stream-lifecycle puts every expert layer on the GPU, and the Q3 package doesn't fit in 22 GB that way.

🤖 Generated with Claude Code

…rm match)

Drama 3 cached the encoded reference for one waveform only, so every
change of voice re-encoded the reference clip (about 0.4-0.57 s on an
RTX 2080 Ti). Drama3ReferenceCache keeps up to N encodings in host memory,
keyed by sample rate, channel count and every sample byte, and evicts the
least recently used one. A clip over 30 s is encoded and never stored, and
no longer clears the cached voices.

New session option fish_drama3.reference_cache_slots: 0 to 64, default 8;
0 encodes every request. Each lookup logs drama3.reference_cache
hit|miss|skip with --log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@0xShug0

0xShug0 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@grogroningem-code Thanks for the improvement! PR merged.

@0xShug0
0xShug0 merged commit f270511 into 0xShug0:main Nov 19, 2026
7 checks passed
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.

2 participants