Skip to content

omnivoice: front-shard RKNN ladder so guidance works on the NPU - #1261

Merged
0xShug0 merged 12 commits into
0xShug0:mainfrom
wOvAN:omnivoice-rknn-generator
Nov 12, 2026
Merged

0xShug0 merged 12 commits into
0xShug0:mainfrom
wOvAN:omnivoice-rknn-generator

Conversation

@wOvAN

@wOvAN wOvAN commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Makes classifier-free guidance work on the RK3588 NPU for the omnivoice generator sidecar (#1259, merged), by adding a second engine contract: the front-shard ladder.

The shipped step-graph ladder is validated at --guidance-scale 0.0 only. Its in-graph fp16 audio heads put the unconditional logits at 26.9 dB SNR against the fp32 reference, and the CFG gain doubles that noise past the diffusion-LM decoding knife-edge, so a guidance-2.0 rollout leaves the speech basin. Depth probes on the PC simulator with the real board step-0 feed show the 28-layer fp16 backbone is not the noise source (the unconditional hidden state sits at 67 dB at every depth probed, k=7/14/21/28): the whole 26.9 dB comes from the in-graph fp16 heads.

So the tail moves out of the engine:

  • Producer: prepare_omnivoice_rknn_generator.py --front-k 28 exports/compiles a shard engine that runs the embedding mix and all 28 backbone layers and returns the raw hidden state [2, S, hidden] (five inputs, no guidance input). The padding gate and the simulator verify run front-k-aware; the simulator feed now declares data_format='nchw' so the converter's seq-length-dependent NHWC labeling of the 4-D attention input cannot bite.
  • Sidecar (rknn_generator.{h,cpp}): the contract is name-detected at registration (front<k> in the producer's file name) and attribute-validated at load; run() feeds the five shard inputs and crops the hidden rows into the packed host row layout.
  • Generator (generator.cpp): Qwen3DiffusionForwardGraph gains a front-shard mode where one hidden graph input replaces the token/mask/position inputs and the existing fp32 build_guided_logits (final RMS norm, 8 audio heads, guidance combine, optional device scoring) consumes it. Front-shard requests run at batch 1 (the packed CFG-pair engine pass writes the batch-1 host row layout); batched shard requests fall back to the ggml graph.
  • model_specs/omnivoice.json gains the omnivoice_generator_front_rk3588 package (front28 seq256/384/512/768/1024), docs updated.

Why it is the right split

At step 0 the hybrid (fp16 shard engine on the simulator, fp32 tail on the host) reproduces the torch fp32 guided logits at 84.3 dB output SNR with 99.4% argmax agreement, 16x under the knife-edge, while the full fp16 engine sits at 0.6-0.9 logit-rms perturbation (noise).

Runtime validation (RK3588 board, Orange Pi 5 Plus)

Engines compiled on x86_64 with SDK 2.3.2 (--front-k 28, all five --seq-len rungs); padding gate 392-401 dB padded-vs-exact at fp32.

Gate (the same request as the #1259 gate: 132-char Russian baseline text, b.wav reference + its English reference text, seed 42, --threads 4):

./build/bin/audiocpp_cli --task clon --family omnivoice \
  --model /root/audio.cpp/models/OmniVoice-GGUF --backend cpu --threads 4 \
  --text "<baseline text>" --voice-ref .../b.wav --reference-text "<EN ref>" \
  --seed 42 --guidance-scale 2.0 \
  --session-option 'omnivoice.exec_plan={"generator":{"impl":"rknn","artifacts":{"main":"omnivoice_generator_front28_seq768_fp16.rknn"}}}' \
  --out ov-npu768g2.wav

Result: clean at guidance 2.0, whisper-parity with the ggml baseline render (faster-whisper small, ru, beam 5: identical transcriptions, the same two whisper mishears on both files). 8.3-8.5 s/step on the NPU plus about 0.4 s/step of fp32 CPU tail, wall 286 s, against 293 s for the full engine at guidance 0 and 883 s for the ggml graph at the same length.

All five rungs are board-gated at guidance 2.0 (seed 7). The gate length accounts the reference audio: the 14 s b.wav reference costs about 393 prompt tokens on its own, so the short rungs use the 5.95 s a.wav reference, and requests above a rung's capacity fall back whole to the ggml graph (omnivoice.generator.rknn.fallback_tokens in the trace log, exercised by the 775-token baseline on seq768 and back on seq1024). Per-step engine time scales with the rung (1.5 s at seq256, 2.4 at 384, 3.4 at 512, 8.4 at 768, 12.2 at 1024) and resident aperture runs 1665 MiB (seq256) to 3644 MiB (seq1024) inside the 3900 MiB budget. A second control text renders whisper-clean on the seq768 shard at guidance 2.0.

PC side: full build (AUDIOCPP_MODEL_SET=custom, omnivoice) + ctest: 68/68 pass; loader/catalog gate green. Sidecar unit test extended with a front-shard fake-engine case (compiles in RKNN-enabled builds; board run comes with the engines). This PR also corrects the #1259 verified note: the ggml twin's guidance term is alive (its own step-0 cond-minus-uncond reads -8.3 dB SNR with 0.2% argmax agreement at q8_0 and fp32 alike); the fp16 engine's uncond branch is the outlier.

Known limits

  • Front-shard is batch 1 (documented; batched shard requests fall back to the ggml graph with a trace line).
  • Deep rungs probed and dropped: seq1536 is simulator-clean (55.8 dB hidden SNR, 100% step-0 argmax) and completes 32 board steps at rc=0, yet renders non-speech on the NPU (fp16 attention accumulation collapses at spans the fp32 simulator survives); seq2048 fails rknn_run task submission on driver 0.9.8 (8377 tasks), and preloading the parked 2.5.0 userspace to work around it panics the kernel. The ladder caps at seq1024; longer requests fall back to the ggml graph.
  • Engines (omnivoice_generator_front28_seq{256,384,512,768,1024}_fp16.rknn, 1.21-1.26 GiB) upload to wOvANAI/rknn-tts-engines under rk3588/omnivoice/ alongside the full ladder; the spec package names them and the repo SHA256SUMS pins all ten engine hashes.

wOvAN added 4 commits November 12, 2026 01:08
The shipped step-graph ladder is validated at guidance 0 only: its in-graph
fp16 audio heads put the unconditional logits at 26.9 dB SNR, and the CFG
gain doubles that noise past the diffusion-LM decoding knife-edge, so a
guidance-2.0 rollout leaves the speech basin. Depth probes on the PC
simulator with the real board step-0 feed show the 28-layer fp16 backbone
is not the noise source (the uncond hidden state sits at 67 dB at every
depth probed): the whole 26.9 dB comes from the in-graph fp16 heads.

So move the tail out of the engine. The producer's new --front-k 28 export
compiles a shard engine that runs the embedding mix and all 28 backbone
layers and returns the raw hidden state; the sidecar detects the contract
from the file name (front<k>), validates it at load, feeds the five shard
inputs and crops hidden rows in the packed host layout. On the generator
side Qwen3DiffusionForwardGraph gains a front-shard mode: one hidden
graph input replaces the token/mask/position inputs and the existing
fp32 build_guided_logits (final RMS norm, 8 audio heads, guidance
combine, optional device scoring) consumes it. At step 0 this hybrid
returns the guided logits at 84.3 dB SNR with 99.4% argmax agreement,
16x under the knife-edge.

Board gate (RK3588, seq768 front engine, baseline text, b.wav reference,
seed 42, threads 4, --guidance-scale 2.0, faster-whisper small ru beam 5):
clean, whisper-identical to the ggml baseline render, at 8.3-8.5 s/step on
the NPU plus about 0.4 s/step of fp32 CPU tail (wall 286 s, against 293 s
for the full engine at guidance 0 and 883 s for the ggml graph). Front
shard runs at batch 1 (the packed CFG-pair engine pass writes the batch-1
host row layout); batched shard requests fall back to the ggml graph.

Also: verify_fp16/check_padding front-k plumbing (the front exports carry
five inputs, and the simulator's data_format now declares the fed layout
so the seq-length-dependent NHWC labeling cannot bite), the simulator feed
uses data_format='nchw' for the same reason, and model_specs gains the
omnivoice_generator_front_rk3588 package for the two front rungs.
The 0.9 logit-rms cond/uncond reading came from a board dump comparison that
does not reproduce: dumping the ggml graph's own conditional and unconditional
target slices at step 0 of the same request (text, reference, seed) reads
-8.3 dB SNR with 0.2% argmax agreement at q8_0 and fp32 weight precision
alike. The ggml guidance term is alive; the fp16 engine's uncond branch, at
26.9 dB against the fp32 reference, is the outlier the front-shard split
fixes. The g=-1-vs-0/1/2 render observation stands.
The producer supports any --seq-len; the shipped package only carried seq256/768.
Compile and publish seq384/512/1024 front-28 rungs so bucket selection covers
intermediate and long requests on the NPU path instead of falling back to ggml
above 768 tokens.
seq256/384/512/1024 front rungs validated at guidance 2.0 on the board
(short rungs with the short a.wav reference; the 14 s b.wav reference costs
~393 prompt tokens on its own). Document the reference-length interaction.
@wOvAN

wOvAN commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Follow-up landed: the front-shard package now ships all five rungs (seq256/384/512/768/1024), each board-gated at guidance 2.0 (seed 7) - short rungs with the 5.95 s a.wav reference, since the 14 s b.wav reference alone costs about 393 prompt tokens. Engines are on wOvANAI/rknn-tts-engines with all ten OmniVoice hashes pinned in SHA256SUMS; per-rung step times 1.5/2.4/3.4/8.4/12.2 s and apertures 1665-3644 MiB are in the PR body, plus a streaming gate (TTFB 85.7 s vs 125.8 s ggml twin, whisper-identical). Ready for review.

Streaming runs the shard path unchanged (batch 1 per chunk): baseline text at
60-char chunks over the short reference, TTFB 85.7 s / wall 223.8 s on the NPU
against 125.8 s / 338.0 s on the ggml twin, whisper-identical renders.
@wOvAN
wOvAN force-pushed the omnivoice-rknn-generator branch from 9e78f0d to 4bd79d4 Compare November 11, 2026 22:50
@0xShug0

0xShug0 commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@wOvAN One potential issue remains when reusing a session: RKNN stays enabled, but requests exceeding the engine’s capacity fall back to GGML. A later shorter request switches back to RKNN. The code detects this change but rebuilds the existing graph without changing its type.

For example, the long request creates a full GGML graph. The shorter request rebuilds that same graph, then calls set_hidden() with the RKNN output. Since the full graph has no hidden-state input, this throws.

(This is based on static code analysis.)

wOvAN added 7 commits November 12, 2026 04:57
Deep text (>1024 tokens) is where the NPU path pays most against the ggml
fallback; the board has the RAM headroom (32 GB), the gate re-prices the
aperture via AUDIOCPP_RKNN_APERTURE_MIB.
seq1536 compiled and runs clean in the PC simulator (55.8 dB hidden SNR,
100% argmax) and completes 32 board steps at rc=0, but the render is
non-speech (whisper tags it as music): the NPU's fp16 attention
accumulation collapses at the 1536 span where the simulator's fp32
accumulation does not. seq2048 cannot run at all: rknn_run submission
fails on driver 0.9.8 with 8377 tasks, and preloading the 2.5.0 runtime
to work around it panics the kernel. Requests above 1024 tokens stay on
the ggml graph.
…seq2048 cannot run)

seq1536 is simulator-clean (55.8 dB, 100% argmax) and completes 32 board steps
at rc=0, yet renders non-speech: fp16 attention accumulation on the NPU
collapses at spans the simulator survives. seq2048 fails rknn_run task
submission on driver 0.9.8 (8377 tasks), and preloading the parked 2.5.0
runtime to work around it panics the kernel. Ladder cap is seq1024; beyond it
requests fall back to the ggml graph.
w8a8 layer-method on the seq768 front shard measured 2 dB hidden SNR at
21-69% argmax agreement (fp16: 67 dB / 99.4%), w8a16 is refused on rk3588,
auto_hybrid needs unsupported expand-batch. seq2048's 4116 MiB resident
aperture is past the ~4 GB single-mapping IOVA ceiling already documented.
Note that the OmniVoice generator inherits the shared 3-core mask default.
seq768 at guidance 2.0: 32 steps 464.5 s wall, 24 steps 344.1 s
(whisper-identical), 16 steps 254.5 s (one-word whisper drift).
Engine time is linear in the step count at ~11.25 s/step on this rung.
The converter's channel method lands at 2.2/-0.0/1.5 dB hidden SNR, the
same death as the layer method, so int8 by converter is closed on both
granularities.
…itch

A reused session that ran a fallback (ggml full) request first and a
front-shard request second called rebuild() on the existing graph, which
keeps the type: the shard path then fed hidden rows to a full graph with
no hidden-state input and threw. Type changes now construct a fresh
graph; rebuild() stays a same-type shape change.

Board-validated on the front-28 seq768 engine (server, one session,
guidance 2.0, 2 steps): ggml-full -> shard -> ggml-full all 200 with
byte-identical renders for the two identical full-graph requests.
@wOvAN

wOvAN commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed and fixed in 32da510. The type change was detected but routed through rebuild(), which keeps the graph type, so the shard path fed hidden rows into a full graph with no hidden-state input and threw; the reverse switch left token-id inputs missing on the shard tail. Type changes now construct a fresh graph, rebuild() stays a same-type shape change.

Board-validated on the front-28 seq768 engine (audiocpp_server, one reused session, guidance 2.0, seed fixed, 2 steps): long request (1010 tokens, above the rung, falls back to the ggml graph) -> short request (712 tokens, NPU shard, rknn.step_ms x2 in the trace, fallback_tokens absent) -> the same long request again. All three returned 200 with non-empty audio, the two long renders are byte-identical, and the long -> short -> long trace shows exactly two fallback_tokens lines and two shard steps, no set_hidden throw.

@0xShug0
0xShug0 merged commit 0d6ebbc into 0xShug0:main Nov 12, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@wOvAN Thanks! PR merged.

@wOvAN
wOvAN deleted the omnivoice-rknn-generator branch November 15, 2026 20:29
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