Skip to content
Draft
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
16 changes: 11 additions & 5 deletions test/dynamo/test_guard_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import abc
import functools
import inspect
import unittest
import weakref

import torch
Expand Down Expand Up @@ -257,8 +256,12 @@ def test_default_device_guard(self):
guard = guards.DEFAULT_DEVICE(root, ["cpu device"], None)
self.assertTrue(guard(foo))

if not torch.accelerator.is_available():
self.skipTest("Accelerator is not available")

try:
torch.set_default_device("cuda")
device = torch.accelerator.current_accelerator()
torch.set_default_device(device)
self.assertFalse(guard(foo))
finally:
torch.set_default_device(None)
Expand Down Expand Up @@ -448,11 +451,14 @@ def test_weakref_alive_guard(self):
del x
self.assertFalse(guard(weakref_x()))

@unittest.skipIf(not torch.accelerator.is_available(), "requires accelerator")
@requires_cuda
def test_call_function_no_args_guard(self):
if not torch.accelerator.is_available():
self.skipTest("Accelerator is not available")

root = RootGuardManager()
x = torch.cuda.current_device()
device = torch.accelerator.current_accelerator()
# Use device.index which is device-agnostic (works on all accelerators)
x = device.index if device.index is not None else 0
guard = guards.EQUALS_MATCH(root, x, [0], None)
self.assertTrue(guard(0))
self.assertFalse(guard(1))
Expand Down
Loading