Make MPS op imports side-effect safe during package discovery - #4675
Conversation
…compile_and_package never fuses quantized Linear into onednn::qlinear_pointwise (silent fp32 fallback) Closes pytorch#4566
|
Hi @saisharan0103! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
🔗 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 FailureAs of commit c88c80f with merge base bfbc842 ( 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:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Fixes #4566.
pkgutil.walk_packages(torchao.__path__)can importtorchao.experimental.ops.mpswhile 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 andlibtorchao_ops_mps_aten.dylibare not available. The unconditional_load_torchao_mps_lib()call intorchao.experimental.ops.mps.__init__raisesRuntimeError, andpkgutil.walk_packagesonly suppressesImportError, 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.pythat verifiespkgutil.walk_packages(torchao.__path__)completes without an unhandledRuntimeError.ruff check test/test_lean_import.py torchao/experimental/ops/mps/__init__.py torchao/experimental/ops/mps/utils.pyreports no new findings on the changed files.Ran
pytest -xlocally with no new failures.