Fix shape inference failure with file-backed external data - #31169
Open
yoonseok-kim wants to merge 1 commit into
Open
Fix shape inference failure with file-backed external data#31169yoonseok-kim wants to merge 1 commit into
yoonseok-kim wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
@yoonseok-kim please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
yoonseok-kim
force-pushed
the
fix/file-backed-external-shape-inference
branch
2 times, most recently
from
July 30, 2026 13:42
52768e4 to
b5769da
Compare
Materialize file-backed external initializers into temporary TensorProto values when ONNX shape inference requests their data. Keep the graph initializers external so runtime loading can continue to use mmap.
yoonseok-kim
force-pushed
the
fix/file-backed-external-shape-inference
branch
from
July 30, 2026 13:49
b5769da to
dbe461e
Compare
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.
Description
This change allows ONNX shape inference to consume file-backed external initializers when their values are required.
TensorProto.temp_tensor_protos_lifetime, so the temporary data is released after node shape inference.ReduceSum.axesin external data, loads the model, verifies the inferred output shape, and confirms that the graph initializer remains external.Motivation and Context
ONNX models can store initializer payloads in separate external-data files. This includes offline-optimized artifacts saved by ONNX Runtime as well as models created or repackaged by other tooling. Such a model can place values required by shape inference, such as
Reshape.shape, in an external-data file.When the model is loaded again,
InferenceContextImpl::getInputData()returns aTensorProtowhose payload is still external. ONNX shape inference does not load file-backed external data, so loading fails with aShapeInferenceErroreven though the artifact was successfully produced by ONNX Runtime.This is the failure reported in #21325 for an offline-optimized model, but the underlying issue is not specific to offline optimization. A similar failure was previously reported in #11137.
ONNX Runtime already materializes in-memory external initializers into temporary
TensorProtovalues for shape inference, as implemented in #26263. This change extends the same approach to file-backed external initializers. Only initializer values requested by shape inference are read; the original graph initializer and the runtime file-backed loading path are unchanged.Fixes #21325
Testing
GraphTest.ShapeInferenceWithFileBackedExternalData, which verifies that:ReduceSumoutput shape is correct; and