-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gpu): auto-detect GPU (CUDA/MPS/cpu), remove hard-coded (#20)
TODO: amd64 base image with anything else we need for apple silicon
- Loading branch information
Showing
5 changed files
with
44 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import torch | ||
|
||
if torch.cuda.is_available(): | ||
print("[device] CUDA (Nvidia) detected") | ||
device_id = "cuda" | ||
device_name = torch.cuda.get_device_name() | ||
elif torch.backends.mps.is_available(): | ||
print("[device] MPS (MacOS Metal, Apple M1, etc) detected") | ||
device_id = "mps" | ||
device_name = "MPS" | ||
else: | ||
print("[device] CPU only - no GPU detected") | ||
device_id = "cpu" | ||
device_name = "CPU only" | ||
|
||
if not torch.backends.cuda.is_built(): | ||
print( | ||
"CUDA not available because the current PyTorch install was not " | ||
"built with CUDA enabled." | ||
) | ||
if torch.backends.mps.is_built(): | ||
print( | ||
"MPS not available because the current MacOS version is not 12.3+ " | ||
"and/or you do not have an MPS-enabled device on this machine." | ||
) | ||
else: | ||
print( | ||
"MPS not available because the current PyTorch install was not " | ||
"built with MPS enabled." | ||
) | ||
|
||
device = torch.device(device_id) |
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
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