-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python3Packages.torch.tests.tester-darwin
Tests for Darwin. Both CPU and MPS are tested. Signed-off-by: Mika Tammi <[email protected]>
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
cudaPackages, | ||
libraries, | ||
pythonPackages, | ||
}: | ||
(cudaPackages.writeGpuTestPython.override { python3Packages = pythonPackages; }) | ||
{ | ||
inherit libraries; | ||
name = "torch-darwin-check"; | ||
} | ||
'' | ||
import torch | ||
def opt_foo2(x, y): | ||
a = torch.sin(x) | ||
b = torch.cos(y) | ||
return a + b | ||
print("Testing CPU") | ||
print( | ||
opt_foo2( | ||
torch.randn(10, 10), | ||
torch.randn(10, 10))) | ||
print("Testing MPS") | ||
assert torch.backends.mps.is_built(), "PyTorch not built with MPS enabled" | ||
if not torch.backends.mps.is_available(): | ||
print("MPS not available because the current MacOS version is not 12.3+ " | ||
"and/or you do not have an MPS-enabled device on this machine.") | ||
else: | ||
print( | ||
opt_foo2( | ||
torch.randn(10, 10, device="mps"), | ||
torch.randn(10, 10, device="mps"))) | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters