ML 125: Jupyter Notebook on a Mac M1 (10 pts extra)

What You Need

Purpose

To run a LLM locally, gaining experience with its performance.

Installing Jupyter

In a Terminal, enter this code:
python3 -m venv jenv
source jenv/bin/activate
pip3 install jupyter
Jupyter installs, as shown below.

Installing PyTorch

In a Terminal, enter this code:
pip3 install torch torchvision
The installation succeeds, as shown below.

Assigning a Password

In the Terminal, enter this code:
jupyter server --generate-config
jupyter server password
Enter your desired password twice.

The password is saved to the configuration file, as shown below.

Fixing the Jupyter Kernel Issue

In the Terminal, enter this code:
jupyter notebook
A browser window opens showing a Jupyter page.

Enter your password and log in, as shown below.

Launching a Notebook

At the top right, click the New button.

Click "Python 3 (ipykernel)".

In your jupyter notebook, execute this command:

print("Hi")
You should see "Hi", as shown below.

If jupyter crashes, see this page for instructions to specify the arm64 instruction set manually.

ML 125.1: Jupyter Version

In your jupyter notebook, execute this command:
import torch, os

print(torch.__version__)
if (torch.backends.mps.is_available()):
  if (torch.backends.mps.is_built()):
    print( os.system("jupyter --version") )
The flag is covered by a green rectangle in the image below.

References

How to Run Jupyter Notebooks on an Apple M1 Mac

Pytorch for Mac M1/M2 with GPU acceleration 2023. Jupyter and VS Code setup for PyTorch included.

Posted 5-20-24