Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196634
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 51ddba5 with merge base f62c80c ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
@pytorchbot label "release notes: inductor" Fixes #196233 — the generated AOTI MPS wrapper discarded both shim return codes, so a Metal compile failure dereferenced a null library handle instead of raising. @yushangdi confirmed the approach on the issue. Could someone add the |
Fixes pytorch#196233. ## Summary `cpp_wrapper_mps.py` generated AOTI code that ignored the return codes from: - `aoti_torch_mps_create_shader_library` - `aoti_torch_mps_get_kernel_function` When shader compilation failed, `aoti_torch_mps_create_shader_library` returned an error without initializing `library_handle`. The generated wrapper then passed the null handle to `aoti_torch_mps_get_kernel_function`, causing a SIGSEGV and discarding the original Metal compiler diagnostic. Wrap both calls with `AOTI_TORCH_ERROR_CODE_CHECK`, matching every other `cpp_wrapper` backend (`cpp_wrapper_cpu.py`, `cpp_wrapper_cpu_array_ref.py`, `cpp_wrapper_gpu.py`) and the hand-written consumer of this same shim API in `test/cpp_extensions/libtorch_agn_2_14_extension/csrc/mps/mps_set_arg_bytes_test.cpp`, which wraps every one of these calls. `cpp_wrapper_mps.py` was the only `cpp_wrapper` backend that did not reference the macro at all. Also move the shader-library handle into its `unique_ptr` immediately after a successful create call. With the new error check, ownership must be established before the subsequent kernel-function lookup to avoid leaking the library on failure. Update the `codegen_additional_funcs` docstring to match the generated code. ## Test plan ```bash python test/inductor/test_mps_basic.py MPSBasicTestsAOTI.test_shader_compile_error_raises python test/inductor/test_mps_basic.py MPSBasicTestsAOTI.test_kernel_function_lookup_error_raises python test/inductor/test_mps_basic.py python test/inductor/test_aot_inductor.py AOTInductorTestABICompatibleMps spin quicklint ``` ### Regression coverage One test per shim call. Each forces a real failure and asserts the diagnostic reaches Python; each segfaults without the fix. - `test_shader_compile_error_raises` injects invalid MSL, so `aoti_torch_mps_create_shader_library` fails. - `test_kernel_function_lookup_error_raises` renames the kernel symbol, so the library compiles but `aoti_torch_mps_get_kernel_function` cannot find `generated_kernel`. This covers the second call, which the first test never reaches because it fails earlier. Before this change both segfault with no output: ```bash $ python test/inductor/test_mps_basic.py MPSBasicTestsAOTI.test_shader_compile_error_raises; echo "exit=$?" exit=139 $ python test/inductor/test_mps_basic.py MPSBasicTestsAOTI.test_kernel_function_lookup_error_raises; echo "exit=$?" exit=139 ``` After: ```bash $ python test/inductor/test_mps_basic.py MPSBasicTestsAOTI.test_shader_compile_error_raises MPSBasicTestsAOTI.test_kernel_function_lookup_error_raises .. ---------------------------------------------------------------------- Ran 2 tests in 4.642s OK ``` ### Results | Test | Result | |---|---| | `test/inductor/test_mps_basic.py` | 63 run, 63 passed | | `test/inductor/test_aot_inductor.py` (MPS class) | 386 run: 196 passed, 157 skipped, 33 expected failures | | `spin quicklint` | Passed | ## Environment - macOS 15.5, arm64 - Apple M4 Pro - `2.15.0a0+gitf62c80c`, built from source - No CUDA available; non-MPS `test_aot_inductor.py` device classes were not run locally Note: pytorch#195587 currently prevents editable builds from resolving shader `#include`s because `torch/include` is absent. Full-suite results above used a local `torch/include/c10 -> ../../c10` symlink. Without that workaround, Metal shader compilation fails due to the unrelated issue; this PR now reports the shim error rather than segfaulting. The two regression tests pass with or without the workaround. ## BC-breaking? No. Successful generated code is unchanged; only error handling on failure paths changes. ## Follow-ups Out of scope for this PR: - Add return-code checks for other emitted `aoti_torch_mps_*` calls. - Fix JIT `cpp_wrapper` on MPS, which currently fails on main with `undeclared identifier 'get_mps_lib_0_handle'`. *** The implementation was prepared with an AI assistant (Claude) and reviewed and validated by the author. The reproduction, negative control, and suite runs were executed locally on the environment above. Co-Authored-By: Claude Opus 5 <[email protected]>
74e3541 to
51ddba5
Compare
|
@pytorchbot merge -f "Lint + MPS are green, though test location is wrong" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes #196233.
Summary
cpp_wrapper_mps.pygenerated AOTI code that ignored the return codes from:aoti_torch_mps_create_shader_libraryaoti_torch_mps_get_kernel_functionWhen shader compilation failed,
aoti_torch_mps_create_shader_libraryreturned an error without initializinglibrary_handle. The generated wrapper then passed the null handle toaoti_torch_mps_get_kernel_function, causing a SIGSEGV and discarding the original Metal compiler diagnostic.Wrap both calls with
AOTI_TORCH_ERROR_CODE_CHECK, matching every othercpp_wrapperbackend (cpp_wrapper_cpu.py,cpp_wrapper_cpu_array_ref.py,cpp_wrapper_gpu.py) and the hand-written consumer of this same shim API intest/cpp_extensions/libtorch_agn_2_14_extension/csrc/mps/mps_set_arg_bytes_test.cpp, which wraps every one of these calls.cpp_wrapper_mps.pywas the onlycpp_wrapperbackend that did not reference the macro at all.Also move the shader-library handle into its
unique_ptrimmediately after a successful create call. With the new error check, ownership must be established before the subsequent kernel-function lookup to avoid leaking the library on failure.Update the
codegen_additional_funcsdocstring to match the generated code.Test plan
Regression coverage
One test per shim call. Each forces a real failure and asserts the diagnostic
reaches Python; each segfaults without the fix.
test_shader_compile_error_raisesinjects invalid MSL, soaoti_torch_mps_create_shader_libraryfails.test_kernel_function_lookup_error_raisesrenames the kernel symbol, so thelibrary compiles but
aoti_torch_mps_get_kernel_functioncannot findgenerated_kernel. This covers the second call, which the first test neverreaches because it fails earlier.
Before this change both segfault with no output:
After:
$ python test/inductor/test_mps_basic.py MPSBasicTestsAOTI.test_shader_compile_error_raises MPSBasicTestsAOTI.test_kernel_function_lookup_error_raises .. ---------------------------------------------------------------------- Ran 2 tests in 4.642s OKResults
test/inductor/test_mps_basic.pytest/inductor/test_aot_inductor.py(MPS class)spin quicklintEnvironment
2.15.0a0+gitf62c80c, built from sourcetest_aot_inductor.pydevice classes were not run locallyNote: #195587 currently prevents editable builds from resolving shader
#includes becausetorch/includeis absent. Full-suite results above used a localtorch/include/c10 -> ../../c10symlink. Without that workaround, Metal shader compilation fails due to the unrelated issue; this PR now reports the shim error rather than segfaulting. The two regression tests pass with or without the workaround.BC-breaking?
No. Successful generated code is unchanged; only error handling on failure paths changes.
Follow-ups
Out of scope for this PR:
aoti_torch_mps_*calls.cpp_wrapperon MPS, which currently fails on main withundeclared identifier 'get_mps_lib_0_handle'.The implementation was prepared with an AI assistant (Claude) and reviewed and validated by the author. The reproduction, negative control, and suite runs were executed locally on the environment above.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo