Repository navigation
OmniVoice: native batching and faster generation - #1208
Conversation
|
@kawshikbuet17 Thanks for the PR! This is a great improvement. One regression found: With Q8 weights, voice cloning, seed 17, and 16 steps, this input succeeds on main but aborts the PR’s CLI and server: The new packed layout creates attention-mask views at unaligned buffer offsets. Vulkan softmax rejects those offsets. Setting Other minor cleanup:
Update: also please rebase. |
The Qwen3 diffusion graph now runs 2 * N sequences per step (rows 0..N-1 conditional, N..2N-1 unconditional) instead of 2, so N requests share one forward pass per decoding step. Each request is padded to the longest one; padded positions attend only to themselves. Target-frame gather, audio head and classifier-free guidance (per-request scale) work on the whole batch. The memory-saver layerwise graph is batched the same way. OmniVoiceQwen3DiffusionRuntime::generate_batch() keeps a schedule, RNG and accepted tokens per request; requests may differ in length, guidance scale and step count. generate() is generate_batch() with one request and gives bit-identical output to before (the candidate order of the threaded scorer is kept, since the position noise is drawn in that order). tests/omnivoice/omnivoice_batch_test.cpp compares run() with run_batch() and with raw outputs saved by an earlier build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
OmniVoiceSession implements IBatchedOfflineVoiceTaskSession, so the server's /v1/tasks/batch runs OmniVoice requests as one batch. Every request gets its own seeded RNG (same seed => same result as run() for a batch of one). Requests over the chunk threshold are split as in run(); round k batches chunk k of every request, so a request without reference audio still uses its own first chunk as the reference. Audio decode and post-processing stay per request. omnivoice_batch_test: --timing-log and --request-option. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The unconditional sequence of a request is only its target frames, but it was padded to the full prompt length (style + text + reference + target), so about a quarter of every forward pass was padding. The forward graph now lays out the conditional rows and the target-length unconditional rows back to back: norms, projections and MLP run once over all tokens, and attention runs per segment with its own mask. omnivoice.packed_cfg=false restores the previous layout, which is still bit-identical to the old output. Packed vs unpacked first-step logits with f32 weights: mean |diff| 0.001-0.002, 99.9-100% argmax agreement. RTX 4090, f16 weights, 16 steps: one 9-word request 0.281 -> 0.222 s, batch of 8 such requests 1.995 -> 1.404 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every decoding step read the full guided logits back to the host ([frames, codebooks, 1025] floats per request) and scored them on CPU threads, about 30% of the request time. For greedy class decoding (the default, class_temperature=0) the forward graph now also computes, per (frame, codebook), the best non-mask token and its log-probability (logit - logsumexp), and only those are read back. Ties, common with f16 weights, go to the lowest token index as in the CPU scorer. Sampled class decoding and the layerwise (mem_saver) graph keep the host scorer; omnivoice.device_scoring=false forces it. On the RTX 4090 the device scores give bit-identical audio to the host scorer for the test requests (max log-prob difference 1.5e-5). RTX 4090, f16 weights, 16 steps: one 9-word request 0.222 -> 0.147 s, batch of 8 such requests 1.404 -> 0.966 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With packed guidance rows a batch still padded every conditional row to the longest prompt, so mixed-length batches did more work than the same requests one by one. Each row of the packed layout now has exactly its request's length (prompt for the conditional row, target frames for the unconditional one); attention runs per segment of consecutive equal-length rows, and each segment's context is written into its slot of the layer output. generate_batch() orders requests by length internally so equal lengths share segments and graph shapes, and returns results in the caller's order. A request's logits in a packed batch are now exactly equal to its solo logits with f32 weights; with f16 weights 6 of the 8 mixed-length test requests give bit-identical audio to run(). RTX 4090, f16 weights, 16 steps, 8 requests of 5-20 words: run_batch() 2.536 -> 1.442 s (8 x run() 1.569 s). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Model spec and docs list omnivoice.packed_cfg and omnivoice.device_scoring; docs/models/omnivoice.md gains a Native Batching section (server /v1/tasks/batch, per-request seeds, chunk rounds) with RTX 4090 timings; tests/omnivoice/README.md describes omnivoice_batch_test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ggml_flash_attn_ext broadcasts each K/V head over its query-head group, so the perf_mode=flash_attention path no longer materializes the 2x repeated K/V (op_repeat + copies) and the kernel converts half as much K/V data to f16. The standard path is unchanged. Tesla T4, f16 weights, 16 steps: 1 request 1.816 -> 1.600 s; run_batch of 8 mixed-length requests 9.191 -> 7.761 s. Audio bit-identical to the repeated-K/V flash path (18/18 outputs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
omnivoice.fused_projections (default true) loads q/k/v and gate/up as one packed weight each (PackedLinearWeightsBuilder, deferred upload, so no extra weight memory). Each layer runs one GEMM per group, so its shared input is converted to f16 once instead of 3x and 2x, and ggml_swiglu replaces silu + mul. q/k/v are head views of the packed output; the head RMSNorm reads them in place. Tesla T4, f16 weights, 16 steps, GPU kernel time (nsys): - flash_attention, 1 request (with the un-repeated K/V commit): 2024 -> 1770 ms - standard, run_batch of 8 mixed lengths: 12727 -> 12172 ms (f32->f16 conversions 791 -> 544 ms, mul 360 -> 95 ms) Parity: f32 weights, standard path: bit-identical to fused=false (9/9); flash path 8/9 (its K/V go through f16). f16 weights: 12/18 identical, the rest differ by f16 GEMM rounding. fused=false is the previous path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The packed layout viewed every segment's mask from one shared input buffer at offset sum(tokens^2) * element size, which is not aligned for odd row lengths. Vulkan's softmax asserts on a misaligned mask (ggml-vulkan.cpp: get_misalign_bytes(src1) == 0) and aborted. Each segment now has its own [rows, 1, tokens, tokens] mask input, so the backend allocator aligns it; the host keeps one buffer and uploads each segment's range. The unpacked layout is unchanged. Tesla T4: Vulkan Q8 run_batch(8) of mixed lengths no longer aborts and matches packed_cfg=false bit-exactly (9/9). CUDA output is bit-identical to before for standard and flash attention (9/9 each). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Matches the option name Qwen3-TTS, Qwen3-ASR and YuE2 use for the same packed q/k/v and gate/up weights. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reproducing earlier output takes packed_cfg, device_scoring and packed_projections all false; the docs and test README named only the first two. packed_cfg (like device_scoring) is ignored with mem_saver=true, whose layerwise graph always uses the padded layout. Checked on a Tesla T4 (CUDA) against upstream main, two texts, f16 and f32 generator weights, byte-identical WAVs: - all three false vs main: 4/4 - mem_saver=true with packed_projections=false vs main mem_saver: 4/4 Co-Authored-By: Claude Opus 5.5 <[email protected]>
omnivoice_batch_parity_test (ENGINE_BUILD_MODEL_TESTS; registered with
ctest when AUDIOCPP_OMNIVOICE_TEST_MODEL is set) uses f32 generator
weights and five requests of different lengths, seeds, step counts and
guidance scales, one sampled, and exits 1 on any failed check:
- batch_of_one: run_batch({r}) == run(r) bit for bit, every request
- batched_vs_run: run_batch() == run() bit for bit for greedy requests
on CUDA; other backends pick kernels by row count, so there it
requires equal length and finite audio and prints the difference
- batched_repeat: a second run_batch() is identical, sampled included
- device_scoring_off == default, every request
- packed_projections_off == default, greedy requests
Sampled requests are not compared across layouts: different GEMM shapes
change f32 logits in the last bits and sampling can draw another token.
omnivoice_batch_test --compare-dir now exits 1 on a mismatch or a
missing baseline, and is rejected with --mode batch (nothing to compare).
Tesla T4: all checks pass on CUDA (ctest) and on Vulkan (batched_vs_run
max |diff| 0.00016 and 0.032 on two short requests).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
335ffed to
d2e684e
Compare
|
Thanks for the review! I've addressed everything and rebased onto current Vulkan abort (
Docs (
Naming ( Tests (
It exits 1 on any failure, and passes on the T4 with both CUDA and Vulkan. One more note: on Vulkan, batched and solo greedy audio are close but not bit-identical (max |diff| 0.00016 and 0.032 on two short requests), because the kernels differ by row count. The test and docs say so instead of claiming exact parity there. |
|
@kawshikbuet17 Thanks! PR merged! |
Throughput of the C++ runtime vs the Python OmniVoice package (plain, FlashInfer, FlashInfer + CUDA graphs) on one RTX 4090, f16 and bf16. Each variant runs as 1, 2, 3, ... instances (one model per process) at batch size 1, 2, 3, ... until the GPU saturates; one round = all instances start together, each with one call of batch-size sentences. 5 warm-up rounds, then 1 timed round per row. docs/reports/omnivoice_concurrency_benchmark.md: findings, setup, method, saturation point per variant, and every round (1511: 1496 measured, 15 failed with the reason). The same table is in docs/reports/data/omnivoice_concurrency_rtx4090.csv. docs/models/omnivoice.md links the report. Measured on the OmniVoice code merged in 0xShug0#1208. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Throughput of the C++ runtime vs the Python OmniVoice package (plain, FlashInfer, FlashInfer + CUDA graphs) on one RTX 4090, f16 and bf16. Each variant runs as 1, 2, 3, ... instances (one model per process) at batch size 1, 2, 3, ... until the GPU saturates; one round = all instances start together, each with one call of batch-size sentences. 5 warm-up rounds, then 1 timed round per row. docs/reports/omnivoice_concurrency_benchmark.md: findings, setup, method, saturation point per variant, and every round (1511: 1496 measured, 15 failed with the reason). The same table is in docs/reports/data/omnivoice_concurrency_rtx4090.csv. docs/models/omnivoice.md links the report. Measured on the OmniVoice code merged in 0xShug0#1208.
…, f16/bf16) (#1262) * docs: add OmniVoice concurrency benchmark report (RTX 4090) Throughput of the C++ runtime vs the Python OmniVoice package (plain, FlashInfer, FlashInfer + CUDA graphs) on one RTX 4090, f16 and bf16. Each variant runs as 1, 2, 3, ... instances (one model per process) at batch size 1, 2, 3, ... until the GPU saturates; one round = all instances start together, each with one call of batch-size sentences. 5 warm-up rounds, then 1 timed round per row. docs/reports/omnivoice_concurrency_benchmark.md: findings, setup, method, saturation point per variant, and every round (1511: 1496 measured, 15 failed with the reason). The same table is in docs/reports/data/omnivoice_concurrency_rtx4090.csv. docs/models/omnivoice.md links the report. Measured on the OmniVoice code merged in #1208. * docs: remove the OmniVoice concurrency benchmark CSV The full table stays in docs/reports/omnivoice_concurrency_benchmark.md.
Throughput of the C++ runtime vs the Python OmniVoice package (plain, FlashInfer, FlashInfer + CUDA graphs) on one RTX 4090, f16 and bf16. Each variant runs as 1, 2, 3, ... instances (one model per process) at batch size 1, 2, 3, ... until the GPU saturates; one round = all instances start together, each with one call of batch-size sentences. 5 warm-up rounds, then 1 timed round per row. docs/reports/omnivoice_concurrency_benchmark.md: findings, setup, method, saturation point per variant, and every round (1511: 1496 measured, 15 failed with the reason). The same table is in docs/reports/data/omnivoice_concurrency_rtx4090.csv. docs/models/omnivoice.md links the report. Measured on the OmniVoice code merged in 0xShug0#1208.
This PR adds true batched inference to the OmniVoice C++ generator and makes every request about 2x faster on CUDA.
run_batch()runs one generator forward pass per decoding step for all requests together; it never loops overrun(). This makes the server'sPOST /v1/tasks/batchwork for OmniVoice (requiresmode=offline).Results
RTX 4090,
generator_weight_type=f16,audio_tokenizer_weight_type=f16, 16 steps, voice clone (omnivoice_batch_test). These numbers were measured before the last two commits:perf_mode=flash_attentionrun(), 9 wordsrun_batch()of 8, 9 wordsrun(), 5-20 wordsrun_batch()of 8, 5-20 wordsThe "Before" column for
run_batch()is the first batched commit. Without packing, mixed lengths were padded to the longest request.Tesla T4, same settings, total GPU kernel time from nsys, for the last two commits (un-repeated K/V and fused projections). Kernel time is used because the T4 throttles thermally and its wall-clock times drift:
perf_mode=flash_attentionrun_batch()of 8, 5-20 words, standard attentionBatching itself adds only about 8-16% on the 4090, and nothing on the T4. One request already keeps the GPU busy (about 700 token rows per step over 28 layers), so most of the gain comes from making each request cheaper.
Commits
21c4fc31Batched generator forward pass.54dddd37run_batch()for offline sessions (IBatchedOfflineVoiceTaskSession).run(), and chunk k of every request runs in the same batch.7898ce07Packed guidance rows (omnivoice.packed_cfg, defaulttrue).e0f3709eDevice scoring (omnivoice.device_scoring, defaulttrue).class_temperature=0), each step's best token and log-probability are computed on the backend, and only those are read back instead of the full logits.47d32e72Ragged packing.[1, flat_tokens]sequence with every row at its exact length.f17496e2Docs and tests.docs/models/omnivoice.md("Native Batching").tests/omnivoice/omnivoice_batch_test.cpp, which checksrun()x B againstrun_batch(B)for parity and timing.ca4baecaFlashAttention without repeating K/V.ggml_flash_attn_extbroadcasts the 8 K/V heads over the 16 query heads, so the repeat (and its copies) is gone.335ffedeFused projections (omnivoice.fused_projections, defaulttrue).PackedLinearWeightsBuilder, deferred upload, no extra memory).ggml_swiglureplaces separate SiLU and multiply kernels.New options
falsegivesomnivoice.packed_cfgtrueomnivoice.device_scoringtrueomnivoice.fused_projectionstrueAll three are in
model_specs/omnivoice.jsonand the docs. Invalid values are rejected.Correctness
packed_cfg=falseanddevice_scoring=false,run()is bit-identical to the code before this PR, in both standard and memory-saver mode.run_batch()of 1 is identical torun().run()with that seed.device_scoring: picks the same tokens as the host scorer, and audio was bit-identical in the tests.fused_projections:fused_projections=false(9/9).Not in this PR
perf_mode=flash_attentionis not the default. It matches the standard path to rounding (f32 argmax agreement 99.6-99.8%) and is faster, but the docs describe the standard path as the exact-safe default. It is recommended for deployments, especially the T4.class_temperature > 0) still scores on the host.ggml_setare f32-only in the CUDA backend, andmul_matalways outputs f32. The remaining f16<->f32 conversions are about 19% of GPU time on the T4. Removing more of them needs ggml kernel changes.How to test
Build with
-DENGINE_BUILD_WARMBENCH=ON, then:--compare-dir <earlier out/>to compare bit-exactly against a saved run. Usegenerator_weight_type=f32for exact comparisons.--session-option omnivoice.packed_cfg=false --session-option omnivoice.device_scoring=false --session-option omnivoice.fused_projections=false.mode=offlineand send several OmniVoice requests toPOST /v1/tasks/batch; the results come back in request order.