Add support in Python API for the recommended max working set size. (#128289) Adds ways for users to request recommended max size for Metal on Mac. It plumbs through https://developer.apple.com/documentation/metal/mtldevice/2369280-recommendedmaxworkingsetsize?language=objc Can be used like ``` max_memory = torch.mps.recommended_max_memory() print ("Recommended Max Memory : ", (max_memory/(1024*1024*1024)), "GB") ``` Co-authored-by: Nikita Shulga <[email protected]> Pull Request resolved: https://github.com/pytorch/pytorch/pull/128289 Approved by: https://github.com/malfet
diff --git a/test/test_mps.py b/test/test_mps.py index 00fc5c0..c59a598 100644 --- a/test/test_mps.py +++ b/test/test_mps.py
@@ -7893,6 +7893,11 @@ self.assertTrue(current_alloc_after > current_alloc_before) self.assertTrue(driver_alloc_after > driver_alloc_before) + def test_mps_allocator_stats(self): + max_memory = torch.mps.recommended_max_memory() + print(f"Recommended Max Memory : {max_memory/ 1024 ** 3} GB") + self.assertTrue(max_memory > 0) + # to verify this test, run XCode Instruments "Metal System Trace" or "Logging" tool, # press record, then run this python test, and press stop. Next expand # the os_signposts->PyTorchMPS and check if events or intervals are logged