This repository contains a simple Python script that checks for the availability of the Metal Performance Shaders (MPS) device using PyTorch. The script initializes a PyTorch tensor on the MPS device and prints the tensor if the device is available; otherwise, it notifies the user that the MPS device was not found.
Before running the script, ensure that you have the following prerequisites installed:
-
Python: The script is written in Python, so you need to have Python installed on your machine.
-
Pipenv: Pipenv is recommended for managing Python dependencies. If you don't have Pipenv installed, you can install it using the following command:
pip install pipenv
-
Clone the repository:
git clone https://github.com/69hunter/mps-device-check.git
-
Navigate to the project directory:
cd mps-device-check
-
Install dependencies using Pipenv:
pipenv install
-
Activate the virtual environment:
pipenv shell
-
Run the script:
python main.py
The script will output either the initialized tensor on the MPS device or a message indicating that the MPS device was not found.
The script consists of the following steps:
-
Check for MPS Availability:
if torch.backends.mps.is_available():
It checks whether the Memory Persistence Service (MPS) is available.
-
Initialize MPS Device:
mps_device = torch.device("mps")
If the MPS device is available, it initializes the device.
-
Create and Print Tensor:
x = torch.ones(1, device=mps_device) print(x)
It creates a PyTorch tensor with all elements set to 1 on the MPS device and prints the tensor.
-
Handle MPS Device Not Found:
else: print("MPS device not found.")
If the MPS device is not available, it prints a message indicating that the MPS device was not found.
This simple script serves as a quick check to see if the Memory Persistence Service (MPS) device is available using PyTorch. Use it as a starting point for more complex scripts or integrate it into your projects that require MPS functionality. The PyTorch library will be automatically installed as part of the Pipenv setup.