Skip to content

Fix initializer load for in-memory external data#29349

Open
tairenpiao wants to merge 1 commit into
microsoft:mainfrom
tairenpiao:fix-initializer-inmemory-from-array
Open

Fix initializer load for in-memory external data#29349
tairenpiao wants to merge 1 commit into
microsoft:mainfrom
tairenpiao:fix-initializer-inmemory-from-array

Conversation

@tairenpiao

Copy link
Copy Markdown
Contributor

Description

The Initializer(graph, …) constructor wrongly required a model_path for an initializer with in-memory external data when its OrtValue wasn't registered. It now loads the data from memory via CreateTensorFromTensorProto, matching the other constructor.

Motivation and Context

Fixes #28267. A model loaded from bytes via CreateSessionFromArray failed with model_path must not be empty; loading the same model from a file worked.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 empty enforcement in the graph-based Initializer constructor for the in-memory-external-data + missing-OrtValue case.
  • Add a regression test covering an in-memory external-data initializer with empty model_path and no registered OrtValue.

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.

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.

Calling CreateSessionFromArray on our model triggers an Exception

2 participants