Repository navigation
Strip the ONNX module prefix in the Inflect v2 converter - #933
Merged
Merged
Conversation
`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.
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.
Symptom
tools/community_models/convert_inflect_v2.pyproduces a weights file the runtime refuses to load.The first tensor it inspects already fails:
Cause
The two sides spell the same 302 tensors differently, and the converter ships the wrong spelling.
_expected_tensors) is written in the ONNX export's spelling, withthe
model.module prefix:model.enc_p.emb.weight,model.flow.flows.0.pre.weight, ... Itvalidates the loaded ONNX initializers against that inventory by exact set equality, so the check
only passes because the exports really are prefixed.
expected_tensorsinsrc/community_models/inflect_v2/assets.cpp) isunprefixed:
enc_p.emb.weight,flow.flows.0.pre.weight,dec.conv_pre,dp.proj, ... and itvalidates the loaded file by exact name lookup, with
actual.size() != expected.size()andInflect v2 has unexpected tensor: <name>as the two failure paths.convert()then savestensors— 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 inventorybefore it writes anything.Fix
Strip the prefix at the one place where the spelling changes, the
save_filecall. The inventorycheck 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.onnx7.3 MB,onnx/decode.onnx30.4 MB,config.json), Python 3.12, onnx 1.23.2,safetensors 0.8.0:
model.modeldec,dp,enc_p,flowThe 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
(
inflect_micro_v2_orig), so the safetensors the converter writes is not the file the packagedmodel path opens. The name sets are compared directly instead, which is the check the loader
performs.