Skip to content

perf(voxcpm2): cheaper AudioVAE decode (exact-size graph, one-pass CPU Snake, optional CPU decode overlap) - #981

Merged
0xShug0 merged 4 commits into
0xShug0:mainfrom
ersensari:voxcpm2-audiovae-perf
Oct 19, 2026
Merged

0xShug0 merged 4 commits into
0xShug0:mainfrom
ersensari:voxcpm2-audiovae-perf

Conversation

@ersensari

@ersensari ersensari commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Three VoxCPM2 AudioVAE changes that make CPU decoding cheaper. Outputs are bit-identical to main on the CPU backend.

  1. perf(voxcpm2): build the AudioVAE decoder graph at the request's frame count
    decoder_capacity_for() doubled the capacity from patch_size until 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. When voxcpm2.audiovae_latent_capacity is not set, the graph is now built at the request's frame count (rounded to patch_size) and the allocator is kept across rebuilds (a graph rebuild costs ~6.5 ms). Setting the option keeps the old reservation behaviour.
  2. perf(voxcpm2): optional dedicated CPU AudioVAE backend, decode streaming windows off the generator thread
    Uses voxcpm2.exec_plan with component audiovae and params.threads. Omitted/zero threads retain the shared session backend. Positive values require a CPU session. Example:
    {"audiovae":{"impl":"ggml","backend":"cpu","params":{"threads":4}}}
    • With N > 0, the AudioVAE gets its own CPU ExecutionContext with N threads.
    • Streaming requests hand their windows, in patch order, to a worker thread while the generator keeps running.
    • Only the worker touches the StreamingAudioController and the event sink. It is joined before the request returns, so events stay sequential.
    • If the sink fails (client gone), generation stops at the next patch and the error is rethrown.
    • Positive AudioVAE thread counts on other backends are rejected with a clear error; an explicit component backend must match the session.
  3. perf(voxcpm2): one-pass CPU Snake, broadcast AudioVAE per-channel params
    • Snake used to repeat alpha to 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_div broadcast [1, C, 1] directly, so the repeats are gone.
    • On the CPU backend, Snake is now a single ggml_map_custom2 pass: the same float operations in the same order, with rows split across the graph's threads. kokoro_tts already uses this pattern.
    • Other backends keep the graph form.

Why: profiling on a Ryzen 9 9900X (Zen 5, 12 cores) put the AudioVAE at ~43% of a plain request. perf showed 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):

cmake -S . -B build-native -DCMAKE_BUILD_TYPE=Release -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=voxcpm2 \
  -DENGINE_ENABLE_CPU_ALL_VARIANTS=ON -DENGINE_ENABLE_CUDA=OFF -DENGINE_ENABLE_VULKAN=OFF -DENGINE_ENABLE_OPENMP=ON \
  -DENGINE_BUILD_EXAMPLES=OFF -DENGINE_BUILD_TESTS=OFF -DENGINE_BUILD_WARMBENCH=OFF
cmake --build build-native --parallel --target audiocpp_cli --target audiocpp_server

Model: audio-cpp/audio.cpp-gguf VoxCPM2-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.

audiocpp_cli --task tts --family voxcpm2 --model voxcpm2-q8_0.gguf --backend cpu --threads 12 \
  --request-option seed=13 --text "Good morning. I checked the schedule, and your first meeting starts at nine. The rest of the day is clear, so you can finish the report." \
  --out plain.wav --metrics --log
# clone: --task clon --voice-ref ref.wav --reference-text "<transcript>"
main this branch
plain: audiovae_decoder_ms 3313 (latent_capacity 256) 1420 (latent_capacity 140)
plain: RTF 1.39 1.05
clone: RTF 1.84 1.31
sha256, plain / clone 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 from docs/tts.md):

  • Commit 1 alone, 6 sentences offline: VAE 6.36 → 5.62 s.
  • Commit 3, 17.4 s of audio: VAE 5.41 → 3.61 s. Clone reference encoder: 3.39 → 1.51 s.
    • Bit-identical: offline 3 and 6 sentences, and clone including the reference encoder.
  • Commit 2, server streaming, 6 sentences (18.7 s of audio at 10 steps, 17.4 s at 5). Each cell gives RTF / total playback stall, if playback starts at the first chunk:
config 10 steps 5 steps
main, 12 threads, stream_frames_per_event 4 (default) 2.03 / 18.9 s 1.55 / 9.3 s
main, 12 threads, stream_frames_per_event 16 – 1.26 / 6.2 s
commit 1, 12 threads, fpe 16 1.31 / 7.4 s –
all three, 12 generator + 4 AudioVAE threads, fpe 16 1.09 / 3.8 s 0.99 / 3.4 s
all three, 6 generator + 6 AudioVAE threads, fpe 16 1.28 / 7.2 s 0.87 / 2.5 s
  • Output was bit-identical to the shared-backend path (offline, streaming and clone).
  • Disconnecting the client mid-stream, three times: generation stopped at the next window, and the next request was served normally.
  • audiovae.params.threads=-1 gives a clear error.
  • model_spec_system_test and tools/check_loader_catalog_sync.py pass.

CUDA: RTX 5060 Ti (sm_120), CUDA 12.9.1, voxcpm2-only build.

  • VAE: 151 → 70 ms (3 sentences) and 305 → 234 ms (6 sentences). Total request time changes only 2-8%, because the VAE is small on the GPU.
  • Plain TTS output is bit-identical to main.
  • Clone output differs at 66.4 dB SNR. Both builds are deterministic; the smaller graph from commit 1 picks different CUDA kernels, so this is a rounding-level difference.
  • audiovae.params.threads > 0 on CUDA is rejected, as designed.
  • RTF 0.18 at 10 steps.

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.

Path Original PR RTF Execution-plan RTF Peak VRAM, original → refactored
CPU shared backend 1.930 1.924 —
CPU worker, four AudioVAE threads 1.324 1.314 —
CUDA shared backend 0.194 0.189 3,628 → 3,628 MiB

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

  • The dedicated AudioVAE worker helps only on the CPU backend, and only when the generator has spare cores. On this CPU, splitting 6+6 across the two CCDs works best at 5 steps.
  • Offline requests still decode after generation; the overlap applies to streaming only.

🤖 Generated with Claude Code

ersensari and others added 3 commits October 19, 2026 13:31
…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]>
@0xShug0

0xShug0 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

@ersensari Thanks for the optimizations! I updated the interface to use voxcpm2.exec_plan, consistent with other models for this type of optimization.

@0xShug0
0xShug0 merged commit 673ade4 into 0xShug0:main Oct 19, 2026
6 checks passed
@0xShug0

0xShug0 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

@ersensari PR merged!

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