ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
Find a file
Chi Lo bbc30feb63
Make execution order an option for GraphViewerToProto() (#20411)
**Current issue:**

Once ORT gets the capability from EP's GetCapability(), it creates a
graph viewer based on the capability as below:
`viewers.push_back(std::make_unique<GraphViewer>(graph,
*cur_capability.sub_graph));` or see the code
[here](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/framework/graph_partitioner.cc#L458).

At this point, the graph viewer has the chance to generate the wrong
order of `nodes_in_topological_order_` when calling
[Graph::ReverseDFSFrom](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/graph/graph_viewer.cc#L107),
so that during EP Compile(), EP might create the "wrong nodes ordering"
model proto from the graph viewer when calling
[GraphViewerToProto()](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/graph/graph_proto_serializer.cc#L37)
because of the `nodes_in_topological_order_`.

This is a problem for TRT EP to refit weights to the "weightless"
engine. Since the engine is built from the model proto provided by TRT
EP and the weights is in the original onnx model. The model proto and
the orignal onnx model are not the same in terms of node ordering which
makes TRT complain when refitting.

**The original model (subgraph of ResNet50):**
<img width="442" alt="image"
src="https://github.com/microsoft/onnxruntime/assets/54722500/bb9a641d-f2f2-46c3-aebf-4084a08ff289">

**The serialized model proto generated by TRT EP:**
(The highlighted part has the wrong node order compared to the original
model.)
<img width="340" alt="image"
src="https://github.com/microsoft/onnxruntime/assets/54722500/bbc6bf34-f960-4753-9474-a18ebc2dc48b">

**The solution 1:**
Change default comparator to `NodeCompare::operator() {return
n1->Index() > n2->Index();}`

The root cause of the different node order between original model and EP
generated model is from graph viewer [generating
](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/graph/graph_viewer.cc#L107)the
different `nodes_in_topological_order_`. Modifying the
`NodeCompare::operator()` for sorting can fix the problem.

The `NodeCompare::operator()` will be used in
[Graph::ReverseDFSFrom](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/graph/graph.cc#L1760)
where the input nodes of the current node will be
[sorted](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/graph/graph.cc#L1802)
based on node index.
Due to the sorted nodes will be pushed into a stack which later
determines the final topological node order in a "first in, last out"
approach, the larger node index should be pushed into the stack first.
So that we can get a topological node order aligns with smaller index
node comes first.

**The solution 2 (This PR uses this solution):**
Use priority-based BFS for topological sort in GraphViewerToProto().
2024-04-25 16:07:36 -07:00
.config
.devcontainer
.gdn
.github Bump gradle/wrapper-validation-action from 2 to 3 (#20305) 2024-04-16 14:20:51 -07:00
.pipelines Update DML to 1.14.1 (#20380) 2024-04-18 22:43:41 -07:00
.vscode disable gemm f16 on CPU (#19744) 2024-03-01 13:44:29 -08:00
cgmanifests upgrade emsdk to 3.1.57 (#20295) 2024-04-19 23:05:18 -07:00
cmake [TensorRT] adapt for TRT lib name change after TRT 10 GA (#20445) 2024-04-24 21:46:54 -07:00
csharp Revert "Nuget .NET changes for Mac Catalyst (#19923)" (#20418) 2024-04-23 15:08:12 +08:00
dockerfiles OpenVINO EP Rel 1.18 Changes (#20337) 2024-04-19 00:31:38 -07:00
docs add bf16 support for few ops (#20385) 2024-04-25 11:28:34 -07:00
include/onnxruntime/core Introduce memory efficient topological sort (#20258) 2024-04-23 08:00:23 +08:00
java [java][DML EP] Modifying dml_provider_factory.h so it can compile as a C header file (#20157) 2024-04-01 21:58:50 -07:00
js [WIP][JS/WebGPU] Inputs Key and Value could be 4-dims. (#20470) 2024-04-25 13:33:46 -07:00
objectivec Fix Objective-C static analysis warnings. (#20417) 2024-04-24 11:48:29 -07:00
onnxruntime Make execution order an option for GraphViewerToProto() (#20411) 2024-04-25 16:07:36 -07:00
orttraining add bf16 support for few ops (#20385) 2024-04-25 11:28:34 -07:00
rust Fix rust compile issues and add GH action to run build validations and tests (#18346) 2023-11-09 04:26:02 -08:00
samples Removed all the deprecated python training code and related tests and utils (#18333) 2023-11-17 18:19:21 -08:00
tools Extend mac package jobs time out limit (#20459) 2024-04-25 10:13:13 -07:00
winml [DML EP] Add GroupQueryAttention (#20327) 2024-04-19 10:25:29 -07:00
.clang-format Prevent GSL_SUPPRESS arguments from being modified by clang-format (#17242) 2023-08-22 18:26:53 -07:00
.clang-tidy
.dockerignore
.gitattributes
.gitignore Build onnxruntime.dll as arm64x (#18633) 2023-12-06 16:49:00 -08:00
.gitmodules upgrade emsdk to 3.1.57 (#20295) 2024-04-19 23:05:18 -07:00
.lintrunner.toml Support >2GB of Tensor data in training checkpoint (#20077) 2024-04-22 15:17:43 -07:00
build.bat try to find patch.exe in git default installation folder (#17106) 2023-08-10 21:48:13 -07:00
build.sh Upgrade old Python version in packaging pipeline (#16667) 2023-07-17 08:24:47 -07:00
build_arm64x.bat remove unnecessary environment variable (#19166) 2024-01-16 16:24:37 -08:00
CITATION.cff Fix citation author name issue (#19597) 2024-02-22 17:03:56 -08:00
CODEOWNERS
CONTRIBUTING.md
lgtm.yml
LICENSE
NuGet.config
ort.wprp ORT ETW dynamic logging that improves ORT diagnosability & performance (#18882) 2024-01-11 12:43:27 -08:00
ORT_icon_for_light_bg.png
packages.config Update DML to 1.14.1 (#20380) 2024-04-18 22:43:41 -07:00
pyproject.toml Bump ruff to 0.3.2 and black to 24 (#19878) 2024-03-13 10:00:32 -07:00
README.md Update README.md (#18963) 2024-01-03 17:26:25 -08:00
requirements-dev.txt ONNX 1.15 integration (#17125) 2023-09-26 14:44:48 -07:00
requirements-doc.txt
requirements-lintrunner.txt Bump ruff to 0.3.2 and black to 24 (#19878) 2024-03-13 10:00:32 -07:00
requirements-training.txt ONNX 1.15 integration (#17125) 2023-09-26 14:44:48 -07:00
requirements.txt.in
SECURITY.md
setup.py Introducing ORTPipelineModule - DeepSpeed Parallel Pipeline Support. (#20287) 2024-04-18 11:30:15 -07:00
ThirdPartyNotices.txt Fix HalideIR title in third party notices reference (#20190) 2024-04-05 11:12:43 -07:00
VERSION_NUMBER [ORT 1.17.0 release] Bump up version to 1.18.0 (#19170) 2024-01-17 11:18:32 -08:00

ONNX Runtime is a cross-platform inference and training machine-learning accelerator.

ONNX Runtime inference can enable faster customer experiences and lower costs, supporting models from deep learning frameworks such as PyTorch and TensorFlow/Keras as well as classical machine learning libraries such as scikit-learn, LightGBM, XGBoost, etc. ONNX Runtime is compatible with different hardware, drivers, and operating systems, and provides optimal performance by leveraging hardware accelerators where applicable alongside graph optimizations and transforms. Learn more →

ONNX Runtime training can accelerate the model training time on multi-node NVIDIA GPUs for transformer models with a one-line addition for existing PyTorch training scripts. Learn more →

Get Started & Resources

Builtin Pipeline Status

System Inference Training
Windows Build Status
Build Status
Build Status
Linux Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Mac Build Status
Android Build Status
iOS Build Status
Web Build Status
Other Build Status

Third-party Pipeline Status

System Inference Training
Linux Build Status

Data/Telemetry

Windows distributions of this project may collect usage data and send it to Microsoft to help improve our products and services. See the privacy statement for more details.

Contributions and Feedback

We welcome contributions! Please see the contribution guidelines.

For feature requests or bug reports, please file a GitHub Issue.

For general discussion or questions, please use GitHub Discussions.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

This project is licensed under the MIT License.