Repository navigation
Conversation
test_64bit_binops checks unary and binary ops on a 5000x1024x1024 fp16 tensor (9.77 GiB) to cover the 32-bit split added in pytorch#155183. Writing `(a + b).sin()` keeps the sum and its sine alive together, a ~21 GB peak, while the guard only requires recommended_max_memory() >= 16 GB. On a 24 GB Mac (17.76 GiB working set) the test fails every time with kIOGPUCommandBufferCallbackErrorOutOfMemory. On CI's macos-m2-15 runners it used 92% of their 21.3 GiB working set and was disabled as flaky in pytorch#190665 after returning wrong values and running out of memory on reruns. Compute the sine in place so only one 10 GB tensor is alive, and free the tensors at the end like the other TestLargeTensors tests. sin_ goes through the same split in exec_unary_kernel as sin. Raising the guard instead would skip the test on 24 GB Macs and leave it at the edge on the CI runners. Test Plan: On an Apple M4 Pro (24 GB, macOS 27.0.1): ``` PYTORCH_TEST_WITH_SLOW=1 python test/test_mps.py TestLargeTensors.test_64bit_binops PYTORCH_TEST_WITH_SLOW=1 python test/test_mps.py TestLargeTensors spin quicklint ``` Before, test_64bit_binops raised OutOfMemoryError. After, it passes in 3 of 3 runs, the class passes, and 2 to 4 of the 64-bit cat tests that run after it no longer skip for insufficient memory. With exec_unary_kernel temporarily changed to dispatch only its first 32-bit chunk, the patched test fails with 98.6% of the checked elements wrong, so it still covers the 64-bit unary path. This change was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201836
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 776d6a3 with merge base 3c53c6f ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@pytorchbot label "topic: not user facing" |
|
One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via: Supported
Alternatively, if the co-author should not be included, remove the Please update your commit message(s) by doing |
|
Please follow contributing guidelines |
|
alright, I have changed it back to draft and I'll wait for #201835 to be marked actionable :) |
| rc_slice_cpu = (a.cpu() + b.cpu()[slice_idx:]).sin() | ||
| self.assertEqual(rc_slice, rc_slice_cpu) | ||
| del a, b, rc, rc_slice | ||
| gc.collect() |
There was a problem hiding this comment.
Why do you need this one? I.e. there are no reference cycles and no backward, so del should free them right away
There was a problem hiding this comment.
Thats true, no harm using it, but there is no need to add this. The main issue is the torch.mps.recommended_max_memory() < 16_000_000_000 which was initially not entirely correct.
|
@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 |
Linked issue or supporting maintainer
Fixes #201835
BC-breaking?
No
Summary (human written only)
The test_mps function test_64bits_binops assumes <= 16 GiB of GPU Mem is required, however, this is not the case due to broadcasting where a + b makes a 9.77 GiB tensor and another .sin() makes a second 9.77 GiB, where the sum becomes 9.77 GiB * 2 > 16 GiB.
Using .sin_() writes the result back to the first tensor, so it only use a total of 9.77 GiB of memory well below 16 GiB.
From the code, it continues the test if GPU Mem > 16 GiB which is not true.
pytorch/test/test_mps.py
Lines 10531 to 10532 in 3c53c6f
Agent details (if applicable)
🤖 Generated with Claude Code