Skip to content
Open
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
21 changes: 13 additions & 8 deletions torchtnt/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ def captured_output() -> Generator[Tuple[TextIO, TextIO], None, None]:


"""Decorator for tests to ensure running on a GPU."""
skip_if_not_gpu: Callable[..., Callable[..., object]] = unittest.skipUnless(
torch.cuda.is_available(), "Skipping test since GPU is not available"
)

"""Decorator for tests to ensure running when distributed is available."""
skip_if_not_distributed: Callable[..., Callable[..., object]] = unittest.skipUnless(
torch.distributed.is_available(), "Skipping test since distributed is not available"
)
def skip_if_not_gpu(func: Callable) -> Callable:
"""Decorator that checks for GPU availability at decoration time."""
return unittest.skipUnless(
torch.cuda.is_available(),
"Skipping test since GPU is not available"
)(func)

def skip_if_not_distributed(func: Callable) -> Callable:
"""Decorator that checks for distributed availability at decoration time."""
return unittest.skipUnless(
torch.distributed.is_available(),
"Skipping test since distributed is not available"
)(func)