Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mps data to CPU in util.to_numpy #884

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions skorch/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ def test_invalid_inputs(self, to_numpy, x_invalid):
expected = "Cannot convert this data type to a numpy array."
assert e.value.args[0] == expected

@pytest.mark.skipif(
not (hasattr(torch.backends, "mps") and torch.backends.mps.is_available()),
reason='Skipped because mps is not available as a torch backend'
)
def test_mps_support(self, to_numpy, x_tensor):
device = torch.device('mps')
x_tensor.to(device)
x_numpy = to_numpy(x_tensor)
self.compare_array_to_tensor(x_numpy, x_tensor)


class TestToDevice:
@pytest.fixture
Expand Down
3 changes: 3 additions & 0 deletions skorch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def to_numpy(X):
if X.is_cuda:
X = X.cpu()

if hasattr(X, 'is_mps') and X.is_mps:
X = X.cpu()

if X.requires_grad:
X = X.detach()

Expand Down