Skip to content

fix: torch compile default to inductor on cpu#673

Open
gsprochette wants to merge 2 commits into
mainfrom
fix/torch-compile-default-to-inductor-on-cpu
Open

fix: torch compile default to inductor on cpu#673
gsprochette wants to merge 2 commits into
mainfrom
fix/torch-compile-default-to-inductor-on-cpu

Conversation

@gsprochette

Copy link
Copy Markdown
Collaborator

Description

This PR makes inductor the default for torch compile on CPU. Doing this moves away from openvino which fails on some architectures due to some known shape checks in openvino.

With a very quick benchmark of torchvision.models.vit_b_16 on CPU with both torch 2.11 and 2.12, the compiled model with inductor backend also runs slightly faster than the openvino one (41ms with 0.3ms uncertainty for openvino vs 39ms with 0.2ms uncertainty for inductor, on torch 2.12). Hence this change should not affect performance, or even improve them.

Related Issue

Fixes tests/algorithms/test_algorithms.py::test_full_integration[TestTorchCompile_shufflenet-cpu]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactor (no functional change)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Testing

  • I added or updated tests covering my changes
  • Existing tests pass locally (uv run pytest -m "cpu and not slow")

The tests/algorithms/test_algorithms.py::test_full_integration[TestTorchCompile_shufflenet-cpu] usually only passes because of the retry, which for some reason uses cached states on the second run avoiding the faulty shape assumptions. This can be reproduced with the following bash code that needs to run at the root of the pruna project, with your venv activated:

set -euo pipefail

# Should be run from the root of the pruna repository.
if [[ "$(basename "$PWD")" != "pruna" ]]; then
  echo "Error: This script must be run from the 'pruna' directory." >&2
  exit 1
fi
if [[ ! -d "./src/pruna" ]]; then
  echo "Error: './src/pruna' directory does not exist. Are you in the correct directory?" >&2
  exit 1
fi

# Clean up compilation artifacts
USER_TAG="$(whoami | tr '/:*?"<>|\\' '_')"
INDUCTOR_CACHE="${TORCHINDUCTOR_CACHE_DIR:-/tmp/torchinductor_${USER_TAG}}"
rm -rf "$INDUCTOR_CACHE"

# This test fails with a backend error on openvino (something about list index out of range, symbol table,
# or s7 symbol, depending on the torch version).
pytest -o addopts="" tests/algorithms/test_algorithms.py::test_full_integration[TestTorchCompile_shufflenet-cpu]

This test reliably fails on main for me with different versions of torch (+cu126 versions), and passes with the torch inductor switch.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code, especially for agent-assisted changes
  • I updated the documentation where necessary

Thanks for contributing to Pruna! We're excited to review your work.

New to contributing? Check out our Contributing Guide for everything you need to get started.

Note:

  • Draft PRs or PRs without a clear and detailed overview may be delayed.
  • Please mark your PR as Ready for Review and ensure the sections above are filled out.
  • Contributions that are entirely AI-generated without meaningful human review are discouraged.

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@gsprochette gsprochette mentioned this pull request Jun 5, 2026
10 tasks
@begumcig

begumcig commented Jun 8, 2026

Copy link
Copy Markdown
Member

Why were we using openvino in the first place? isn't it only optimal for intel?

@begumcig begumcig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well it makes sense to me that you even got a slightly better performance (assuming you ran this on your company laptop or your workstation, neither uses intel cpus), I don't think our default should be openvino at all and thank you for noticing and changing this!

@begumcig

begumcig commented Jun 8, 2026

Copy link
Copy Markdown
Member

Rerunning the tests that failed due to an internet error, let's wait for them to pass then merge away!!! thanks again <3

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.

2 participants