Skip to content

Commit

Permalink
update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli committed Dec 22, 2022
1 parent 46f204b commit 0210d20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/lightning_lite/accelerators/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def find_usable_cuda_devices(num_devices: int = -1) -> List[int]:
visible_devices = _get_all_visible_cuda_devices()
if not visible_devices:
raise ValueError(
f"You requested to find {num_devices} GPUs but there are no visible CUDA devices on this machine."
f"You requested to find {num_devices} devices but there are no visible CUDA devices on this machine."
)
if num_devices > len(visible_devices):
raise ValueError(
f"You requested to find {num_devices} GPUs but this machine only has {len(visible_devices)} GPUs."
f"You requested to find {num_devices} devices but this machine only has {len(visible_devices)} GPUs."
)

available_devices = []
Expand All @@ -122,9 +122,8 @@ def find_usable_cuda_devices(num_devices: int = -1) -> List[int]:

if len(available_devices) != num_devices:
raise RuntimeError(
f"You requested to find {num_devices} GPUs but only {len(available_devices)} are currently available."
f" GPUs {unavailable_devices} are occupied by other processes and can't be"
" used at the moment."
f"You requested to find {num_devices} devices but only {len(available_devices)} are currently available."
f" The devices {unavailable_devices} are occupied by other processes and can't be used at the moment."
)
return available_devices

Expand Down
4 changes: 2 additions & 2 deletions tests/tests_lite/accelerators/test_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_find_usable_cuda_devices_error_handling():

# Asking for GPUs if no GPUs visible
with mock.patch("lightning_lite.accelerators.cuda.num_cuda_devices", return_value=0), pytest.raises(
ValueError, match="You requested to find 2 GPUs but there are no visible CUDA"
ValueError, match="You requested to find 2 devices but there are no visible CUDA"
):
find_usable_cuda_devices(2)

Expand All @@ -137,5 +137,5 @@ def test_find_usable_cuda_devices_error_handling():
tensor_mock = Mock(side_effect=RuntimeError) # simulate device placement fails
with mock.patch("lightning_lite.accelerators.cuda.num_cuda_devices", return_value=2), mock.patch(
"lightning_lite.accelerators.cuda.torch.tensor", tensor_mock
), pytest.raises(RuntimeError, match=escape("GPUs [0, 1] are occupied by other processes")):
), pytest.raises(RuntimeError, match=escape("The devices [0, 1] are occupied by other processes")):
find_usable_cuda_devices(2)

0 comments on commit 0210d20

Please sign in to comment.