Skip to content

Instantly share code, notes, and snippets.

@knwng
Created January 18, 2023 08:55
Show Gist options
  • Save knwng/2e64c6d84e225b9bbc81f952eae5d8ee to your computer and use it in GitHub Desktop.
Save knwng/2e64c6d84e225b9bbc81f952eae5d8ee to your computer and use it in GitHub Desktop.
check if cuda is available
def check_if_cuda_available() -> bool:
try:
import torch
return torch.cuda.is_available()
except Exception:
try:
import subprocess
subprocess.run(['nvidia-smi'])
return True
except Exception:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment