Skip to content

Commit

Permalink
fix(scripts): check Torch CUDA devices (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 18, 2023
1 parent a9456f4 commit 391a707
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/scripts/check-env.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,31 @@ def check_providers() -> List[str]:
return results


def check_torch_cuda() -> List[str]:
results = []
try:
import torch.cuda

if torch.cuda.is_available():
for i in range(torch.cuda.device_count()):
with torch.cuda.device(i):
mem_free, mem_total = torch.cuda.mem_get_info()
results.append(f"Torch has CUDA device {i} with {mem_free} of {mem_total} bytes of free VRAM")
else:
results.append("loaded Torch but CUDA was not available")
except ImportError as e:
results.append(f"unable to import Torch CUDA: {e}")
except Exception as e:
results.append(f"error listing Torch CUDA: {e}")

return results


ALL_CHECKS = [
check_modules,
check_runtimes,
check_providers,
check_torch_cuda,
]


Expand Down

0 comments on commit 391a707

Please sign in to comment.