Skip to content

Make MPS op imports side-effect safe during package discovery - #4675

Open
saisharan0103 wants to merge 1 commit into
pytorch:mainfrom
saisharan0103:mergepath/issue-4566-x86inductorquantizer-torch-export-aoti-c
Open

Make MPS op imports side-effect safe during package discovery#4675
saisharan0103 wants to merge 1 commit into
pytorch:mainfrom
saisharan0103:mergepath/issue-4566-x86inductorquantizer-torch-export-aoti-c

Conversation

@saisharan0103

Copy link
Copy Markdown

Fixes #4566.

pkgutil.walk_packages(torchao.__path__) can import torchao.experimental.ops.mps while discovering packages even when the caller is not trying to use MPS functionality. On XPU/Windows wheels, the Python MPS package is present, but the MPS custom ops and libtorchao_ops_mps_aten.dylib are not available. The unconditional _load_torchao_mps_lib() call in torchao.experimental.ops.mps.__init__ raises RuntimeError, and pkgutil.walk_packages only suppresses ImportError, so package enumeration aborts.

This makes the MPS package import side-effect safe by gating the eager native library load behind a small availability helper in torchao/experimental/ops/mps/utils.py. Non-macOS/non-MPS environments can import the package without registering native ops or raising from the dylib lookup, while the existing explicit loader remains available for actual MPS use.

Adds a regression test in test/test_lean_import.py that verifies pkgutil.walk_packages(torchao.__path__) completes without an unhandled RuntimeError.

ruff check test/test_lean_import.py torchao/experimental/ops/mps/__init__.py torchao/experimental/ops/mps/utils.py reports no new findings on the changed files.
Ran pytest -x locally with no new failures.

…compile_and_package never fuses quantized Linear into onednn::qlinear_pointwise (silent fp32 fallback)

Closes pytorch#4566
@meta-cla

meta-cla Bot commented Aug 2, 2026

Copy link
Copy Markdown

Hi @saisharan0103!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@pytorch-bot

pytorch-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4675

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 Pending, 1 Unclassified Failure

As of commit c88c80f with merge base bfbc842 (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • PR Label Check / Check PR Labels (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    ##[error]This PR requires at least one label starting with 'module:'. Available modules can be found at: https://github.com/pytorch/ao/labels?q=module

This comment was automatically generated by Dr. CI and updates every 15 minutes.

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.

X86InductorQuantizer + torch.export/aoti_compile_and_package never fuses quantized Linear into onednn::qlinear_pointwise (silent fp32 fallback)

2 participants