Skip to content

Raise an actionable error when onnxruntime is not installed - #2736

Merged
Xiaoyu Z (xiaoyu-work) merged 5 commits into
microsoft:mainfrom
Iyanuoluwa007:friendly-missing-onnxruntime-error
Nov 5, 2026
Merged

Xiaoyu Z (xiaoyu-work) merged 5 commits into
microsoft:mainfrom
Iyanuoluwa007:friendly-missing-onnxruntime-error

Conversation

@Iyanuoluwa007

@Iyanuoluwa007 Oke Iyanuoluwa Enoch (Iyanuoluwa007) commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes

onnxruntime is not an Olive dependency, so installing only olive-ai and running a workflow (for example olive auto-opt ... --device cpu) used to fail in get_ort_available_providers with a bare ModuleNotFoundError: No module named 'onnxruntime'.

get_ort_available_providers now raises ImportError("onnxruntime is not installed.") in that case, chained to the original error. Other import failures, such as a missing dependency of an installed onnxruntime, are re-raised unchanged.

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
    Running Olive without onnxruntime installed now reports that onnxruntime is not installed.

(Optional) Issue link

Fixes #2284

Running a workflow after installing only the base olive-ai package failed
with a bare "ModuleNotFoundError: No module named 'onnxruntime'" from
get_ort_available_providers. Explain that an ONNX Runtime package is needed
and which olive-ai extra installs it.

Fixes microsoft#2284
Copilot AI balanced review requested due to automatic review settings October 16, 2026 18:59
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The broad exception handler mislabels native-library and dependency failures as a missing ONNX Runtime installation.

1 open finding
What changed in this PR

Improves Olive’s missing-ONNX-Runtime error with installation guidance, addressing the workflow failure reported in #2284.

Changes:

  • Adds device-specific installation instructions and chains the original exception.
  • Adds regression coverage for a missing ONNX Runtime package.
File Description
test/​common/​test_ort_inference.py Tests the actionable missing-package error.
olive/​common/​ort_inference.py Adds installation guidance to import failures.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread olive/common/ort_inference.py Resolved
@Iyanuoluwa007

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The targeted change preserves unrelated import errors and includes regression coverage, with no unresolved findings.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Comment thread olive/common/ort_inference.py Resolved
Per review: the error now just says that onnxruntime is not installed, and
the tests added for it are removed.
@xiaoyu-work

Copy link
Copy Markdown
Member

can you update branch to merge main?

@Iyanuoluwa007

Copy link
Copy Markdown
Contributor Author

Done, merged the latest main into the branch (d231f14).

@xiaoyu-work
Xiaoyu Z (xiaoyu-work) enabled auto-merge (squash) November 5, 2026 21:27
@xiaoyu-work
Xiaoyu Z (xiaoyu-work) merged commit ea6ae28 into microsoft:main Nov 5, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

example docs is missing dependencies: ModuleNotFoundError: No module named 'onnxruntime'

3 participants