Skip to content

Commit 87dff99

Browse files
authored
Handle edge case for find_usable_cuda_devices(0) (#18722)
1 parent 379ed8c commit 87dff99

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/lightning/fabric/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
221221
- Fixed redundant input-type casting in FSDP precision ([#18630](https://github.com/Lightning-AI/lightning/pull/18630))
222222

223223

224+
- Fixed an issue with `find_usable_cuda_devices(0)` incorrectly returning a list of devices ([#18722](https://github.com/Lightning-AI/lightning/pull/18722))
225+
226+
224227
## [2.0.9] - 2023-09-14
225228

226229
### Fixed

src/lightning/fabric/accelerators/cuda.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def find_usable_cuda_devices(num_devices: int = -1) -> List[int]:
9090
both processes determine that the device is unoccupied, leading into one of them crashing later on.
9191
9292
"""
93+
if num_devices == 0:
94+
return []
9395
visible_devices = _get_all_visible_cuda_devices()
9496
if not visible_devices:
9597
raise ValueError(

tests/tests_fabric/accelerators/test_cuda.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,6 @@ def test_find_usable_cuda_devices_error_handling():
157157
"lightning.fabric.accelerators.cuda.torch.tensor"
158158
):
159159
assert find_usable_cuda_devices(-1) == [0, 1, 2, 3, 4]
160+
161+
# Edge case
162+
assert find_usable_cuda_devices(0) == []

0 commit comments

Comments
 (0)