Created
January 18, 2023 08:55
-
-
Save knwng/2e64c6d84e225b9bbc81f952eae5d8ee to your computer and use it in GitHub Desktop.
check if cuda is available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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