Skip to content

Commit

Permalink
python3Packages.torch.tests.tester-darwin
Browse files Browse the repository at this point in the history
Tests for Darwin. Both CPU and MPS are tested.

Signed-off-by: Mika Tammi <[email protected]>
  • Loading branch information
mikatammi committed Nov 8, 2024
1 parent 1610bc1 commit 83a4928
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkgs/development/python-modules/torch/mk-darwin-check.nix
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")))
''
3 changes: 3 additions & 0 deletions pkgs/development/python-modules/torch/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ rec {
feature = "rocm";
libraries = ps: [ ps.torchWithRocm ];
};
tester-darwin = callPackage ./mk-darwin-check.nix {
libraries = ps: [ ps.torch ];
};
}

0 comments on commit 83a4928

Please sign in to comment.