Repository navigation
fish_drama3: keep several encoded reference voices (LRU) - #1345
Merged
Merged
Conversation
…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]>
Owner
|
@grogroningem-code Thanks for the improvement! PR merged. |
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.
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_slotstakes 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:
--logprintsdrama3.reference_cache hit|miss|skip <used>/<slots>for each lookup.Drama3ReferenceCacheclass built onruntime::CacheSlots, with its own unit test;Drama3Generator::encode_referencecalls into it. I added the option tomodel_specs/fish_drama3.json, to the loader's accepted options and to the table indocs/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.
multi_reference_condwith A and B), after both were usedThe WAVs match byte for byte across the two builds (one md5 per voice, plus one for the two-speaker request). With
reference_cache_slots: 1the 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_testchecks 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-lifecycleputs every expert layer on the GPU, and the Q3 package doesn't fit in 22 GB that way.🤖 Generated with Claude Code