Repository navigation
refactor(rknn): build every engine through one converter helper - #961
Merged
Merged
Conversation
All five tools/rknn/prepare_* converters ended in the same five calls on the
RKNPU2 Python API -- config, load_onnx, the register-field-gated build,
export_rknn, release -- written out five times, with the fp16/single_core_mode
comments repeated with them. The sequence moves to tools/rknn/rknn_build.py as
build_engine(onnx, output, target, names=..., shapes=..., opt_level=...,
verbose=..., gate_label=..., gate_log=...); the gate itself stays where it
lives (rknn_build_log.rknn_build_gate) and is still what wraps rknn.build.
What stays per converter is everything that produces the arguments: the ONNX
surgery, the input names and shapes, per-engine file naming, and the
simulator-side verification (CosyVoice3's verify_fp16 keeps its own build +
init_runtime path, which is an inference call and not part of this).
Net -54 lines in the converters. The shared failure messages replace the
per-file variants ("build failed (see the rknn log above)" everywhere,
instead of also "ERROR: rknn build failed: {ret}" in the Qwen3 converter); the
return code was always the same nonzero value.
Validation (host, x86_64, rknn-toolkit2 2.3.2 in a dedicated venv):
- python3 -I -m py_compile tools/rknn/*.py
- python3 -I tools/rknn/rknn_build_log.py (gate self-test) -> ok
- three real rk3588 builds through build_engine on a synthetic 4-input step
graph, one per call shape the converters make: static graph with nothing
declared (Inflect), declared names+shapes with optimization_level
(CosyVoice3), str paths + verbose + explicit gate label and log (Qwen3-TTS).
All three export a 28369-byte engine and write their build log.
- one converter end-to-end through the CLI: prepare_piper_tts_rknn_vocoder.py
--onnx decoder_z.onnx --output decoder_z.rknn --target rk3588 --window 93
--skip-check -> "wrote decoder_z.rknn (0.1 MB, inputs ['z', 'y_mask', 'g'],
window 93)" plus decoder_z.build.log.
- tools/check_loader_catalog_sync.py -> ok (no C++ or spec surface touched).
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.
What moves
Follow-up to the review on #951, where «(3) is safe» was the shared converter build helper.
All five
tools/rknn/prepare_*converters ended in the same five calls on the RKNPU2 Python API —config,load_onnx, the register-field-gatedbuild,export_rknn,release— written out fivetimes, with the
fp16/single_core_modecomments repeated with them. The sequence now lives intools/rknn/rknn_build.pyasbuild_engine(onnx, output, target, *, names, shapes, opt_level, verbose, gate_label, gate_log). The gate itself stays where it lives(
rknn_build_log.rknn_build_gate) and is still what wrapsrknn.build.Everything that produces the arguments stays in the converter: the ONNX surgery, the input names
and shapes it declares, the per-engine file naming, the print of what it wrote. CosyVoice3's
verify_fp16is deliberately untouched — itsbuild+init_runtime()+inferenceis thesimulator parity probe, not an engine export.
-54net lines in the converters,+65with the new module and its docstring.Behaviour kept, behaviour changed
Kept per converter:
optimization_level(CosyVoice3, Qwen3-TTS),RKNN(verbose=True)(Qwen3-TTS),the gate labels (
build <name>.rknnwhere that was the label,<name>.rknnwhere it was that) andthe log paths (
<out>.build.log).Changed: one set of failure messages.
load_onnx failed/build failed (see the rknn log above)/export_rknn failedeverywhere, instead of alsoERROR: rknn build failed: {ret}in the Qwen3converter. The code in that message was always the same nonzero value.
Not touched: no C++, no spec, no
model_specs, no docs beyond a three-line pointer indocs/build/rockchip-npu.mdnext to the paragraph that documents the gate.Validation
Host, x86_64, rknn-toolkit2 2.3.2 in a dedicated venv (onnx 1.22.0, numpy 1.26.4, onnxruntime
1.26.0), Python 3.12 with
-I. No board involved — this path is PC-side conversion.python3 -I -m py_compile tools/rknn/*.py→ clean.python3 -I tools/rknn/rknn_build_log.py(gate self-test) →rknn_build_log self-test ok.Three real
rk3588builds throughbuild_engineon a synthetic 4-input step graph(
audio_codesint64[1,16,4],freqs_in,cache_valid,cache_in), one per call shape theconverters make:
a.build.lognames/shapes+opt_level=3b.build.logstrpaths +verbose=True+ explicitgate_label/gate_logc.rknn.build.logA synthetic graph is enough here because the thing under test is argument wiring — that
load_onnxgets the declared names and shapes, thatoptimization_levelreachesconfig, thatthe gate is still the thing wrapping
buildand still writes its log — not the engine's quality.One converter end-to-end through its own CLI, real ONNX, real target:
plus
decoder_z.build.log.python3 -I tools/check_loader_catalog_sync.py→ok: runtime loaders, model_specs, and model_manager_v2 are in sync.Limitation, stated plainly: only the Piper converter was run as a whole script; the other four were
exercised through
build_enginewith their exact argument sets, and their non-build stages (ONNXsurgery, gates, verification) are untouched by this diff.