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 9, 2024
1 parent 1610bc1 commit 9a5874a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkgs/development/python-modules/torch/darwin-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
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")))
12 changes: 12 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,12 @@
{
libraries,
python,
writeShellApplication,
}:
writeShellApplication {
name = "test-torch-darwin";
runtimeInputs = [ (python.withPackages libraries) ];
text = ''
python ${./darwin-check.py}
'';
}
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 9a5874a

Please sign in to comment.