Repository navigation
Add an opt-in RKNN iSTFTNet generator sidecar for kokoro_tts - #904
Merged
Merged
Conversation
The kokoro_tts generator is 83% of the runtime on an RK3588 (RTF 1.41 for a 14.85 s utterance), and the stages are already graph-isolated, so the same per-stage seam used for qwen3_tts and piper_tts applies: with ENGINE_ENABLE_RKNN and the session option kokoro_tts.rknn_generator the generator stage is voiced by a pre-compiled .rknn through librknnrt instead of ggml, and the ggml generator graph is never prepared. The seam is the generator alone - x [1,512,W], the harmonic conditioning har [1,22,60W+1], the style vector and the frame mask at the two rates the graph normalizes at, in and out as spec_phase [1,22,60W+1]. Source-signal synthesis, the forward STFT and the iSTFT head stay on CPU, and the windows are stitched in the spectrogram domain (one global iSTFT over the stitched spectrogram), so there is no waveform crossfade and no depop search. tools/prepare_kokoro_tts_rknn_generator.py re-traces the generator the GGUF weights describe (decoder.module.generator.* in kokoro-v1_0.pth) at one fixed window, checks it against the runtime, and compiles it. Three graph rewrites are compiled in, all of them the reference Kokoro RKNN port's, and each is there for a measured reason: - Weight-norm folded at load. Left in the graph, vector_norm traces to 51 ReduceL2 nodes and rknn.build aborts. - Masked instance norm through GlobalAveragePool. A ReduceSum over the time axis lowers to a register field capped at 8191. The mask has to zero the padding at every stage boundary (after the upsampling reflect-pad, on the resblock sum, on the noise branch), not only inside AdaIN's statistics: a conv after a masked AdaIN writes real-frame sums into the pad, and the next conv_transpose reads them where a full decode reads implicit zeros. - Snake's sin to a clipped minimax odd polynomial (degree 5), and its 1/alpha folded into the following convolution. librknnrt has no NPU Sin: the 48 sine nodes of a 128-frame window ran on CPU and were 41% of the window's time (350 ms of 846 ms, RKNN_LOG_LEVEL=5 operator ranking). Degree 5, 7 and 9 measure the same 30.4 dB against the exact sine, so the clip saturation past pi dominates and the cheap fit wins. The alpha-fold is exact algebra and removes one multiply and one divide per Snake; elementwise ops are 84% of this graph's NPU time and the convolutions 15%. The window width is capped by the NPU, not by the model: the longest axis in the graph, the fine rate 60W+1, has to stay under the 13-bit register field. At W=512 the compiler emits ~800k "REGTASK: The bit width of field value exceeds the limit, ... limit: 0x1fff, value: 0x7800" lines and the engine voices clipped noise (rms 32764 of 32767, SNR -27 dB against the CPU decode). 128 is the widest power of two inside the limit, and it emits 128-2*28 = 72 latent frames per step, where 28 is the measured receptive field. Runtime validation, Orange Pi 5 Plus (RK3588), librknnrt 2.3.2, native gcc build with -DENGINE_ENABLE_RKNN=ON -DENGINE_RKNN_INCLUDE_DIR=/usr/local/include -DENGINE_RKNN_LIBRARY=/usr/lib/librknnrt.so, model models/Kokoro-82M-GGUF/kokoro-82m-q8_0.gguf, 185 Russian characters, seed 1234, --threads 4 (14.85 s of audio, 1188 latent frames, 17 windows): path RTF peak RSS generator ms ggml generator 1.415 2777 MB 17748 RKNN generator (w128) 0.867 2334 MB 9609 1.63x wall, 1.85x on the generator (14.9 -> 8.1 ms per latent frame processed), -16% RSS, NPU load Core0 95% / Core1 18% / Core2 19%. The generator-side gain is smaller than the 5.1x measured in the reference engine because this window carries 28+28 frames of context for 72 emitted frames (1.78x of the compute is context, and 28 is the exact receptive field, so it cannot shrink) and because the register limit forces 17 windows. Producer gates, on a decode dumped out of this runtime (AUDIOCPP_KOKORO_DECODER_DUMP): the re-traced module reproduces the runtime's own generator at 60.5 dB interior SNR (the floor is the q8_0 style affine), a padded 128-frame window reproduces the same frames decoded unpadded at 135.1 dB, and the exported ONNX reproduces the torch graph it was traced from at 124.6 dB - measured with the torch reference evaluated in the same sine form, so the gate measures the export and not the approximation. Quality, ggml-vs-RKNN output SNR 0.49 dB, and that number has to be read against what it compares. The generator normalizes per window (AdaIN), so a multi-window decode is a different valid synthesis and not an approximation of the full-length one: dropping 2 of 486 latent frames from the statistics moves the generator output by 25% RMS. The shipping reference Kokoro engine, with the same per-window normalization at T_fix=50, measures 17.11 dB against its own CPU decode on a 7.1 s utterance (2 windows); the gap between its 17 dB and our 0.5 dB is window count, not stitching. Utterances of 72 latent frames or fewer (about 0.9 s) fit one window and are exact. Also in this commit: - kokoro_tts asks for RKNN_NPU_CORE_0_1_2 and falls back to AUTO, as piper_tts does. One context per sidecar: running the windows concurrently on three rknn_dup_context contexts, which is what the reference engine does, measured 1.15x on the window loop (9650 -> 8375 ms) with corrupted output (-7 dB SNR, rms 2x the reference) - duplicated contexts share the runtime's tensor staging, and this engine streams ~75 MB of weights per window, so windows are DRAM-bound, not scheduler-bound. - kokoro_tts accepts the rknn_generator session option by name as well as through the spec, because a published GGUF package embeds an older spec (piper_tts does the same). - The generator I/O dump harness, which is what the producer's parity gate reads. Two knobs on the window walk, both off by default (with them unset the render is byte-identical to the shipping stitch, md5 1f4926e4...), measured on the same utterance against the artifact the ear hears - per-window loudness pumping (0.9 s window rms against the CPU render, spread 7.23 dB, seams clean): walk windows SNR max|d| spread RTF RSS stitch (shipping) 17 0.46 20777 7.23 1.16 2340 overlap 36 32 0.84 20715 7.14 1.79 2340 gain 17 -0.08 25988 3.27 2.24 2884 overlap 36 + gain 32 0.38 25942 3.05 3.03 2884 kokoro_tts.rknn_generator_overlap advances the walk by emitted-overlap and blends the shared spectrogram columns with a raised-cosine ramp; kokoro_tts.rknn_generator_gain keeps the ggml generator graph prepared, renders one full-length CPU decode per utterance, and gives each window's log-magnitude rows the log-loudness ratio against it. The pumping is a loudness effect, not a seam effect: overlap alone does not move the metric, the loudness correction halves it for 1.9x wall.
(cherry picked from commit 9cb1c82)
…t the same cost The shipped range reduction folds the Snake argument by 2*pi and fits sin on [-pi,pi]. Snake consumes sin(alpha*x)^2, which is pi-periodic, so the fold period can be pi: k = Floor(x/pi + 0.5); xr = x - k*pi, with the minimax fit of sin on [-pi/2, pi/2]. Same 10 elementwise ops per sine, same 74.7 MB engine, and the fit gets half the interval: the exported graph measures 93.2 dB against the exact sine (the 2*pi fold: 50.0 dB at the generator output, the clipped form 30.4), and the export-vs-torch gate moves 124.6 -> 124.3 dB, i.e. the reference and the rewrite are still the same function. The torch reference form has to fit on the same domain as the ONNX rewrite, so the export gate's coefficient call now derives the clip from the reduction mode. Measured on RK3588 (integration build, 6.37 s RU, --threads 4, engines from one producer revision interleaved 3x): RTF median 0.867 clipped, 1.079 2*pi-fold, 1.046 pi-fold - the fold's cost is the Floor chain, not its algebra. The build log names the mechanism: the 2.3.2 compiler lowers every rounding op off the NPU (`Floor FLOAT16 CPU` at all 48 sine sites of a folded engine, `Clip FLOAT16 NPU` at all 48 of the clipped one, 58 CPU-lowered ops against 10), so each fold site is a full-tensor NPU->CPU->NPU round trip. Renders are audibly distinct: clipped-vs-2*pi 17.28 dB, clipped-vs-pi 16.95, 2*pi-vs-pi 28.48 dB (max|d| 8020/6922/1936 of 32767). RK3566 re-export: 61,281,856 bytes, 352 REGTASK lines, same gates.
…not the window walk A listening pass found 3 clicks on the 33.58 s render and 2 on the 14.88 s English one. They are content-locked, not grid-locked (moving the window walk with rknn_generator_overlap=36 reproduces them at the identical samples; all three sine forms put them at the same samples), and engine-only (the CPU render of the same text and seed has no jump there, and a 30 ms window at those positions carries 2.5-5x the CPU render's 9-12 kHz energy). Not the fp16 range and not the iSTFT head: the dumped generator output of the NPU render has log-magnitude rows in [-58.8, +3.35] (CPU [-115, +3.03]), and clamping the exponent at 4.0 in the head leaves every render byte-identical. The engine raises its own upper mel bins at those columns (row 6 +3.31 against +1.74, the Nyquist bin +0.50 against -0.93) at the window-relative fine columns where the graph's largest activations peak, and the same graph is clean there in fp32 onnxruntime and in the PC simulator of the same compiled engine, so the excess is the RK3588 DPU's own fp16 accumulation at the activation peaks.
…t paths Both paths existed to measure the sidecar, not to serve a request, and both changed behaviour outside the sidecar: the dump path wrote files under an environment variable from inside the shared decoder, and the statistics path added graph inputs and outputs to the generator graph, extra forward-expanded nodes, and a runtime hook in the shared runtime. Removed: AUDIOCPP_KOKORO_DECODER_DUMP and its writer in src/models/kokoro_tts/ decoder.cpp; the stats-capture parameter, the per-site (mean, biased variance) graph outputs and their readout in the generator graph session; the sidecar's stats_in/use_global/stats_out contract, which is now the 5-input/1-output shipping contract (a 7-input engine is rejected by the name and count check); --global-stats and --dump-dir in tools/prepare_kokoro_tts_rknn_generator.py, keeping the torch-module gate and the padded-window exactness gate. Restored: upload_time_masks guards mask.norm for null again, as upstream does, now that no graph in the tree registers those inputs. The findings stay in the docs: the statistics path is fp32-exact (9.7 -> 135.4 dB) and unusable on a board (every window after the first renders as a constant-energy tone, 1.8x wall, +1.5 GB RSS), which is why it is not shipped. Verified on an Orange Pi 5 Plus (RK3588), gcc 15.2, librknnrt 2.3.2, engine gen_w128.rknn, af_heart, seed 1234, --text-chunk-size 120: the stripped build renders byte-identical to the pre-strip build (md5 3515c8a25eba36ea525f091fdb054b90), and both the RKNN-on and RKNN-off targets build clean.
…rator sidecar Moved to framework/rknn: the engine-image reader (read_engine), the rknn_init plus RKNN_NPU_CORE_0_1_2-then-AUTO core-mask block with the AUDIOCPP_RKNN_CORE_MASK override (Engine::load; the two core-mask return-code timing keys went with the block, the measured core-split numbers stayed as a comment), the IN_OUT_NUM query and the per-index INPUT_ATTR/OUTPUT_ATTR loops (cached input_count/output_count/input_attr/output_attr), the inputs_set/run/outputs_get/outputs_release step sequence (one Engine::run), and rknn_destroy plus the status-string formatter (Engine's destructor and engine::rknn::status). Stayed model-local: the 5-input/1-output contract and its name check (x/har/style/mask_mid/mask_out; a 7-input engine is rejected by the count check naming tools/prepare_kokoro_tts_rknn_generator.py), the W=128 latent-frame window walk (emitted = W - 2*padding, the 60W+1 fine-rate iSTFT geometry), the overlap and gain knobs, the seam stitching, the timing-log keys, and every model-specific error message. Inputs keep pass_through = 0 with size = n_elems * sizeof(float), not attr.size, and the sidecar keeps its single rknn_context (no dup_context). Co-Authored-By: Claude <[email protected]>
…n the gain path The RKNN render carries 2-3 content-locked near-Nyquist clicks per 26 s render: at the columns where the graph's activations peak, the top iSTFT bins run 10-24x the full-length CPU decode's 9-12 kHz energy there. They are fp16 rounding in the convolutional accumulation. Measured invariant to every export-time lever that exists: the clip sine, the range-reduced sine (--sin-reduce), the exact Sin node, the unfolded Snake (--no-snake-fold, which bounds the convolution input), and the w128/w136 grids all leave the same columns at the same magnitude. RKNN 2.3.2 has no per-layer dtype knob, and moving the peak convolutions to the CPU gives up the sidecar (the convolutions are 15% of the window's time, the elementwise chain 84%). What does remove them is to cap the top five log-magnitude rows at the reference level at every column, which needs the full-length CPU decode the gain knob already runs. Orange Pi 5 Plus (RK3588), gen_reduce5_w128.rknn, af_heart, seed 1234, 25.9 s render, per-column 9-12 kHz energy ratio against the CPU render (top 8 columns) and full-render SNR against it: | path | top-8 ratios | SNR | wall | peak RSS | |---|---|---|---|---| | shipping (no gain) | 23.3 .. 10.6x | 0.62 dB | 29.7 s | 2792 MB | | gain, no cap | 14.7 .. 6.5x | 0.08 dB | - | - | | gain + cap | 2.8 .. 1.4x | 0.13 dB | 56.6 s | 3393 MB | The residual 1.4-2.8x is the iSTFT Hann-overlap smear: PCM at 9-12 kHz draws on spectrogram bins beyond the five the cap touches. SNR is dominated by the per-window-vs-full-length normalization gap (~0 dB for every w128 engine), not by the clicks, so it does not move. Without kokoro_tts.rknn_generator_gain there is no reference and the block is a no-op: the shipping render is byte-identical (md5 3515c8a2...).
Contributor
Author
Owner
|
@wOvAN All merged! I can't really test them myself, so I only checked that the changes were well-scoped. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an opt-in RKNN iSTFTNet generator sidecar for kokoro_tts
Branch:
rknn-kokoro-rknn(kokoro files from therknn-speech-decoderwork). Depends on theENGINE_ENABLE_RKNNCMake plumbing introduced by the qwen3_tts sidecar PR.What this is
kokoro_ttson an RK3588 is generator-bound: the iSTFTNet generator is 83% of the runtime, andggml has no RKNN backend. This adds no backend and no scheduler: a model-local module voices one
graph-isolated stage — the generator (latents → mel, with the iSTFT head) — through
librknnrt,behind
ENGINE_ENABLE_RKNN=OFF(default off) plus one session option,kokoro_tts.rknn_generator.The generator normalizes per window (AdaIN), so a fixed window is a legitimate unit of work rather
than an approximation of a longer graph: the engine is compiled for 128 latent frames and the
runtime walks it over the latent (1188 frames = 17 windows for a 14.85 s utterance).
tools/prepare_kokoro_tts_rknn_generator.pyre-traces the generator from the GGUF the runtimeloads, checks the re-traced module against the runtime's own generator, and compiles the engine.
Build and run (as tested)
Board: Orange Pi 5 Plus, RK3588, 8 cores, librknnrt 2.3.2, native gcc 15.2.
Producer (PC, rknn-toolkit2 2.3.2):
tools/prepare_kokoro_tts_rknn_generator.py.Read the utterance column before reproducing. Kokoro has no Russian voice (
frontend.cppaccepts a, b, e, f, h, i, j, p, z only;
--language russianthrowsunsupported Kokoro language: russian). The 185-character utterance behind every figure below isRussian text voiced through the American-English
af_heartvoice, i. e. the built-in eSpeak-ngG2P applied to Cyrillic — a language transfer, not a supported Russian path. Reproduce with the same
voice and the same text or the numbers move.
What that transfer costs, measured: faster-whisper
small, language forced, character-error-rateagainst the source text — the 224-character Russian utterance scores CER 1.390 on the CPU render
and 1.356 / 1.356 / 1.435 on the three NPU engines (the ASR recovers syllable-shaped noise: «Привет»
→ «Пэривея та»), while the English utterance through the same voice and the same engines scores
0.000, word for word. The NPU path is indistinguishable from the CPU reference; the language
transfer is what is unintelligible.
Measured on the board
q8_0, 185 Russian characters, seed 1234,
--threads 4(14.85 s audio, 1188 latent frames,17 windows):
The shipping producer default is the range-reduced (π-fold) engine, and it is slower: engines
from one producer revision interleaved three times, RTF median 1.046 against the clipped engine's
0.867 on a 6.37 s utterance (+21%), and 1.074 / 28400 ms against 0.851 / 20849 ms on a 224-character
(33.6 s) one (+36%). The 0.867 row is the clipped engine's figure.
NPU load with
RKNN_NPU_CORE_0_1_2: Core0 95% / Core1 18% / Core2 19%.Graph rewrites the NPU forces, all measured
vector_normtraces to 51ReduceL2andrknn.buildfails.GlobalAveragePool, with the mask zeroing the pad at every stageboundary (after the reflect-pad upsampler, at the resblock sum, at the noise-resblock output), not
only inside AdaIN: the conv after a masked AdaIN writes real-frame sums into the pad, and the next
conv_transposereads them where a full-length decode reads implicit zeros. Measured: 135.1 dBper-window exactness against the same frames decoded unpadded.
sin→ minimax odd polynomial (degree 5),1/αfolded into the next conv.librknnrthas no NPUSin: the 48 sine nodes of a window on CPU were 41.33% of the window(350 ms of 846 ms, operator ranking at
RKNN_LOG_LEVEL=5). The α-fold is algebraically exact(
conv(W, u + sin²(αu)/α) ≡ conv(W/α, αu + sin²(αu))) and removes one multiply and one divide.Elementwise ops are 84% of this graph's NPU time, convolutions 15%.
sine-level SNR is the
Clip, not the polynomial: over the 49,155,072 Snake arguments of a200-frame decode, 1.60% are past π (max 20.5 = 6.5π) and 0.06% past 2π, and a clipped argument
evaluates a fit outside its fitted domain — which is why degrees 5, 7 and 9 all measure the same
17.6 dB. Folding with
k = Floor(x/π+0.5); xr = x − k·π(Mul/Add/Floor/Mul/Sub) and fitting theminimax on [-π/2, π/2] gives 93.2 dB at the export against the exact sine. The fold period is
π, not 2π, because Snake consumes
sin(αu)², which is π-periodic: folding by π is exact for thisgraph's use, costs the identical 4 extra full-tensor ops per Snake, and halves the fitted interval
(the 2π fold with the fit on [-π,π] measures 50.0 dB at the generator output, 41.7 at the sine).
The fold is a quality default, not a speed one: with engines built from one producer revision
and interleaved three times per utterance on the board it costs +21% generator wall (6.37 s
RU: RTF median 1.046 against the clipped engine's 0.867; the 2π fold on a 33.6 s RU utterance
measured +36%, 28400 ms against 20849), and the build log names the mechanism — the 2.3.2 compiler
lowers every rounding op off the NPU: its per-op target column reads
Floor FLOAT16 CPUat all 48sine sites of a folded engine against
Clip FLOAT16 NPUat all 48 of the clipped one (58CPU-lowered ops against 10), so each fold site is a full-tensor NPU→CPU→NPU round trip. That is
the NPU-load signature (Core0 86-94% clipped, 70-72% folded).
Castto INT32 is CPU-lowered too,so an int-rounding form does not escape it, and
Clipis the only NPU-native op in the family:the only form cheaper than the fold is the clipped one, and the only all-NPU accurate form (a
~7-segment piecewise Clip, ~84 elementwise ops per Snake against the fold's 10) is predicted to
cost more than it saves. The renders are audibly distinct: clipped-vs-π-fold 16.95 dB,
2π-vs-π-fold 28.48 dB, clipped-vs-2π 17.28 dB (max|d| 6922/1936/8020 of 32767); in a listening
test the folded engine ranks between the CPU render and the clipped one. The CPU-vs-NPU SNR of the
engines (0.46/0.48 dB) is the per-window AdaIN renormalization below, not the sine.
--no-sin-reducereproduces the clipped export byte for byte.Parity and quality — how to read the number
No gate here is an equality gate, on purpose. The reverse-engineered RK3588 notes record a per-core
fp16 difference (lane 0 of each 16-channel group) and
rknn.configin 2.3.2 has nocore_num, soan engine is built multi-core and the runtime core mask decides what runs where — measured on the
Piper engine the four masks give byte-identical output, so this is a precaution rather than an
observed spread, and NPU renders are compared by SNR and max|d|.
ggml↔RKNN is 0.49 dB, and that has to be read against what it compares. The generator normalizes
per window (AdaIN), so a multi-window decode is a different valid synthesis, not an approximation
of a full-length one: dropping 2 of 486 latent frames from the statistics moves the output 25% RMS.
The shipping reference Kokoro RKNN engine measures 17.11 dB CPU-vs-NPU on the same utterance at 2
windows. Per-window exactness is the gate that means something:
The near-Nyquist clicks, and the cap that removes them
The NPU render carries 2-3 content-locked clicks per 26 s render: at the columns where the graph's
activations peak, the top iSTFT bins run 10-24x the full-length CPU decode's 9-12 kHz energy there.
They are fp16 rounding in the convolutional accumulation, and that is a measurement, not a guess: the
clip sine, the range-reduced sine (
--sin-reduce), the exactSinnode, the unfolded Snake(
--no-snake-fold, which bounds the convolution input) and the w128/w136 grids all leave the samecolumns at the same magnitude, so no export-time lever moves them. RKNN 2.3.2 has no per-layer
dtype knob, and moving the peak convolutions to the CPU gives up the sidecar (the convolutions are
15% of the window's time, the elementwise chain 84%).
What does remove them is runtime-side and rides the existing
rknn_generator_gainknob: cap the topfive log-magnitude rows at the reference's level at every column. Orange Pi 5 Plus (RK3588),
gen_reduce5_w128.rknn,af_heart, seed 1234, 25.9 s render; ratios are per-column 9-12 kHz energyagainst the CPU render (top 8 columns), SNR is full-render against the same:
The residual 1.4-2.8x is the iSTFT Hann-overlap smear — PCM at 9-12 kHz draws on spectrogram bins
beyond the five the cap touches. SNR does not move because it is dominated by the per-window AdaIN
renormalization above (~0 dB for every w128 engine), not by the clicks.
Deliberately opt-in: the cap needs the full-length CPU decode, so it costs 1.9x wall and +601 MB RSS
with the gain knob's own cost. Without
rknn_generator_gainthere is no reference and the block is ano-op — the shipping render is byte-identical (md5
3515c8a2…).Framework changes
framework/rknnlibrary (its own PR): the sidecar now usesengine::rknn::Enginefor the engine image,rknn_init, the core mask, the tensor attributecache and the fused
rknn_inputs_set/rknn_run/rknn_outputs_get/rknn_outputs_releasestep.What stays in
rknn_generator.cppis model-local: the 5-input contract and its name check, theW=128 window walk, the overlap and gain knobs, the seam stitching. Verified on the board: the
sidecar render is byte-identical to the pre-port render (md5
3515c8a25eba36ea525f091fdb054b90,engine
gen_w128.rknn,af_heart, seed 1234,--text-chunk-size 120).CMakeLists.txt: per-family source selection underENGINE_ENABLE_RKNN(additive, default off).kokoro_ttsaccepts its sidecar option by name as well as through the spec, because a publishedGGUF package embeds an older spec.
Docs
docs/models/kokoro_tts.md(+23): the three option rows, the measured RK3588 numbers, thecontent-locked near-Nyquist clicks finding, and the paragraph stating that the
--global-statsvariant is not in the build and why. Its link target,
docs/build/rockchip-npu.md, is added by theqwen3_tts PR in this stack, so the link resolves once that one merges.
Known limitations
A
.rknnis compiled per SoC and per fixed shape. The window width is set by the measuredreceptive field (72+28+28) and by the NPU's 13-bit register field on the longest axis: the fine
rate is
60W+1, so W=128 gives 7681 and fits, W=512 gives 30721, emits ~800kREGTASK: The bit width of field value exceeds the limit, ... limit: 0x1ffflines atvalue: 0x7800, and voicesclipped noise (rms 32764 of 32767, SNR −27 dB to the CPU decode). 128 is the widest power of two
inside the limit;
GlobalAveragePooldoes not escape it (the pool size is the same axis). A fewhundred REGTASK lines are benign — the RK3566 builds of the three shipping engines log 352
(kokoro w128), 355 (piper w93) and 6570 (qwen3 vocoder) and measure 24.1-27.0 dB against the CPU
path.
tools/rknn_build_log.pygates the difference: it captures fds 1/2 aroundrknn.build(the lines come from the C++ compiler, not Python logging), counts them and aborts past 100 000.
The ceiling is per axis and per op, and escaping it is enough for the engine. Slicing the
fine-rate axis inside the graph takes W=256 from 403,587 REGTASK lines to 0 with every gate intact
(60.5 dB parity, 135.6 dB padded-window exactness, 124.4 dB export-vs-torch), and the engine then
voiced fp16-saturated output: 117,682 non-finite values of a 14.85 s utterance, contiguous in
columns 8329-13872, peak 65440 = fp16 max — not input amplitude (identical inf counts at
x1.0/0.5/0.25/0.125), not the padding (a fully-filled window with an all-ones mask still gives
20,534), not the AdaIN all-padding divide (clamping the count changes the count by 0). It is the
AdaIN global pooling: its statistics are raw sums over the fine axis, so the site that peaks at
7681 at W=128 peaks at 1.1e6 at W=256 (onnxruntime fp32 per-node maxima: first node past fp16 max
a Mul at 612,487, largest an Add at 1,106,990).
--max-axismoves the runtime's window walkinside the graph — windows of
(max_axis-1)//scaleframes with--paddingcontext per side, eachthrough the full unsliced module, emitted columns concatenated the way
decode_windowedoverwrites the seam — so every in-graph reduction axis is at most
max_axis: W=256 (3 windows of136 at padding 28) builds with 1 REGTASK line and voices 0 non-finite values, peak 56.25, 46.8 dB
against the chunked torch reference; W=160 (2 windows) builds with 0. The 9.5 dB against the
monolithic reference is the per-window AdaIN gap (chunked-vs-monolithic gate 9.9 dB, and the fp32
PC simulator of the same graph gives the identical 9.5 dB, so the engine sits at the fp32 graph's
floor). Not shipped: the in-graph escape replicates the module inside the engine (142.7 MB for 3
windows against 74.7 MB for one W=128 window), so widening the window that way costs the weight
copies the runtime walk exists to avoid, and the stitched result is a per-window synthesis, not
the monolithic one. The cheap wide window was built and measured instead — the widest mono window
the field allows, W=136 (emitted 80, 15 windows, 76.0 MB): RTF 1.057 vs 1.114 at W=128, RSS 2345
vs 2340 MB, 0 non-finite values, pumping spread 7.67 dB vs 7.23 dB. Wider is not better, the
same verdict
rknn_generator_overlapgave. That run also closes the normalized-statistics idea:the raw sums peak at 8161 at W=136 (nothing over 65504) and at 1.1e6 at W=256, so the band of
widths where they saturate and the field passes is empty — the cure applies only to a graph the
field already rejects, so it is not implemented.
The audible artifact of the window walk is loudness pumping, not clicks. The rms of successive
0.9 s windows against the CPU render swings −2.8 to +4.5 dB (spread 7.2 dB) and the top-20 peak
samples do not land on window boundaries, i.e. the seams are clean and the per-window AdaIN
renormalization is what the ear hears as compression. The exact cure exists in fp32: making the
statistics graph I/O and feeding the full-latent statistics computed on CPU moves the stitched
windowed decode from 9.7 dB to 135.4 dB from the full-length decode (486-frame dump). It does not
survive the engine's fp16 range: on the board every window after the first renders as a
constant-energy tone (rms flat at 51.5 dB, spectral flatness 1.7e-17, energy at DC, 4800 Hz and
9600 Hz), at 1.8× the wall clock and +1.5 GB RSS. That variant is not in this branch: the producer
flag, the runtime plumbing and the extra graph I/O were removed, and the engine contract is the
5-input/1-output shipping one (a 7-input engine is rejected at load). The fix has to be in the
window walk, not in the statistics. Two knobs on the walk itself are in this branch, both off by
default (with them unset the render is byte-identical to the shipping stitch, md5
1f4926e4…), measured on the same utterance against that metric:rknn_generator_overlap=36rknn_generator_gain=1The pumping is a loudness effect, not a seam effect: overlap-blend (advance the walk by
emitted − overlap, blend the shared spectrogram columns with a raised-cosine ramp) does notmove the metric at all, while the loudness correction halves it — the ggml generator graph
stays prepared, renders one full-length CPU decode per utterance, and each window's
log-magnitude rows get the log-loudness ratio against it (linear-domain statistic,
speech-masked at 40 dB below the region peak; a plain log-domain mean is dominated by the
silence floor and measured a 26.3 dB spread). Cost 1.9× wall and +544 MB. Neither is a
default;
gain=1is the knob when wall clock is spare.The clicks are the engine's, not the walk's, and they are not fixed. A listening pass found 3
clicks on the 33.58 s render (samples 111,984 / 221,903 / 668,520) and 2 on the 14.88 s English
one. They are content-locked, not grid-locked:
rknn_generator_overlap=36(39 + 33 windowsagainst 20 + 17) reproduces them at the identical samples, and all three engines (clipped, 2π-fold,
π-fold) put them at the same samples. They are engine-only: the CPU render of the same text and
seed has no jump there (its own largest jump anywhere 16,300, theirs 23,000–34,000,
sign-alternating = energy near Nyquist) and a 30 ms window at those positions carries 2.5–5× the
CPU render's 9–12 kHz energy. Not the fp16 range, not the iSTFT head: the generator output of the
NPU render, captured with the dump path in a development build (since removed), has log-magnitude
rows in [−58.8, +3.35] (CPU [−115, +3.03]), and clamping the
exponent at 4.0 in the head leaves every render byte-identical (md5), so
exp()amplifiesnothing. The engine raises its own upper mel bins there: at the burst columns row 6 is +3.31
against the CPU's +1.74 and row 10 (the Nyquist bin of
gen_istft_n_fft = 20) +0.50 against−0.93 — a 4–5× magnitude increase at ~7 columns of 87,121, at the window-relative fine columns
(~3498, ~3612 of 7681) where the graph's largest activations peak. The same graph is clean there
in fp32 onnxruntime (123–125 dB per window) and in the PC simulator of the same compiled engine
(ulp-level per-layer error), so the excess is the RK3588 DPU's own fp16 accumulation at the
activation peaks. Nothing in the window walk reaches it; the only reference available to repair
against is the full-length CPU decode the
gain=1path already renders.One
rknn_contextper sidecar. Running windows concurrently on threerknn_dup_contextcontexts,which is what the reference Kokoro engine does, measured 1.15× on the window loop (9650 → 8375 ms)
with corrupted output (−7 dB, rms 2×): duplicated contexts share the runtime's tensor staging and
this engine reads ~75 MB of weights per window at 0.098 GB/s against a measured 26.4-29.4 GB/s
DRAM ceiling, so the loop is compute-bound, not bandwidth-bound — three cores on one job beat
three jobs on three cores.
RK3566 target: the documented producer command was run on the host and the engine builds
(61,281,856 bytes with the π-fold sine default, 352 REGTASK lines, same parity gates:
60.5 dB parity, 135.1 dB padded-window, 124.3 dB export-vs-torch; the clipped-sine export is
60,981,696, the 2π-fold's 61,282,176). Unmeasured on a board — there is no RK3566 here.
Mali/Vulkan is 2.1× slower than CPU on this board (measured) and is out of scope.