Skip to content

Conversation

@soof-golan
Copy link
Contributor

  • Add nansum_out_mps and nansum_mps functions
  • Moved get_dtype_from_self into ReduceOpsUtils.h

Fixes #86809

@pytorch-bot
Copy link

pytorch-bot bot commented Feb 1, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit e921ed1:
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added ciflow/mps Run MPS tests (subset of trunk) release notes: mps Release notes category labels Feb 1, 2023
@soof-golan soof-golan marked this pull request as ready for review February 1, 2023 14:23
@soof-golan soof-golan requested a review from kulinseth as a code owner February 1, 2023 14:23
@malfet malfet added the topic: improvements topic category label Feb 2, 2023
test/test_mps.py Outdated
Comment on lines 8190 to 8234
def helper(self, dtype, noncontiguous, dim):
zero_cpu = torch.zeros((), dtype=dtype)

# Randomly scale the values
scale = random.randint(10, 100)
x_cpu: torch.Tensor = make_tensor(
(5, 5), dtype=dtype, device='cpu',
low=-scale, high=scale, noncontiguous=noncontiguous)

if dtype.is_floating_point:
nan_mask_cpu = x_cpu < (0.2 * scale)
x_no_nan_cpu = torch.where(nan_mask_cpu, zero_cpu, x_cpu)
x_cpu[nan_mask_cpu] = np.nan
else:
x_no_nan_cpu = x_cpu

x_mps = x_cpu.to('mps')
actual_out_mps = torch.empty(0, dtype=dtype, device='mps')
expect_out_cpu = torch.empty(0, dtype=dtype)
dim_kwargs = {"dim": dim} if dim is not None else {}
expect = torch.sum(x_no_nan_cpu, **dim_kwargs)

actual_cpu = torch.nansum(x_cpu, **dim_kwargs)
# Sanity check on CPU
self.assertEqual(expect, actual_cpu)

# Test MPS
actual_mps = torch.nansum(x_mps, **dim_kwargs)
# Test out= variant
torch.nansum(x_mps, out=actual_out_mps, **dim_kwargs)
torch.nansum(x_cpu, out=expect_out_cpu, **dim_kwargs)
self.assertEqual(expect, actual_mps)
self.assertEqual(expect_out_cpu, actual_out_mps)

def test_nansum(self):
args = itertools.product(
(torch.float16, torch.float32, torch.int32, torch.int64), # dtype
(True, False), # noncontiguous
(0, 1, None), # dim
)

for dtype, noncontiguous, dim in args:
with self.subTest(dtype=dtype, noncontiguous=noncontiguous, dim=dim):
self.helper(dtype, noncontiguous, dim)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't make it a new class, but rather add as a method to say test_consistency (and actually, can't it just be added using opinfo?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure how to add it with opinfo, I might be missing something, could you give me some guidance?

I tried running EXPECTTEST_ACCEPT=1 python test_mps.py TestConsistencyCPU per the instructions in TestConsistency and the interpreter crashes on unrelated things (e.g. unssuported type conversions like cdouble)

As a default I'll update the PR and move test_nansum into TestMps as a method, but helping me test this with opinfo would be very appreciated :)

* Add nansum_out_mps and nansum_mps functions
* Moved `get_dtype_from_self` into ReduceOpsUtils.h
@soof-golan soof-golan requested review from malfet and removed request for kulinseth February 8, 2023 12:50
@soof-golan
Copy link
Contributor Author

@pytorchmergebot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Feb 9, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mps Run MPS tests (subset of trunk) ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: mps Release notes category topic: improvements topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MPS] Add support for aten::nansum for MPS backend

4 participants