Skip to content

OmniVoice: native batching and faster generation - #1208

Merged
0xShug0 merged 12 commits into
0xShug0:mainfrom
kawshikbuet17:omnivoice
Nov 6, 2026
Merged

0xShug0 merged 12 commits into
0xShug0:mainfrom
kawshikbuet17:omnivoice

Conversation

@kawshikbuet17

Copy link
Copy Markdown
Contributor

This PR adds true batched inference to the OmniVoice C++ generator and makes every request about 2x faster on CUDA.

  • True batching. run_batch() runs one generator forward pass per decoding step for all requests together; it never loops over run(). This makes the server's POST /v1/tasks/batch work for OmniVoice (requires mode=offline).
  • Per-request speed.
    • Guidance rows hold only their target frames.
    • Greedy token scoring runs on the GPU.
    • FlashAttention uses the K/V heads without repeating them.
    • Q/K/V and gate/up are fused projections.

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:

Workload Before Default perf_mode=flash_attention
1 request, 9 words 0.281 s 0.147 s 0.138 s
1 request, 20 words 0.602 s 0.313 s 0.227 s
8 x run(), 9 words 2.228 s 1.180 s 1.096 s
run_batch() of 8, 9 words 1.995 s 0.995 s 0.824 s
8 x run(), 5-20 words 2.822 s 1.569 s 1.362 s
run_batch() of 8, 5-20 words 4.327 s 1.442 s 1.226 s

The "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:

Workload Before After
1 request, 20 words, perf_mode=flash_attention 2.02 s 1.77 s
run_batch() of 8, 5-20 words, standard attention 12.73 s 12.17 s

Batching 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

  1. 21c4fc31 Batched generator forward pass.
    • The graph batch dimension goes from 2 to 2B: conditional rows first, then unconditional rows, with per-row masks, target indices and guidance scales.
    • Each request keeps its own schedule, RNG, scoring and accepted tokens, and may use a different step count.
    • The memory-saver (layerwise) graph is batched the same way.
  2. 54dddd37 run_batch() for offline sessions (IBatchedOfflineVoiceTaskSession).
    • Long texts are split into chunks as in run(), and chunk k of every request runs in the same batch.
    • Reference audio goes through the existing reference-token cache.
  3. 7898ce07 Packed guidance rows (omnivoice.packed_cfg, default true).
    • The unconditional sequence holds only the target frames instead of being padded to the full prompt length.
    • That padding was about 25% of every forward pass.
  4. e0f3709e Device scoring (omnivoice.device_scoring, default true).
    • For greedy decoding (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.
    • Ties go to the lowest index, matching the host scorer.
  5. 47d32e72 Ragged packing.
    • Batched requests are packed into one [1, flat_tokens] sequence with every row at its exact length.
    • Attention runs per segment of equal-length rows; the batch is sorted by length internally, and results keep the request order.
  6. f17496e2 Docs and tests.
    • Model spec options, docs/models/omnivoice.md ("Native Batching").
    • tests/omnivoice/omnivoice_batch_test.cpp, which checks run() x B against run_batch(B) for parity and timing.
  7. ca4baeca FlashAttention without repeating K/V.
    • ggml_flash_attn_ext broadcasts the 8 K/V heads over the 16 query heads, so the repeat (and its copies) is gone.
    • Audio is bit-identical to the previous FlashAttention path (18/18 outputs).
  8. 335ffede Fused projections (omnivoice.fused_projections, default true).
    • Q/K/V and gate/up are loaded as one packed weight each (PackedLinearWeightsBuilder, deferred upload, no extra memory).
    • Each layer runs one GEMM per group, so the shared input is converted to f16 once instead of 3x and 2x, and ggml_swiglu replaces separate SiLU and multiply kernels.

New options

Option Default false gives
omnivoice.packed_cfg true the padded guidance layout
omnivoice.device_scoring true host scoring from full logits
omnivoice.fused_projections true separate projections

All three are in model_specs/omnivoice.json and the docs. Invalid values are rejected.

Correctness

  • Old path still reachable: with packed_cfg=false and device_scoring=false, run() is bit-identical to the code before this PR, in both standard and memory-saver mode.
  • Batch of 1: run_batch() of 1 is identical to run().
  • Batched vs solo:
    • With f32 weights, a request's logits are exactly equal batched or alone, ragged packing included.
    • With f16 weights, batched and solo can round differently, because the batched GEMMs have different shapes. In the 4090 test, 6 of 8 mixed-length requests gave bit-identical audio.
  • Each request keeps its own RNG: a seeded request in a batch follows the same sampling path as run() with that seed.
  • device_scoring: picks the same tokens as the host scorer, and audio was bit-identical in the tests.
  • fused_projections:
    • With f32 weights on the standard path, it is bit-identical to fused_projections=false (9/9).
    • The FlashAttention path matched 8/9, since its K/V go through f16.
    • With f16 weights, 12 of 18 outputs are identical and the rest differ by f16 GEMM rounding.
  • Default output changes at rounding level: default-path output differs from the previous code by floating-point rounding only (checked with f32 weights).

Not in this PR

  • perf_mode=flash_attention is 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.
  • Audio decoding and post-processing still run per request.
  • Sampled decoding (class_temperature > 0) still scores on the host.
  • Activations stay f32 in the ggml graph. RMSNorm, softmax, SwiGLU and ggml_set are f32-only in the CUDA backend, and mul_mat always 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:

build/bin/omnivoice_batch_test \
  --model models/OmniVoice \
  --clone-audio tests/omnivoice/assets/ref_audio_02.wav \
  --reference-text-file tests/omnivoice/assets/ref_text_02.txt \
  --text-file <texts.txt> --num-step 16 --batch-sizes 1,8 \
  --session-option omnivoice.generator_weight_type=f16 \
  --session-option omnivoice.audio_tokenizer_weight_type=f16 \
  --out-dir out/
  • Parity: add --compare-dir <earlier out/> to compare bit-exactly against a saved run. Use generator_weight_type=f32 for exact comparisons.
  • Old path: pass --session-option omnivoice.packed_cfg=false --session-option omnivoice.device_scoring=false --session-option omnivoice.fused_projections=false.
  • Server: start it with mode=offline and send several OmniVoice requests to POST /v1/tasks/batch; the results come back in request order.

@0xShug0

0xShug0 commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

@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 afternoon train is running on time.

The new packed layout creates attention-mask views at unaligned buffer offsets. Vulkan softmax rejects those offsets. Setting omnivoice.packed_cfg=false fixes the reproduction; disabling the other optimizations does not. The fix should stay model-local: allocate aligned segment masks.

Other minor cleanup:

  • Documentation: restoring main now requires all three options false. The older two-option instructions are incomplete. Also document that packed_cfg is ignored with mem_saver=true.
  • Naming: prefer packed_projections over fused_projections, matching Qwen3-TTS, YuE2, and VoxCPM2.
  • Tests: the added benchmark prints parity differences and skips missing baselines without failing. Add asserting model tests for these guarantees.

Update: also please rebase.

kawshikbuet17 and others added 12 commits November 6, 2026 23:15
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]>
@kawshikbuet17

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've addressed everything and rebased onto current main. The branch's earlier NFC and codebook commits were already merged as #1116 and #1129, so they are gone; 12 commits remain.

