Repository navigation
perf(voxcpm2): cheaper AudioVAE decode (exact-size graph, one-pass CPU Snake, optional CPU decode overlap) - #981
Merged
Conversation
…e count The decoder graph capacity doubled from patch_size until the request fit and the whole capacity was computed, so a 5.6 s phrase (140 latent frames) decoded a 256-frame (10.24 s) graph. The decoder is causal, so the padding never changes the kept samples; it only costs compute. Without voxcpm2.audiovae_latent_capacity the graph is now built at the request's frame count (rounded to patch_size) and the allocator is kept across rebuilds. Setting the option keeps the old reservation behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing windows off the generator thread Streaming decoded every window inside the generator's chunk callback, on the session backend, so generation stopped while the AudioVAE ran. On a 12-core Zen 5 CPU the decoder is ~40% of a request (offline 5.6 s of 20.7 s for 18.7 s of audio), and the generator scales poorly past ~6 threads (OpenMP barrier waits are ~20% of a perf profile), so the two serialized stages left cores idle. New session option voxcpm2.audiovae_threads (CPU only, default 0 = unchanged): the AudioVAE gets its own CPU ExecutionContext with that many threads, and streaming requests hand windows to a worker thread in patch order. Only the worker touches the StreamingAudioController and the event sink, and it is joined before the request returns, so events stay sequential. A failing sink (client gone) stops generation at the next patch and the error is rethrown. Output is bit-identical to the shared-backend path (offline, streaming, clone). Also documents voxcpm2.audiovae_latent_capacity's new meaning (previous commit). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Snake (x + sin(a*x)^2 / (a + 1e-9)) repeated alpha to the activation's full [1, C, T] size, ran scale_bias over that full tensor, then five more full-size passes; the sample-rate condition repeated its scale and bias the same way. ggml_mul / ggml_div broadcast [1, C, 1] directly, so the repeats go, and on the CPU backend Snake is one ggml_map_custom2 pass (the same float operations in the same order, rows split across the graph's threads; the pattern kokoro_tts already uses). Other backends keep the graph form. Output is bit-identical (offline, 3 and 6 sentences). AudioVAE decode on a Ryzen 9 9900X, 12 threads, 17.4 s of audio: 5.41 s -> 3.61 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
@ersensari Thanks for the optimizations! I updated the interface to use |
Owner
|
@ersensari 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.
What
Three VoxCPM2 AudioVAE changes that make CPU decoding cheaper. Outputs are bit-identical to
mainon the CPU backend.perf(voxcpm2): build the AudioVAE decoder graph at the request's frame countdecoder_capacity_for()doubled the capacity frompatch_sizeuntil the request fit, and the graph computed the full capacity. A 5.6 s phrase (140 latent frames) therefore decoded a 256-frame (10.24 s) graph. The decoder is causal, so the padding never changes the samples that are kept; it only costs compute. Whenvoxcpm2.audiovae_latent_capacityis not set, the graph is now built at the request's frame count (rounded topatch_size) and the allocator is kept across rebuilds (a graph rebuild costs ~6.5 ms). Setting the option keeps the old reservation behaviour.perf(voxcpm2): optional dedicated CPU AudioVAE backend, decode streaming windows off the generator threadUses
voxcpm2.exec_planwith componentaudiovaeandparams.threads. Omitted/zero threads retain the shared session backend. Positive values require a CPU session. Example:{"audiovae":{"impl":"ggml","backend":"cpu","params":{"threads":4}}}ExecutionContextwith N threads.StreamingAudioControllerand the event sink. It is joined before the request returns, so events stay sequential.perf(voxcpm2): one-pass CPU Snake, broadcast AudioVAE per-channel paramsalphato the full[1, C, T]size and then make five more full-size passes. The sample-rate condition repeated its scale and bias the same way.ggml_mul/ggml_divbroadcast[1, C, 1]directly, so the repeats are gone.ggml_map_custom2pass: the same float operations in the same order, with rows split across the graph's threads.kokoro_ttsalready uses this pattern.Why: profiling on a Ryzen 9 9900X (Zen 5, 12 cores) put the AudioVAE at ~43% of a plain request.
perfshowed the generator spending ~20% of its time in libgomp barrier waits, and 8, 12 and 16 threads all ran at about the same speed. That means the decoder and the generator can overlap on separate cores instead of running one after the other.Validation
Build (CPU only, voxcpm2 only, Ubuntu 24.04, gcc 14, OpenMP):
Model:
audio-cpp/audio.cpp-ggufVoxCPM2-GGUF/voxcpm2-q8_0.gguf.The table below is from a re-run on this branch against
main@ ccdbe76, using the same commands. Each run was a single CLI process,--threads 12,--request-option seed=13.audiovae_decoder_mslatent_capacity 256)latent_capacity 140)bf50140e…/c77d9514…bf50140e…/c77d9514…(identical)Other numbers from the same machine, measured during development on
main@ 5b772fe (the branch was later rebased onto ccdbe76; voxcpm2 is untouched between the two apart fromdocs/tts.md):stream_frames_per_event4 (default)stream_frames_per_event16audiovae.params.threads=-1gives a clear error.model_spec_system_testandtools/check_loader_catalog_sync.pypass.CUDA: RTX 5060 Ti (sm_120), CUDA 12.9.1, voxcpm2-only build.
main.audiovae.params.threads > 0on CUDA is rejected, as designed.All three commits run on CUDA in a self-hosted voice assistant (streamed 48 kHz speech) (in use since 2026-10-19).
Execution-plan Refactor Validation
Debug, Q8, streaming, 48-character input, seed 13, eight generator threads. Median of three interleaved fresh CLI-session runs per version; these are not warmed persistent-session measurements.
All outputs are byte-identical across versions. No observed performance regression; small timing differences are not claimed as speedups. Strict Clang C++17, Debug build, and model-spec validation pass. Standalone existing GGUF runs without a spec override; empty/default plans, the CPU worker, and invalid-plan rejection were checked.
Known limitations
🤖 Generated with Claude Code