Skip to content

refactor(rknn): read the sliced graph through one shared helper - #983

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
wOvAN:rknn-converter-shared-reads
Oct 19, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
wOvAN:rknn-converter-shared-reads

Conversation

@wOvAN

@wOvAN wOvAN commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

What

tools/rknn/prepare_piper_tts_rknn_vocoder.py and tools/rknn/prepare_inflect_v2_rknn_decoder.py each carried a private copy of the same two ONNX graph reads:

  • graph_input_names(onnx_path) — the input-name list of the sliced graph;
  • decoder_channels — the latent channel count read back from z, with the message naming the path (#961 was the first dedup pass; this is the second, smaller layer of the same audit).

One copy of each now lives in tools/rknn/rknn_graph.py, imported by both converters. The Piper spelling's message (which names the path) wins: the graph reader takes a where label, and the path wrapper passes the path through it.

The same-named function in prepare_cosyvoice3_rknn_flow.py is not a reader — it validates the export's feeder set against the expected ladder and refuses an export whose names differ. It stays in its converter, renamed to check_graph_inputs, so the one name no longer reads as the other.

No behavior change: the moved code is the same loop, the same SystemExit texts (modulo the path prefix Piper already had), and the qwen3/kokoro converters are untouched.

Validation (PC, rknn-toolkit2 2.3.2 venv, onnx 1.22)

python3 -m py_compile tools/rknn/*.py
# all six tools/rknn scripts import inside the toolkit venv
~/venv-rknn/bin/python -c "import importlib; [importlib.import_module(m) for m in (...6 modules...)]"
  • Shared readers on the real sliced Piper graph (decoder_z.onnx, sliced en_US-lessac-medium): graph_input_names -> ['z'], decoder_channels -> 192.
  • check_graph_inputs on the real CosyVoice3 export (flow.decoder.estimator.fp32.onnx) still returns ['x', 'mask', 'mu', 't', 'spks', 'cond'].
  • Full converter self-check through the moved functions:
~/venv-rknn/bin/python tools/rknn/prepare_piper_tts_rknn_vocoder.py \
  --onnx .../out/decoder_z.onnx --voice-onnx .../en_US-lessac-medium.onnx --skip-rknn
# -> global_snr=105.5 dB, tail slice 33.6 dB, depop shift=0 at every seam
  • Engine side: a full RK3588 compile of the same graph through the refactored converter path builds (gate log kept), and two builds of the same graph in the same venv give bit-identical simulator outputs (RKNN.inference on the PC simulator, max abs diff 0.000e+00) — the compiler is deterministic, so nothing in the moved reads perturbed the compiled graph.
  • python3 tools/check_loader_catalog_sync.py --self-test && python3 tools/check_loader_catalog_sync.py — ok (untouched surfaces, run per repo ritual).

The Piper vocoder and Inflect v2 decoder converters each carried a private
copy of the same two ONNX graph reads: the input-name list of the sliced
graph and the latent channel count read back from its `z`. One copy of each
now lives in `tools/rknn/rknn_graph.py`, imported by both converters.

The Piper path keeps its message shape (`<path>: input z must be ...`) by
threading the path into the graph reader as its `where` label; the Inflect
slice stage keeps reading the in-memory graph it just renamed.

The same-named function in the CosyVoice3 converter is not a reader -- it
validates the export's feeder set against the expected ladder -- so it is
renamed to `check_graph_inputs` and stays in its converter, where the one
name can no longer read as the other.

Validated in the toolkit venv (rknn-toolkit2 2.3.2, onnx 1.22): all six
`tools/rknn` scripts import; `graph_input_names`/`decoder_channels` read
`['z']` and 192 from the sliced `en_US-lessac-medium` decoder;
`check_graph_inputs` still validates the flow estimator export as
`['x', 'mask', 'mu', 't', 'spks', 'cond']`; the Piper converter's full
self-check on the real voice reports `global_snr=105.5 dB` with the tail at
33.6 dB, as before the move.
@0xShug0
0xShug0 merged commit f82b88a into 0xShug0:main Oct 19, 2026
6 checks passed
@0xShug0

0xShug0 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

@wOvAN Merged!

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