Fix initializer load for in-memory external data#29349
Open
tairenpiao wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Initializer(graph, ...) behavior for initializers that use in-memory external data when the corresponding OrtValue is not registered: the constructor no longer incorrectly requires a non-empty model_path, and instead falls back to CreateTensorFromTensorProto to load from the in-memory external buffer (consistent with the other Initializer constructor). This addresses the CreateSessionFromArray failure reported in #28267.
Changes:
- Remove the
model_path must not be emptyenforcement in the graph-basedInitializerconstructor for the in-memory-external-data + missing-OrtValue case. - Add a regression test covering an in-memory external-data initializer with empty
model_pathand no registeredOrtValue.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/core/optimizer/initializer.cc | Removes the incorrect model_path enforcement so in-memory external data can be loaded via CreateTensorFromTensorProto when no OrtValue is present. |
| onnxruntime/test/optimizer/initializer_test.cc | Adds a regression test to ensure in-memory external-data initializers load correctly without model_path when no OrtValue is registered. |
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
The
Initializer(graph, …)constructor wrongly required amodel_pathfor an initializer with in-memory external data when itsOrtValuewasn't registered. It now loads the data from memory viaCreateTensorFromTensorProto, matching the other constructor.Motivation and Context
Fixes #28267. A model loaded from bytes via
CreateSessionFromArrayfailed withmodel_path must not be empty; loading the same model from a file worked.