Skip to content

Conversation

@ingyukoh
Copy link

Move sympy from required to optional dependencies. Users doing inference-only don't need
symbolic math library.

  • Guard sympy import in symbolic_shape_infer.py with helpful error message
  • Remove sympy from requirements.txt
  • Add sympy to extras_require["symbolic"] in setup.py

Users can now install with: pip install onnxruntime[symbolic]

Reduces default install size by ~29MB (23%).

Addresses #24872

Description

Make sympy an optional dependency to reduce install size for inference-only users.

Changes:

  • Guard sympy import in symbolic_shape_infer.py with helpful ImportError
  • Remove sympy from requirements.txt (no longer auto-installed)
  • Add sympy to extras_require["symbolic"] in setup.py

Motivation and Context

sympy is ~29MB (23% of total package size) but only used for symbolic shape inference.
Most users doing inference-only don't need it.

After this change:

  • pip install onnxruntime → no sympy (smaller install)
  • pip install onnxruntime[symbolic] → includes sympy

Move sympy from required to optional dependencies.
Users doing inference-only don't need symbolic math library.

- Guard sympy import in symbolic_shape_infer.py with helpful error message
- Remove sympy from requirements.txt
- Add sympy to extras_require["symbolic"] in setup.py

Users can now install with: pip install onnxruntime[symbolic]

Reduces default install size by ~29MB (23%).

Addresses microsoft#24872

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ingyukoh
Copy link
Author

ingyukoh commented Feb 4, 2026

Hi maintainers — CI is blocked by ‘workflows awaiting approval’ (28 pending). Could someone please approve running workflows and take a look? This PR makes sympy optional and adds onnxruntime[symbolic] for users who need symbolic shape inference. Addresses #24872

try:
import sympy
except ImportError:
raise ImportError(

Check notice

Code scanning / lintrunner

RUFF/B904 Note

Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling.
See https://docs.astral.sh/ruff/rules/raise-without-from-inside-except
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.

1 participant