Skip to content

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

Open
Oke Iyanuoluwa Enoch (Iyanuoluwa007) wants to merge 3 commits into
microsoft:mainfrom
Iyanuoluwa007:friendly-missing-onnxruntime-error
Open

Oke Iyanuoluwa Enoch (Iyanuoluwa007) wants to merge 3 commits into
microsoft:mainfrom
Iyanuoluwa007:friendly-missing-onnxruntime-error

Conversation

@Iyanuoluwa007

Copy link
Copy Markdown

Describe your changes

Installing only the base olive-ai package and running a workflow (for example olive auto-opt ... --device cpu) fails in get_ort_available_providers with a bare ModuleNotFoundError: No module named 'onnxruntime', which does not tell the user what to install.

get_ort_available_providers now catches the import failure and raises an ImportError that explains an ONNX Runtime package is required and names the matching extras (olive-ai[cpu], olive-ai[gpu], olive-ai[directml]). The original exception is chained.

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass. (pytest test/common/test_ort_inference.py: 9 passed)
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a (ruff 0.15.11 check and format on changed files)
  • 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 which package or extra to install.

(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 Outdated
@Iyanuoluwa007

Copy link
Copy Markdown
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

This branch has not been deployed

No deployments
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'

2 participants