onnxruntime
a0d9008f - Honor model_external_initializers_file_folder_path for file-path model loads (#29459)

Commit
14 days ago
Honor model_external_initializers_file_folder_path for file-path model loads (#29459) ### Description `session.model_external_initializers_file_folder_path` now takes effect for every model load path and overrides the model's own directory as the base for resolving external initializers. - New `Model::Load(file_path, graph_model_path, ...)` overload reads the model bytes from `file_path` while storing a separate graph model path that is used only for external-data resolution. - `InferenceSession` applies the option in all ONNX load paths (file path, memory buffer, `ModelProto`, `istream`, and the parsed-proto `Load()`): the model is read from its real location, but external initializers are resolved from the option's folder. The prior restriction that only honored the option when the model location was empty is removed. Adds a shared-lib test that loads a model from a path whose directory does not contain the external data and resolves it via the option. ### Motivation and Context The option was originally added in #23557 to let a model loaded from an in-memory buffer point ORT at a folder holding its external initializer files, since a buffer has no directory of its own. That implementation only applied when the model location was empty, so it worked exclusively for buffer/stream loads and required the caller to clear the model directory first. Since then the option is used for more scenarios: weightless/cache models, models that share a single weights file, and packaged models whose weights live outside the model's own folder. In all of these the caller wants to point ORT at a specific external-initializers folder regardless of how the model itself is loaded. Restricting it to buffer loads made the usage narrow and unexpected. This change makes the behavior generic: the option is honored for file-path loads too and overrides the model directory. Overriding is safe because the option only changes the base directory used to resolve external initializer files; the model bytes are still read from the real location. Downstream consumers of the graph model path already tolerate a virtual or non-existent model path, since buffer loads (a very common case) have always produced exactly such a path, and they either use only the parent directory or guard file access with existence checks. A follow-up PR will build on this to simplify the model package flow (fold the `external_data` variant field into general session-options path resolution) and to remove the legacy directory-based `CreateSession` path. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
Parents
Loading