Skip to content

Strip the ONNX module prefix in the Inflect v2 converter - #933

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
wOvAN:inflect-v2-converter-names
Oct 16, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
wOvAN:inflect-v2-converter-names

Conversation

@wOvAN

@wOvAN wOvAN commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Symptom

tools/community_models/convert_inflect_v2.py produces a weights file the runtime refuses to load.
The first tensor it inspects already fails:

Inflect v2 has unexpected tensor: model.dec.conv_pre.weight

Cause

The two sides spell the same 302 tensors differently, and the converter ships the wrong spelling.

  • The converter's own inventory (_expected_tensors) is written in the ONNX export's spelling, with
    the model. module prefix: model.enc_p.emb.weight, model.flow.flows.0.pre.weight, ... It
    validates the loaded ONNX initializers against that inventory by exact set equality, so the check
    only passes because the exports really are prefixed.
  • The runtime's inventory (expected_tensors in src/community_models/inflect_v2/assets.cpp) is
    unprefixed: enc_p.emb.weight, flow.flows.0.pre.weight, dec.conv_pre, dp.proj, ... and it
    validates the loaded file by exact name lookup, with actual.size() != expected.size() and
    Inflect v2 has unexpected tensor: <name> as the two failure paths.
  • convert() then saves tensors — the ONNX names — verbatim.

So the tool and the loader cannot both be satisfied: with prefixed exports the converter's inventory
check passes and the saved file is unloadable, and with unprefixed exports the converter raises
invalid ONNX tensor inventory before it writes anything.

Fix

Strip the prefix at the one place where the spelling changes, the save_file call. The inventory
check keeps running against the ONNX names, which is what makes it a check.

Validation

Run against the official exports, owensong/Inflect-Micro-v2-ONNX
(onnx/duration.onnx 7.3 MB, onnx/decode.onnx 30.4 MB, config.json), Python 3.12, onnx 1.23.2,
safetensors 0.8.0:

convert_inflect_v2.py --duration duration.onnx --decode decode.onnx \
    --config config.json --output out.safetensors
Wrote micro-v2 FP32 weights to out.safetensors        # 37 409 644 bytes, 302 tensors
file tensors names starting with model. roots
as shipped 302 302 model
this change 302 0 dec, dp, enc_p, flow

The fixed set is exactly the shipped set with the prefix removed, and every one of the runtime's
name stems (enc_p.emb.weight, enc_p.encoder.attn_layers.*, enc_p.encoder.ffn_layers.*,
flow.flows.*, dec.ups.*, dec.resblocks.*, dec.conv_pre, dec.conv_post, dp.norm_1/2.gamma/beta,
dp.proj) has names under it in the fixed file — the two inventories are the same 302 names.

Known limitations

  • Verified at the file level, not by loading: the packaged model for this family is a GGUF
    (inflect_micro_v2_orig), so the safetensors the converter writes is not the file the packaged
    model path opens. The name sets are compared directly instead, which is the check the loader
    performs.
  • The Nano v2 export was not converted here; it shares the exporter, so the same prefix applies.

`tools/community_models/convert_inflect_v2.py` writes the ONNX initializer names
verbatim, and the official Inflect v2 exports prefix every one of them with the
`model.` module path. The runtime's inventory
(`src/community_models/inflect_v2/assets.cpp`) is spelled without it, so a package
built by the converter loads and dies on the first name it checks:

    audiocpp_cli failed: Inflect v2 has unexpected tensor: model.dec.conv_post.weight

The inventory check keeps the ONNX spelling - that is what the ONNX files
contain, and it is what the error message should name when an export is missing a
tensor - and only what is written to safetensors is renamed, at the one place
that crosses into the runtime's naming.

Verified on the official exports, owensong/Inflect-Micro-v2-ONNX (onnx/duration.onnx 7.3 MB,
onnx/decode.onnx 30.4 MB, config.json), Python 3.12, onnx 1.23.2, safetensors 0.8.0: as shipped the
converter writes 302 tensors whose root is `model` for all 302; with this change the same run writes
the same 302 tensors with bit-identical values, 0 prefixed names, and roots `dec`, `dp`, `enc_p`,
`flow` - the spelling src/community_models/inflect_v2/assets.cpp builds its inventory in. The loader
itself was not executed against the fixed file (the packaged model for this family is a GGUF,
`inflect_micro_v2_orig`), so the check is the name set, which is what the loader compares.
@0xShug0
0xShug0 merged commit 9c69e6b into 0xShug0:main Oct 16, 2026
6 checks passed
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