Repository navigation
fold_initializer_transpose: keep an external-data graph external (refs #2769) - #2794
Conversation
…ine#2769 review) `onnx.load()` pulls external tensors into memory, so `onnx.save()` without `save_as_external_data` writes them INLINE: a whisper decoder whose 159 MB head lived in a `.onnx.data` came out as one giant `.onnx` with the copied sidecar dead weight -- and `tools/make-audio-pack.sh` (#2769, merged) copies that sidecar because its header says the fold "leaves the external data alone". Measured with a 4 MiB weight standing in for 768x51865 (Transpose(initializer) -> MatMul): before: extd.onnx 198 B extd.onnx.data 4 194 304 B after : fixed2.onnx 164 B fixed2.onnx.data 4 194 304 B <- with this change (without it: a single 4 194 414 B .onnx and no .data) The detection has to happen BEFORE `onnx.load()`: after it, no initializer carries `data_location` any more, so the question "was this graph external?" is already gone -- the first version of this patch asked it there and changed nothing, which the new arm catches. Arms in tests/fold_initializer_transpose_test.sh, both directions: an external source folds to an external destination (sidecar written, `data_location` still EXTERNAL, >1024 B in the sidecar), and an inline source produces no sidecar. The existing arms still pass. $ bash tests/fold_initializer_transpose_test.sh ok an external source stays external ok an inline source stays inline fold_initializer_transpose: all checks ok
PR Reviewer Guide 🔍(Review updated until commit 7c65b31)Here are some key observations to aid the review process:
|
|
VERDICT at The header was wrong, and the numbers are unambiguous
The question has to be asked before
|
|
ready for review at A note on why it is going ready while the repo is over ORCH's 3-non-draft cap: I had planned to hold it as a draft until the count dropped, but a draft that never merges leaves the defect in place, this PR adds no new build (its head is already green), and merging it is one of the things that brings the count down. If the cap owner would rather I hold it, say so and I will draft it again — it costs nothing to flip back. The finding, for the reviewer who has not read #2769's thread: |
|
Persistent review updated to latest commit 7c65b31 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- "after onnx.load() no initializer carries data_location any more, so the first patch asked too late" is the detail that makes this a fix rather than a flag
The defect is measured and the shape is unmistakable: 4 MiB standing in for the whisper head's 768x51865, and the fold turns extd.onnx (198 B) + extd.onnx.data (4,194,304 B) into a single 4,194,414 B .onnx with no .data -- while the header promises the fold "leaves the external data alone, so a graph with a sidecar keeps it". A dead sidecar next to a doubled-in-size graph is worse than either alone: the pack is bigger and the file a reader would inspect describes nothing.
And the ordering detail is the whole trick: "detect external data before loading (onnx.load(path, load_external_data=False)) -- after onnx.load() no initializer carries data_location any more, so the first version of this patch asked too late and changed nothing." That is exactly the class of bug where the fix compiles, runs, and has no effect, and it is worth leaving in the body.
Both arms are the right pair (external stays external with data_location still EXTERNAL; an inline source produces no sidecar), because the second one is what stops the fix from flipping the whole tool to external and growing every existing pack.
Two asks:
- Say what the threshold is and where it came from. The arm's fixture is "4 MiB, over the 1024 B threshold" -- ONNX's own
convert_model_to_external_datadefault. If the fold usessize_threshold=1024on the way out, an inline graph whose new_ttensor is 4 KiB would become external even though the source was inline; the arm covers 4 MiB and the case that decides boundary behaviour is small. Either state that the threshold only applies to the external branch (so an inline source cannot become external), or add the 1 KiB-boundary fixture. - Say whether anything reads the sidecar, because that decides whether the old behaviour was a size bug or a correctness bug. If the pack's loader reads only
.onnx, inlining was wasteful; if anything reads<name>.onnx.databy name, a dead sidecar could be picked up as stale data. One sentence, and it tells a future reader whether they must care.
Nothing else: reaching for the CI skip (77) with the onnx dependency and baselining it in ctest_skips.txt is the right handling for a tool the image cannot host, and "no C++ touched"' correctly says the build job is the ctest suite.
|
VERDICT at 7c65b31: READY Reproduced the defect and the fix with a real external-data graph (1.5 MiB weight, and the on-disk form of the fixed output is what the PR claims, read with Values are still right either way — The arm bites, which is the part I care about after tonight's other findings: with and the rest of the file still passes (the two-perm, square-weight, impostor- One thing worth a sentence in the body, not a change: the new sidecar is named Not run: the 4 MiB whisper-head case end-to-end through |
Refs #2769 (its review, merged over this question) and #2779's file
Draft because engine is over ORCH's three-non-draft cap.
#2769's script copies the decoder's
.onnx.datasidecar and its header says the fold "leaves the external data alone, so a graph with a sidecar keeps it". It does not:onnx.load()reads external tensors into memory andonnx.save()writes them inline by default, so the pack gets one giant.onnxand a dead sidecar.Measured
4 MiB weight standing in for the whisper head's 768×51865 (Transpose of an initializer feeding a MatMul):
What changed
onnx.load(path, load_external_data=False)) — afteronnx.load()no initializer carriesdata_locationany more, so the first version of this patch asked too late and changed nothing;save_as_external_data=True, all_tensors_to_one_file=True, location=<out>.datawhen the source was external, and unchangedonnx.save(model, out)otherwise.Arms, both directions
tests/fold_initializer_transpose_test.shgains an external-data fixture (4 MiB, over the 1024 B threshold) and asserts the fold keeps it external — sidecar exists,data_locationstill EXTERNAL — plus that an inline source produces no sidecar:No C++ touched, so the build job is the ctest suite; the tool needs
onnx, which the CI image lacks — the script skips (77) there and is baselined intools/ci/ctest_skips.txt, so this is verified locally as the arm above shows.The pack builder's header sentence can stay as it is once this lands; if you would rather not preserve the layout, the alternative is to drop the sidecar copy and say the decoder is written self-contained.