Repository navigation
[Feature Refactoring]Parameterize device type checks in cpp_wrapper_mps - #196250
gavinwang269 wants to merge 1 commit into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (4): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196250
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 Cancelled Jobs, 1 Unrelated FailureAs of commit 992117b with merge base 2e10e9e ( NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
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. |
6704540 to
2079966
Compare
|
Hi @desertfire — could you review this? |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
2079966 to
3dd6200
Compare
|
@pytorchbot review |
|
The automated review only re-runs on PRs labeled |
|
@desertfire this is now ready for review -- thank you for the What the PR does, in one paragraph: Two things I cannot do from this account and would appreciate help with:
The branch is two days behind trunk, so I am asking the bot to rebase it onto @pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
3dd6200 to
ef40678
Compare
9835b31 to
992117b
Compare
|
cc @jansel - the automated review rounds converged (last one: nothing blocking) and @lizhihai137 approved; a re-approve on the current head plus CI approval is all that is left. Scope: cpp_wrapper_mps/cpp_wrapper_gpu read the wrapper's own device field instead of hardcoded "mps"/get_gpu_type(), and create() became a factory-correct classmethod - the MPS path is byte-identical on default paths, verified with a generated-code diff harness. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 2 mandatory check(s) failed. The first few are:
Dig deeper by viewing the failures on hud |
|
@pytorchbot recheck |
|
❌ 🤖 pytorchbot command failed: Try |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 2 mandatory check(s) failed. The first few are:
Dig deeper by viewing the failures on hud |
|
The two merge attempts on this PR are failing on infrastructure, not on this diff. Recording the evidence so that someone with permission can either re-run the jobs or force-merge with the reason. Current check state at head In that run (job 130206148298) the The other two cells of that matrix ( Three facts that make this clearly unrelated to the change under review:
Everything else is at the gate already: Could someone re-run the three failed jobs, or: I cannot retry it myself — both |
|
You are not authorized to force merges to this repository. Please use the regular |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 3 checks: Lint / Test collect_env (with_torch, linux.24_04.4x), Lint / Test collect_env (without_torch, linux.24_04.4x), Lint / Test collect_env (older_python_version, linux.24_04.4x) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Summary
CppWrapperMpshardcoded"mps"in two device checks. Both now readself.device— the target-device field the wrapper hierarchy already carries — instead of adding a second concept next to it.Changes (single commit, 4 files):
torch/_inductor/codegen/cpp_wrapper_gpu.py:CppWrapperGpu.__init__keeps a subclass-setdevice(samehasattrpatternCppWrapperCpualready uses) instead of overwriting withget_gpu_type(); the lazy-scratch emitter useswrapper.devicerather than callingget_gpu_type()directly;CppWrapperGpu.createbecomes a classmethod returningcls(), so a subclass that inherits it (e.g. one handed toregister_backend_for_device) is built with its own overrides provided its__init__is argument-freetorch/_inductor/codegen/cpp_wrapper_mps.py: class attributedevice = "mps"; the guard in_generate_kernel_call_helperand the filter incodegen_additional_funcscompare againstself.device, message built from it; the now-redundantcreateoverride is deleted (the base classmethod already returnscls()); the class comment keeps a short contract:devicedrives everything readingself.deviceordevice_codegen(the per-device kernel-driver header included); a retargeting subclass must still overrideget_device_include_path_aotand theaoti_torch_mps_*/AOTIMetal*emission, and matchMetalKernel.device_typeincodegen/mps.pytest/inductor/test_gpu_cpp_wrapper.py: theFakeWrapperintest_lazy_triton_wrapper_forwards_launch_pdlgains thedeviceattribute the realwrappers always have (production-contract fidelity for the lazy-scratch path)
test/inductor/test_cpp_wrapper_asserts.py: six tests driving the production guard and filter paths (base message, matching line emitsget_mps_lib_0_handle, non-matching emits nothing, subclass filter picks its own device's line, subclass guard rejects the base device, create returns the subclass); the fake graph handler is installed viaenterContextso it cannot leak into later testsMotivation
CppWrapperMpsis dispatched per-device viaregister_backend_for_deviceincommon.py, yet the "which device does this class belong to" checks inside the class body were string literals, and the class grew a second target-device concept next to the existingself.devicethat already drivesdevice_codegen(per-device kernel-driver header included), the constant checks and the generateddevice_type. A subclass setting only the second field got an object whose two fields disagreed. Unifying onself.deviceremoves the disagreement by construction. An out-of-tree backend reusing this runtime-shader-library + lazy-handle + callback-launch model no longer needs to hand-edit literals or bypass the factory.Companion to #195809 (same retarget limitation, sibling file).
Test Plan
sources -> 3/10 fail; mps literals restored in the guard/filter only -> the 2 subclass
tests fail; hasattr guard reverted in CppWrapperGpu.init only -> the
init/factory test fails;
createreverted to a staticmethod fails the factory typecheck. The lazy-scratch
wrapper.deviceline is exercised but not discriminated(the fake's
codegen_deviceignores its argument)test_lazy_triton_wrapper_forwards_launch_pdlpasses both parametrizations with the FakeWrapper fixReady once mac CI signal is observed.
Review follow-up (2026-11-05 round)
This revision responds to the automated round on the previous head: the second device field (
device_type) is gone in favour ofself.device(their finding + the Cpu hasattr precedent);create()is a classmethod (factory-contract finding); the fakeV.graphhandler is scoped (leak finding); positive-path assertions were added and the misleadingly named subclass test split into filter+guard pairs (discrimination finding — measured: 3 of the 6 new tests fail on pre-change code).Round 2 (findings on
ceeedf1c9eac) is addressed in the follow-up push: FakeWrapper device attribute, a real-__init__test that fails when the hasattr guard is reverted, the class comment now listing everything the singledevicefield actually retargets, inline raise style, the renamed guard test, module-level subclass/imports, and the@requires_tritongate question stays parked for the same maintainer ruling as #192434.Round 3 (findings on
5b9881e2a60a) addressed in the follow-up push: the two unneeded fakedevicelines were dropped (only the fake reaching_generate_lazy_scratchkeeps the attribute); the factory-test docstring and the guard-revert comment now describe the stubbedCppWrapperCpu.__init__and the classmethod-vs-staticmethod distinction correctly; the cwc/cwg imports moved to module level.Round 4 (review on
2c756fa806a5) addressed in the follow-up push: the class comment is cut to the short contract above (the round-3 wording got the jit-include inheritance and the kernel-driver header wrong); the docstring also covers a class-attributedevice. This paragraph supersedes the merge-readiness claims in the 2026-11-04 comments: the approval onef406784850predates everyCppWrapperGpuchange, and a re-approval on the current head is what counts.Round 5 (review on
b470dbfd171b) addressed in the follow-up push: the redundantCppWrapperMps.createoverride is deleted so the factory test exercises the baseCppWrapperGpu.createclassmethod directly (unused imports dropped, test comment reworded); the out-of-tree behavior change of the basecreateis now stated in both the docstring and this body. The stale-body items that round flagged quoted the round-3 body text that was superseded before its review published; the current body carries the six-tests/four-files counts and the honest witness note.Round 6 (review on
3a9038e4aed6) addressed in the follow-up push: the docstring's create paragraph is now the one-line contract (returnscls(); a subclass that inherits it must have an argument-free__init__) instead of change-history wording, and the Test Plan witness claim was corrected once the Mps override was gone (the base classmethod is witnessed by the factory type check; only the lazy-scratch line stays non-discriminated). One ask for whoever lands this: please add theciflow/mpslabel -- no current job on the PR builds a realCppWrapperMps, and the mac signal is the honest check for the device field path.cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo