How to setup Mac M2 Pro for Deep Learning in 2024
I recently migrated to a Mac M2 Pro from a Windows PC and was having a tough time of figuring out the Mac UI let alone how to use a Mac for Deep Learning. I think its safe to say at first I missed my PC and was seriously questioning my decision to switch to a mac book but I didn’t let myself lose sight of the fact that the reason I switched to a Mac was to utilise its top notch GPU for Deep Learning.
So, here’s all the steps you need to follow to have your PC set-up for DeepLearning, by installing pandas, numpy, matplotlib, scikit-learn, Tensorflow and Jupyter:
- Install Homebrew
- Install Miniconda
- Create environment
- Install Tensorflow and its dependencies
- Confirm Tensorflow is accessing GPU
1) Installing Homebrew
Homebrew is a package manager, which doesn’t come pre-installed in Mac, so we install by running this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This comand can be found on https://brew.sh/.
2) Download & Install Miniconda
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
Download and install from this link, then run the 3 commands:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
Don’t forget to restart the terminal
You should see (base) appear on the left side of your terminal, like this:
3) Create Environment
Go to a directory and create a test folder. This can be anywhere.
mkdir test
cd test
Now create an environment here:
conda create --prefix ./env python=3.8
conda activate ./env
4) Install Tensorflow and its dependencies
conda install -c apple tensorflow-deps
python -m pip install tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
5) Confirm Tensorflow is working
Now install jupyter, pandas, numpy, matplotlib, scikit-learn in one command!
conda install jupyter pandas numpy matplotlib scikit-learn
Now open jupyter notebook by typing this command in terminal:
jupyter notebook
Run this code in jupyter to confirm successful installation:
import numpy as np
import pandas as pd
import sklearn
import tensorflow as tf
import matplotlib.pyplot as plt
print(tf.config.list_physical_devices())
Confirm your Tensorflow is able to access GPU, it should be printed.