Skip to content
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

[Performance]Why is loading an ONNX model taking so long? #23338

Open
MoniqueSciortino opened this issue Jan 13, 2025 · 6 comments
Open

[Performance]Why is loading an ONNX model taking so long? #23338

MoniqueSciortino opened this issue Jan 13, 2025 · 6 comments
Labels
core runtime issues related to core runtime performance issues related to performance regressions

Comments

@MoniqueSciortino
Copy link

Describe the issue

I am using Visual Studio 2022 and onnxruntime downloaded from Manage NuGet Packages. My onnx file of size 915MB (random forest with 500 trees) is taking ages to load using the following code.

To reproduce

#include
#include <onnxruntime_cxx_api.h>

using namespace std;

int main() {
const std::string model_s = "C:/Users/moniq/Downloads/MgarrRFModel.onnx";
std::basic_string<ORTCHAR_T> model = std::basic_string<ORTCHAR_T>(model_s.begin(), model_s.end());

// onnxruntime setup
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "ONNXModelLoader");
Ort::SessionOptions session_options;
session_options.SetIntraOpNumThreads(4);
Ort::Session session = Ort::Session(env, model.c_str(), session_options);
std::cout << "number of model input:" << session.GetInputCount() << std::endl;
std::cout << "number of model Output:" << session.GetOutputCount() << std::endl;

return 0;

}

Urgency

Urgent

Platform

Windows

OS Version

24h2

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

latest on

ONNX Runtime API

C++

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Model File

No response

Is this a quantized model?

Yes

@MoniqueSciortino MoniqueSciortino added the performance issues related to performance regressions label Jan 13, 2025
@github-actions github-actions bot added the .NET Pull requests that update .net code label Jan 13, 2025
@yuslepukhin
Copy link
Member

Without seeing a model, it is hard to say. However, if your model has lots of functions, it may take time to inline them. Optimizations may take time.
My suggestion is to pre-optimize your model with either ONNX optimizer or ONNXRuntime optimizer and save it for repeated runs, your loading time will decrease dramatically.

@yuslepukhin yuslepukhin added core runtime issues related to core runtime and removed .NET Pull requests that update .net code labels Jan 13, 2025
@MoniqueSciortino
Copy link
Author

Thanks for your suggestion. Can you provide help on how to optimize it please?

@yuslepukhin
Copy link
Member

You try this in C++ (although in Python it is quicker)

@MoniqueSciortino
Copy link
Author

Thank you, I'll try it out

@MoniqueSciortino
Copy link
Author

MoniqueSciortino commented Jan 14, 2025

Is there any way I can share the .onnx file with you? With optimization, it is still taking quite a long time (almost two hours - more than without optimization).

@yuslepukhin
Copy link
Member

You can zip it up and put on a cloud provider of your choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core runtime issues related to core runtime performance issues related to performance regressions
Projects
None yet
Development

No branches or pull requests

2 participants