Handle edge case for `find_usable_cuda_devices(0)` (#18722)

This commit is contained in:
Adrian Wälchli 2023-10-06 20:44:33 -07:00 committed by GitHub
parent 379ed8c66e
commit 87dff9928e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -221,6 +221,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed redundant input-type casting in FSDP precision ([#18630](https://github.com/Lightning-AI/lightning/pull/18630))
- Fixed an issue with `find_usable_cuda_devices(0)` incorrectly returning a list of devices ([#18722](https://github.com/Lightning-AI/lightning/pull/18722))
## [2.0.9] - 2023-09-14
### Fixed

View File

@ -90,6 +90,8 @@ def find_usable_cuda_devices(num_devices: int = -1) -> List[int]:
both processes determine that the device is unoccupied, leading into one of them crashing later on.
"""
if num_devices == 0:
return []
visible_devices = _get_all_visible_cuda_devices()
if not visible_devices:
raise ValueError(

View File

@ -157,3 +157,6 @@ def test_find_usable_cuda_devices_error_handling():
"lightning.fabric.accelerators.cuda.torch.tensor"
):
assert find_usable_cuda_devices(-1) == [0, 1, 2, 3, 4]
# Edge case
assert find_usable_cuda_devices(0) == []