Setting up your Mac for Machine Learning with PyTorch is essential for anyone looking to work with deep learning models on their computer. Whether you have a new M1 or M2 Mac, the process is generally the same and can be done in just 11 minutes. In this tutorial, we will walk you through the steps to set up your Mac for Machine Learning with PyTorch.
Step 1: Install Homebrew
Homebrew is a package manager for macOS that allows you to easily install and manage software packages on your Mac. To install Homebrew, open Terminal and paste the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions to complete the installation.
Step 2: Install Python
PyTorch requires Python as its programming language, so the next step is to install Python on your Mac. Homebrew makes this process simple with the following command:
brew install python
Step 3: Install PyTorch
Now that Python is installed, you can use pip, the Python package manager, to install PyTorch. Run the following command in Terminal:
pip install torch torchvision torchaudio
Step 4: Install Jupyter Notebook
Jupyter Notebook is a popular tool among data scientists and machine learning engineers for creating and sharing documents that contain live code, equations, visualizations, and narrative text. You can install Jupyter Notebook with the following command:
pip install jupyter
Step 5: Install Matplotlib
Matplotlib is a data visualization library in Python that creates static, animated, and interactive visualizations in Python. To install Matplotlib, enter the following command:
pip install matplotlib
Step 6: Install Pandas
Pandas is a powerful data manipulation library in Python that provides data structures and data analysis tools for working with structured data. To install Pandas, run the following command:
pip install pandas
Step 7: Install Scikit-learn
Scikit-learn is a machine learning library in Python that provides simple and efficient tools for data mining and data analysis. To install Scikit-learn, use the following command:
pip install scikit-learn
Step 8: Test Your Installation
To test that PyTorch and all the necessary libraries have been installed correctly, open a new terminal window and start a Jupyter Notebook by typing:
jupyter notebook
Create a new Python notebook and enter the following code:
import torch
print(torch.__version__)
import torchvision
print(torchvision.__version__)
import torchaudio
print(torchaudio.__version__)
import matplotlib
print(matplotlib.__version__)
import pandas
print(pandas.__version__)
import sklearn
print(sklearn.__version__)
Run the code cell, and if you see the versions of all the libraries printed without any errors, then congratulations, you have successfully set up your Mac for Machine Learning with PyTorch!
In just 11 minutes, you have installed and configured all the necessary tools and libraries to start working on machine learning projects with PyTorch on your Mac. Happy coding!
Update 30 June 2022: PyTorch 1.12.0 is out and in a stable release. You now no longer need to install the nightly versions of PyTorch as done at 7:37, the updated code is:
pip3 install torch torchvision torchaudio
The code samples have been updated to include this new line of code.
See the announcement blog post here: https://pytorch.org/blog/pytorch-1.12-released/#prototype-introducing-accelerated-pytorch-training-on-mac
Thaaaaank you ! worked beautifully with my M2 macbook air
just finished your pytorch 25 hour video, now i am sad it's over
this is hands down the best video i ever saw, everything worked perfectly fine
You're a legend
I am getting "Kernel Restarting
The kernel for Untitled.ipynb appears to have died. It will restart automatically." how to fix?
when I restarted as shown in @6:10 and reopened my terminal, I don't see (base) next to my username, how to fix this ?
if you get the error "the kernel appears to have died." try changing the python version from 3.8 to 3.11. This solution worked for me.
After miniforge3 install I have conda and (base) but no miniforge3 folder in my home and got "source: no such file or directory: /Users/home/miniforge3/bin/activate" at the end of the install?
Does this work with an older mac book with intel GPU?
Hey sir, Nice video but my mac m1 giving: Kernel Restarting
The kernel for Untitled.ipynb appears to have died. It will restart automatically.
But it work in pycharm.
Thanks for video.
subscribed, i rarely comment on people but you really deserve it!!!
Daniel thx for the content, it was so fast, greetings from México
It worked thanks
Please I need help, I installed everything and it works perfectly. The only issue is that I restarted my terminal and I don’t know how to open up jupyter notebook anymore
It works!!!!
first time a youtube tutorial with 0 problems
Thank you!
I'd rather not have to use conda tbh
thanks I did install this and went fine, however I want to use some script or how to leverage this into like dreambooth where I will give my set of images and set of class images and prompts and inject it to the base model stable diffusion 1.5. Can't seem to find a website for it.