Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Last active January 30, 2024 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iqiancheng/d4497c6a4c487ceab5d72f0758ec2e9a to your computer and use it in GitHub Desktop.
Save iqiancheng/d4497c6a4c487ceab5d72f0758ec2e9a to your computer and use it in GitHub Desktop.
一行式Check if MPS is Available

If you want to check MPS availability using a one-liner in the command line, you can use the following:

python3 -c "import torch; print(f\"MPS is {'' if torch.backends.mps.is_available() else 'not '}available\") "

This one-liner imports the torch module, checks if MPS is available, and prints the corresponding message.

python3 -c "import torch; print(torch.backends.mps.is_available())"
python3 -c "import torch; print(f\"MPS is {'' if torch.backends.mps.is_available() else 'not '}available\") "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment