Skip to content

omnivoice: run the generator on the vendor zero-op matmul API (rknn_zeroop) - #1297

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
wOvAN:omnivoice-rknn-zeroop
Nov 15, 2026
Merged

0xShug0 merged 3 commits into
0xShug0:mainfrom
wOvAN:omnivoice-rknn-zeroop

Conversation

@wOvAN

@wOvAN wOvAN commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

omnivoice: a generator that runs on the vendor zero-op matmul API (rknn_zeroop)

The RKNN OmniVoice generator today needs a ladder of per-bucket compiled .rknn engines
(omnivoice_generator_seq<N>_fp16.rknn): every new canvas geometry is a PC-side reconvert with
the toolkit, and the engines come from a sidecar artifact set. This PR adds a third generator
impl, rknn_zeroop, that needs no artifacts at all: the 28-layer diffusion-LM trunk runs on the
vendor rknn_matmul_api shipped inside librknnrt.so itself (zero custom operators, no external
kernel library, links nothing beyond the runtime), with the geometry built at runtime.

Select it through the existing exec-plan seam:

--session-option 'omnivoice.exec_plan={"generator":{"impl":"rknn_zeroop"}}'

How it works

  • Same front-shard contract as the compiled front-shard ladder: the NPU runs the trunk, the CFG
    tail (final norm, audio heads, guided combine) stays in the host fp32 graph.
  • GEMMs run as per-(layer, shape) fp16-in/fp32-out rknn_matmul contexts. Weights are packed
    once into the native tiled B layout (M-independent, so all buckets share one pack) and cached
    on disk under <model dir>/rknn-zeroop-cache, overridable with AUDIOCPP_RKNN_ZEROOP_CACHE,
    keyed by a weight-set fingerprint.
  • Attention is tile-assembled on the vendor API (per (batch, head) QK^T tiles), softmax on the
    host in fp32, PV over the full cache width. The dLLM step canvas masks make every target row
    self-only, and for that case the step attention is the exact identity on V (zero NPU work).
  • The vendor zero-op matmul is single-core (core_mask is accepted-then-ignored, so it is never
    set), which sets the perf envelope described below.
  • Additive plumbing: OmniVoiceRknnGenerator's public methods become virtual and gain a
    reset() per-request hook (no-op for the stateless compiled ladder), an empty engine list is
    inert instead of throwing (the zero-op generator registers no compiled ladders), and the two
    engine sources compile on non-aarch64 as a clear-error stub. Per-source
    -march=armv8.2-a+fp16 is scoped to the two files that need it (RK3562/RK3561 parts have no
    FP16 SIMD, so the flags must not be target-wide).

Runtime validation (RK3588, Orange Pi 5 Plus, librknnrt 2.3.2, 2026-11-15)

Board build:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
  -DENGINE_ENABLE_RKNN=ON \
  -DENGINE_RKNN_INCLUDE_DIR=/usr/local/include -DENGINE_RKNN_LIBRARY=/usr/lib/librknnrt.so \
  -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=omnivoice
cmake --build build --parallel 8 --target audiocpp_cli

Board run (32 Russian characters + ElevenLabs-style English reference clip, greedy-free seed,
live guidance 2.0):

./build/bin/audiocpp_cli \
  --task clon --family omnivoice --model models/OmniVoice-GGUF/omnivoice-f16.gguf \
  --backend cpu --threads 4 \
  --text "Сегодня утром на площадке калибровали речевой синтез на плате с нейропроцессором. Вакабор стоял в памяти ускорителя." \
  --voice-ref assets/resources/b.wav \
  --reference-text "Some call me nature. Others call me mother nature. ..." \
  --seed 42 --guidance-scale 2.0 \
  --session-option 'omnivoice.exec_plan={"generator":{"impl":"rknn_zeroop"}}' \
  --out cmp.wav

Parity against the compiled front-shard ladder (ground truth) on the same text/seed/geometry,
with the debug hidden-state dump (AUDIOCPP_RKNN_ZEROOP_DEBUG=1, AUDIOCPP_RKNN_ZEROOP_DUMP=...):

  • Per-layer prefill/step referee SNR vs the compiled engine's own hidden states: 80.6-132.9 dB
    across all 28 layers (fp16 trunk noise floor; the final-step conditional row, which the
    host tail actually consumes, lands at 34.3 dB at step 0 of the twin geometry and decays
    smoothly across steps, no cliff).
  • Output audio is whisper-clean Russian, no artifacts, and the run is deterministic: repeated
    twin runs produce a byte-identical WAV (md5 31eaa272118dd19fad97ac326a72f91d).

Timings (same board, 4 threads on the host tail, warm weight cache):

geometry pack (warm) prefill per step (median)
twin run (seq_pad 896 bucket) 1.11-1.20 s 25.8-26.2 s 8.8-9.1 s
deep run (seq1536, bucket 1664) ~1.1 s 50.1 s 22.9 s

(In each run the first step pays the geometry-context build, 25.8 s / 50.1 s respectively;
medians exclude it, means are 9.3 s and 23.8 s.)
At deep geometry that is parity with the compiled front-shard engine (23.2 s/step measured on the
same board and text). First cold run additionally packs the full trunk (~2 min) and writes the
disk cache.

x86: the tree compiles with -DENGINE_ENABLE_RKNN=ON (the engine layer is an explicit stub that
throws a clear error at open()), and the two stub TUs pass g++ -fsyntax-only -std=c++17 -DENGINE_HAVE_RKNN=1 on x86-64. tools/check_loader_catalog_sync.py passes.

Known limitations

  • aarch64-only engine: ARMv8.2-A FP16 NEON host chain; every other target is the stub.
  • Single-core vendor matmul: at short twin geometry the per-step GEMM work is far from the
    multi-core compiled engines; deep geometry is at parity. The 3-core split (open-source
    rknpu2_matmul library) is a separate, license-encumbered engine and deliberately not here.
  • max_tokens() is 2176: a policy/memory cap, the per-geometry KV caches reserve
    seq_pad rows (~528 MB at 2304 padded rows).
  • No unit tests: the path needs a board. The stub tier keeps every non-board build compiling.

Review round (2026-11-15)

Five issues from review, four real, all fixed on this branch:

  • Constant-pack cache key: the generator now appends a content hash of the weight set
    (FNV-1a-64 over sampled windows of every weight view, ~20 ms) to the schema tag, so a
    checkpoint swap in the same model directory repacks instead of reusing the old pack.
  • Weight-store types: non-F16/F32 stores now throw at construction instead of being
    reinterpreted as floats.
  • Prefill and step masks are now separate buffers (mask_p/mask_s). The previous single merged
    buffer gave target rows in the overlap regime (target block bigger than the prompt canvas,
    target > seq - target) full-row visibility, a semantics neither pass defines. Validated on the
    board across three geometries on the fixed binary:
    • Twin (disjoint: canvas total=704, target=262 < prompt region 442): render byte-identical to
      the pre-fix gate (md5 31eaa272118dd19fad97ac326a72f91d), i.e. the fix is a no-op when the
      regions do not overlap.
    • Deep (overlap: canvas total=1248, target=734 > prompt region 514): the render changes
      (expected - this regime was the bug), transcribes whisper-clean over the full text, and
      re-measures at parity with the compiled engine (32 steps, 25.0 s/step median, 52.7 s
      prefill+first-step geometry build).
    • Short-ref overlap (canvas total=361, target=260 > prompt region 101, 159 overlapped rows):
      whisper-clean over the full text.
  • Engine::~Engine() deletes its Impl (KV caches leaked per session teardown).

wOvAN added 2 commits November 15, 2026 11:14
…eroop)

A third generator impl for omnivoice.exec_plan that needs no compiled
engine artifacts: the 28-layer diffusion-LM trunk runs on the vendor
rknn_matmul_api shipped inside librknnrt.so (zero custom operators,
links nothing beyond the runtime), with the geometry built at runtime
and the weights packed once into the native tiled B layout (disk-cached
under <model dir>/rknn-zeroop-cache). Same front-shard contract as the
compiled front-shard ladder: NPU trunk, host fp32 CFG tail. Attention
is tile-assembled on the vendor API with a host fp32 softmax, and the
self-only dLLM step rows take an exact identity on V.

Additive plumbing: OmniVoiceRknnGenerator's public methods become
virtual and gain a reset() per-request hook (no-op for the stateless
compiled ladder), an empty engine list is inert instead of throwing,
the engine layer compiles as a clear-error stub off aarch64, and the
-march=armv8.2-a+fp16 flags are scoped to the two sources that need
them (RK3562/RK3561-class parts have no FP16 SIMD).

RK3588 (librknnrt 2.3.2): 28-layer referee SNR 80.6-132.9 dB against
the compiled front-shard ground truth, whisper-clean Russian renders,
deterministic output; deep geometry at compiled-ladder parity
(22.9 vs 23.2 s/step, 50.1 s prefill).
… 7.5

Measured per-step medians from the twin and deep board logs (32 steps
each): twin 8.8-9.1 s median with the first step at 25.8 s (geometry
build), deep 22.9 s median with a 50.1 s first step.
@0xShug0

0xShug0 commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@wOvAN Serveral potential issues found by Codex:

  • The caller passes the constant "omnivoice-zeroop-v1" as the cache fingerprint. Cache loading checks file sizes, not weight identity. Replacing a checkpoint in the same directory can silently reuse the previous weights.

  • Conversion distinguishes only F16 versus “everything else”. Supported BF16/Q8 packages can therefore produce invalid values and out-of-bounds reads. Convert through the framework or explicitly reject unsupported types.

  • Prefix caching changes the computation. Conditional prefix rows attend to the changing target during prefill, but their later-layer KV states are frozen across subsequent steps. With this bidirectional mask, those states are not constant. This needs correctness validation against full recomputation.

  • Unconditional mask regions overlap. When target length exceeds prefix length, the local-position and canvas-position writes overlap and merge their visible columns. For example, seq=896, target=512 gives some rows 896 visible columns instead of 512 during prefill. Build separate prefill/step masks.

  • Engine destruction leaks host memory. im_ is allocated with new, but the destructor only calls close() and never deletes it. Its KV caches and scratch vectors consequently survive session destruction.

Could you double check them?

Four review findings, all real:

- The constant-pack cache key took only the schema tag and warm-load checked
  file sizes, so a checkpoint swapped into the same model directory silently
  reused the previous pack. The generator now appends a content hash of the
  weight set (FNV-1a-64 over sampled windows of every weight view, ~20 ms) to
  the tag, so the cache key pins the weight content, not just its shape.

- is_f16 treated every non-F16 store as fp32, so a custom Q8_0/BF16 GGUF would
  be reinterpreted as floats (garbage + OOB reads). The views loop throws for
  any store outside {F16, F32} at construction.

- One shared mask buffer carried the prefill b1 convention (canvas-target rows
  [seq-tgt, seq) over [seq-tgt, seq)) and the step b1 convention (block-local
  rows [0, tgt) over [0, tgt)), merged by fills. In the overlap regime (target
  block bigger than the prompt canvas) the two fill regions intersect, and the
  merged rows got full-row visibility - a third semantics neither pass defines.
  Prefill and step now build and pass separate masks (mask_p / mask_s).

- ~Engine() called close() but never deleted Impl, so every session teardown
  leaked the per-layer KV caches and all scratch vectors. It now deletes im_.

Board-validated (RK3588): twin geometry (regions disjoint) render byte-identical
to the pre-fix gate; deep and short-ref overlap geometries render whisper-clean
Russian over the full text.

Co-Authored-By: Claude <[email protected]>
Performed-by: Claude-Fable-5
@wOvAN

wOvAN commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Checked all five, four were real, all fixed in 53e43bf:

  1. Cache fingerprint. Confirmed: open() took the constant schema tag and warm-load checked
    only file sizes, so replacing a checkpoint in the same model directory silently reused the
    previous pack. The generator now appends a content hash to the tag: FNV-1a-64 over every weight
    view, sampling 1 KiB every 64 KiB (~19 MB of the ~1.1 GiB set, ~20 ms), so the cache key pins
    the weight set, not just its shape. Old caches (keyed ovz_omnivoice-zeroop-v1.*) are simply
    not found and repack on the first run.

  2. F16 vs "everything else". Confirmed as a latent hazard: the store is F16/F32 for every
    shipped OmniVoice package (safetensors load path), so no shipping model hits it, but a custom
    Q8_0/BF16 GGUF would have been reinterpreted as floats (garbage + OOB reads). The views loop
    in generator.cpp now throws the vendor engine converts only F16/F32 weight stores, got <type> for anything else, at construction.

  3. Prefix caching vs full recomputation. By design, and its size is measured, not assumed:
    the compiled ground-truth ladder recomputes the whole canvas every step, and the twin gate IS
    the A/B against it - per-layer step/prefill referee SNR 80.6-132.9 dB over all 28 layers, the
    twin-geometry trajectory decays smoothly across the 32 steps with no cliff, and the renders
    transcribe whisper-clean at both twin and deep geometry. Freezing the prefix KV across steps
    is the same approximation the semi-autoregressive dLLM serving convention makes.

  4. Uncond mask overlap. Confirmed, the worst of the five: one shared mask buffer carried the
    prefill convention (b1 canvas-target rows [seq-tgt, seq) see [seq-tgt, seq)) and the step
    convention (b1 block-local rows [0, tgt) see [0, tgt)), and merged them with fills, so in
    the overlap regime (tgt > seq - tgt) those rows got the union = full-row visibility, a third
    semantics neither convention defines. Prefill and step now build and pass separate masks
    (mask_p/mask_s). Re-validated on the board on the fixed binary across three geometries:
    the twin gate (total=704, target=262 < prompt region 442, disjoint) renders byte-identical to
    the pre-fix gate (md5 31eaa272...), i.e. provably a no-op there; and two real overlap
    geometries now have their own gates: the deep run (total=1248, target=734 > prompt 514) and a
    short-ref run (total=361, target=260 > prompt 101, 159 overlapped rows) - both render
    whisper-clean Russian over the full text, deep at step parity (25.0 s/step median).

  5. Engine destructor leak. Confirmed: im_ = new Impl() and ~Engine() { close(); } freed
    nothing, so every session teardown leaked the per-layer KV caches (hundreds of MB at deep
    geometries) and all scratch vectors. The destructor now deletes im_.

The PR description gained a "Review round" section with the new board numbers.

@0xShug0
0xShug0 merged commit 89bccbe into 0xShug0:main Nov 15, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

@wOvAN Thanks! PR merged!

A follow-up PR could check the disk caching and make sure it works as expected, including on a fresh installation where the cache directory doesn’t exist yet. Disk caching is easy to get wrong, especially cache invalidation and handling failed writes. There are two relevant PRs, but neither has been merged yet.

@wOvAN
wOvAN deleted the omnivoice-rknn-zeroop 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