Created
December 30, 2023 06:57
-
-
Save iamaziz/ec9a48c07deb06000820233651235090 to your computer and use it in GitHub Desktop.
Enable MacOS M-series chip for PyTorch
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
import torch | |
# Check if CUDA is available, else check for MPS, otherwise default to CPU | |
if torch.cuda.is_available(): | |
device = torch.device("cuda") # GPU | |
elif torch.backends.mps.is_available(): | |
device = torch.device("mps") # MacOS M-series chip | |
else: | |
device = torch.device("cpu") # CPU | |
print(f"Using device: {device}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment