Add compile_codec option for 3-4x faster batch decoding#191
Open
Finrandojin wants to merge 1 commit into
Open
Conversation
The speech tokenizer codec decoder contains 100+ attention modules whose Python dispatch overhead dominates decoding time (~47% single, ~85% batch). Applying torch.compile with mode="max-autotune" and dynamic=True fuses these into optimized kernels, improving batch throughput by 3-4x. This adds: - compile_codec parameter to from_pretrained() (False/True/mode string) - _compile_codec() method for post-construction compilation - Performance Tips section in README with usage examples and benchmarks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Set this up locally on top of that Faster Qwen3-TTS fork that's using CUDAGraphs and I'm getting massive speedups with no change in generation quality. PR works 👍 |
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.
Summary
compile_codecparameter toQwen3TTSModel.from_pretrained()that appliestorch.compile(mode="max-autotune", dynamic=True)to the speech tokenizer codec decoder_compile_codec()instance method for post-construction compilationMotivation
The codec decoder contains 136+ attention modules whose Python dispatch overhead dominates waveform decoding time. Profiling shows:
Applying
torch.compileeliminates this overhead:Tested on AMD RX 7900 XTX (ROCm 6.3) and the optimization is hardware-agnostic —
torch.compilewithdynamic=Trueworks on NVIDIA, AMD, and CPU backends.API
Trade-offs
compile_codec=False(default)Test plan
compile_codec=Falseproduces identical results to current behaviorcompile_codec=Truecompiles codec and generation works correctlycompile_codec="max-autotune"string mode worksgenerate_custom_voice)