Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up PyTorch with MPS GPU Support on Apple Silicon Macs and Integrating with PyCharm

Tech 1

Install Anaconda for ARM64 Architecture

Download and install the ARM64 version of Anaconda from the official site:

https://www.anaconda.com/products/distribution#Downloads

Verify the installation by running:

conda info

Check the system platform to confirm compatibility:

import platform
print(platform.platform())

Ensure the output indicates an ARM-based architecture.

Configure Conda Channels for Faster Downloads

Set up mirrors from Tsinghua University to accelerate package retrieval:

conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

Remove the default channel to avoid cofnlicts:

conda config --remove channels defaults

Confirm the active channels:

conda config --show channels

Create a Dedicated Environment for PyTorch

Create a new conda environment using Python 3.10:

conda create -n pytorch python=3.10

Activate it:

conda activate pytorch

Install PyTorch with MPS Backend Support

As of May 2022, PyTorch officially supports GPU acceleration on Apple Silicon (M1/M2) Macs via Metal Performance Shaders (MPS). This requires macOS 12.3 or later.

Visit https://pytorch.org/get-started/locally/ to generate the correct installation command. Use the Nightly build (not stable), and select pip as the package manager. Avoid conda due to potential limitations in accessing preview releases.

Install using:

pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

A successful installation will not produce errors and will include torch in the installed packages.

Validate Installation

Launch Python and run:

import torch
print(torch.__version__)
print(torch.device("mps"))

If the output shows a valid MPS device, the setup is complete.

Install PyCharm for Apple Silicon

Download the native Apple Silicon (ARM64) version of PyCharm from:

https://www.jetbrains.com/pycharm/download/other.html

Using the universal version may lead to interpreter detection issues on M-series chips.

Integrate PyTorch with PyCharm

Open PyCharm, go to Settings > Project > Python Interpreter.

Select the pytorch environment you created earlier. Ensure the interpreter path points to the correct Python executable inside the conda envs/pytorch/bin/python directory.

Test the configuration with a simple script:

import torch
print(torch.__version__)

If the version number prints successfully, PyTorch is correctly linked and ready for use.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.