[BE] [MPS] Fix `out` resize logic in `torch.where` (#121476) By deleting `where_mps` and registering MPS dispatch for `where_kernel`. As result of this change resizing and type-checking logic is shared between MPS, CPU and CUDA backends. Add test_case to `TestMPS.test_where` (that should eventually be removed, when `out` OpInfo testing is enabled for MPS Pull Request resolved: https://github.com/pytorch/pytorch/pull/121476 Approved by: https://github.com/albanD, https://github.com/Skylion007 ghstack dependencies: #121473, #121494
diff --git a/test/test_mps.py b/test/test_mps.py index af26cbb..3c5e47c 100644 --- a/test/test_mps.py +++ b/test/test_mps.py
@@ -7475,6 +7475,15 @@ helper((2, 3), (5, 2, 3), (2, 3)) helper((2, 3), (2, 3), (5, 2, 3)) helper((2, 3), (5, 2, 3), (6, 5, 2, 3)) + # Test that output is correctly resizes + # TODO: Remove me when out OpInfo testing is enabled on MPS + output = torch.tensor(0.0, device="mps") + cond = torch.randint(2, (3, 3), dtype=torch.bool, device="mps") + inp = torch.rand(3, 3, device="mps") + other = torch.rand(3, 3, device="mps") + out = torch.where(cond, inp, other, out=output) + self.assertEqual(id(out), id(output)) + self.assertEqual(out.shape, (3, 3)) # Test normal def test_normal(self):