Skip to content

Why onnxruntime.capi.onnxruntime_inference_collection.InferenceSession.run() takes a lot of time for the first time on a new machine? #4098

Answered by jcwchen
AnkushRR asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @AnkushRR,
It seems like a question for ONNXRuntime. My best guess is in the first run, ONNXRuntime does some optimization for your initial model, which takes additional time. And then the optimized model will replace your original model in place. For later inference, ONNXRuntime won't do those optimization again with the optimized model and therefore inference it with higher speed.

To verify my guess, you can try to get the optimized model by optimized_model_filepath, then directly inference it and see whether it can inference faster in the first run. If the first run still takes much time, please raise this issue in ONNXRuntime to get the best help from the Runtime experts.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AnkushRR
Comment options

Answer selected by zhenhuaw-me
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
runtime Issues related to Runtime for ONNX
2 participants