-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model Builder API #23223
Model Builder API #23223
Conversation
Supports creating a model programmatically using the ORT C or C++ API. Supports augmenting an existing model to add nodes.
include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
Fixed
Show fixed
Hide fixed
#include "core/framework/error_code_helper.h" | ||
#include "core/framework/execution_provider.h" | ||
#include "core/session/abi_session_options_impl.h" | ||
// #include "core/session/environment.h" |
Check notice
Code scanning / CodeQL
Commented-out code Note
include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
Outdated
Show resolved
Hide resolved
Is it possible to save out the model from the builder via the C API? It'll be a nice alternative to building ONNX models with raw protobufs in languages which don't have a native ONNX library. |
You can use the SessionOption that's typically used to save the optimized ONNX model. onnxruntime/include/onnxruntime/core/session/onnxruntime_c_api.h Lines 909 to 910 in 6e76179
Caveat is that does not currently support saving tensors created with CreateTensorWithDataAsOrtValue or CreateTensorWithDataAndDeleterAsOrtValue, but could be updated to do so if required. |
Is the optimized model one which has had op fusion and other passes done so it's no longer using ONNX standard ops everywhere, or is that a different process? |
You can specify the optimization level. If you keep it to level 1 (GraphOptimizationLevel.ORT_ENABLE_BASIC) it will only use standard ONNX ops. onnxruntime/include/onnxruntime/core/session/onnxruntime_c_api.h Lines 343 to 345 in a3833a5
onnxruntime/include/onnxruntime/core/session/onnxruntime_c_api.h Lines 1020 to 1029 in a3833a5
https://onnxruntime.ai/docs/performance/model-optimizations/graph-optimizations.html |
* Pass ORT_API_VERSION to `OrtApiBase::GetApi()` Also removes the inclusion of onnx.pb.h header. * Add third_party/onnxruntime_headers Import https://github.com/microsoft/onnxruntime/tree/main/include Commit is based on microsoft/onnxruntime#23223 * Use ORT Model Builder API * Refactor scoped ORT type ptr 1. Rename to ScopedOrtTypePtr 2. Use macros 3. Introduce `operator T*()` 4. Introduce `Release()` method 5. Rename `get_ptr()` to `Get()` 6. Rename `get_pptr()` to `GetAddressOf()` * Remove ONNX Runtime headers from third_party/microsoft_dxheaders
@skottmckay , Saving tensors created with |
- enforce 128 byte minimum for tensors with external data to avoid shape inferencing issues - update unit tests to use 128 byte initializer so external data can be tested - support saving initializer with in-memory external data to ONNX model by copying into TensorProto's raw_data property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
Exclude model editor API funcs from minimal build. They require Graph::Resolve and therefore need a full build.
…uct by adding a dummy field.
Cleanup some SAL annotations Update comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Description <!-- Describe your changes. --> Supports creating a model programmatically using the ORT C or C++ API. Supports augmenting an existing model to add nodes. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. -->
Description
Supports creating a model programmatically using the ORT C or C++ API.
Supports augmenting an existing model to add nodes.
Motivation and Context