Vulkan abort (f07b4dc9): reproduced on a Tesla T4 with Vulkan, as the same GGML_ASSERT(!src1 || get_misalign_bytes(ctx, src1) == 0) in softmax.

  • On the T4 (16-byte offset alignment) your single-request CLI case happened to land on an aligned offset. A run_batch() of 8 mixed-length requests hit the assert.
  • Each packed segment now gets its own mask input tensor, which the backend allocator aligns, instead of a view into one shared buffer. The unpacked layout is unchanged.
  • On Vulkan the CLI case and run_batch(8) run, with standard and flash attention. Packed output is bit-identical to packed_cfg=false (9/9).
  • CUDA output is bit-identical before and after the fix.

Docs (c29089e3): restoring earlier output now lists all three options. I checked it against main on CUDA with f16 and f32 weights:

  • All three options false matched main (4/4, byte-identical WAVs).
  • packed_cfg (like device_scoring) is now documented as ignored with mem_saver=true. There, packed_projections=false alone matches main with mem_saver=true (4/4).

Naming (3b922ba8): omnivoice.fused_projections is now omnivoice.packed_projections.

Tests (d2e684e8): omnivoice_batch_parity_test is built with ENGINE_BUILD_MODEL_TESTS and registered with ctest when AUDIOCPP_OMNIVOICE_TEST_MODEL is set. With f32 weights it asserts:

  • run_batch({r}) equals run(r);
  • batched equals solo for greedy requests (bit-exact on CUDA; on other backends it checks length and finiteness and prints the difference);
  • a repeated batch is identical, sampled request included;
  • device_scoring=false and packed_projections=false equal the defaults.

It exits 1 on any failure, and passes on the T4 with both CUDA and Vulkan. omnivoice_batch_test --compare-dir now also fails on a mismatch or a missing baseline.

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.

@0xShug0
0xShug0 merged commit cd1cec3 into 0xShug0:main Nov 6, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 6, 2026

Copy link
Copy Markdown
Owner

@kawshikbuet17 Thanks! PR merged!

kawshikbuet17 added a commit to kawshikbuet17/audio.cpp that referenced this pull request Nov 12, 2026
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]>
kawshikbuet17 added a commit to kawshikbuet17/audio.cpp that referenced this pull request Nov 12, 2026
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.
0xShug0 pushed a commit that referenced this pull request Nov 12, 2026
…, 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.
kawshikbuet17 added a commit to kawshikbuet17/audio.cpp that referenced this pull request Nov 12, 2026
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.
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