Skip to content

Commit 002af5e

Browse files
committed
Revise Colab setup instructions for TPU: streamline steps for importing notebooks and connecting to local Jupyter Lab.
1 parent 9204d6b commit 002af5e

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

docs/tutorials/how_to_run_colabs.md

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,28 @@ Before starting, make sure you have:
2727

2828
This is the fastest way to run MaxText without managing infrastructure.
2929

30-
### Step 1: Open Google Colab
31-
32-
1. Go to [Google Colab](https://colab.research.google.com/)
33-
2. Sign in → New Notebook
34-
35-
### Step 2: Enable TPU Runtime
36-
30+
### Step 1: Choose an Example
31+
1. Visit the MaxText Examples directory on GitHub:
32+
[https://github.com/AI-Hypercomputer/maxtext/tree/main/src/MaxText/examples](https://github.com/AI-Hypercomputer/maxtext/tree/main/src/MaxText/examples)
33+
2. Find the notebook you want to run (e.g., `sft_qwen3_demo.ipynb`) and copy its URL.
34+
35+
### Step 2: Import into Colab
36+
1. Go to [Google Colab](https://colab.research.google.com/) and sign in.
37+
2. Select **File** -> **Open Notebook**.
38+
3. Select the **GitHub** tab.
39+
4. Paste the target `.ipynb` link you copied in Step 1 and press Enter.
40+
5. Click on the notebook name to open it.
41+
42+
### Step 3: Enable TPU Runtime
3743
1. **Runtime****Change runtime type**
3844
2. Set **Hardware accelerator****TPU**
3945
3. Select TPU version:
4046
- **v5e-8** → recommended for most MaxText examples, but it's a paid option
4147
- **v5e-1** → free tier option (slower, but works for Qwen-0.6B demos)
4248
4. Click **Save**
4349

44-
### Step 3: Upload & Prepare MaxText
45-
46-
Upload notebooks or mount your GitHub repo
47-
48-
> **Note:** In Colab, the repo root will usually be `/content/maxtext`
49-
50-
**Example:**
51-
```bash
52-
!git clone https://github.com/AI-Hypercomputer/maxtext.git
53-
%cd maxtext
54-
```
55-
56-
### Step 4: Run Examples
57-
58-
1. Open `src/MaxText/examples/`
59-
2. Try:
60-
- `sft_qwen3_demo.ipynb`
61-
- `sft_llama3_demo.ipynb`
62-
- `rl_llama3_demo.ipynb` (GRPO/GSPO training)
63-
50+
### Step 4: Run the Notebook
51+
Follow the instructions within the notebook cells to install dependencies and run the training/inference.
6452

6553
> **Tip:** If Colab disconnects, re-enable TPU and re-run setup cells. Save checkpoints to GCS or Drive.
6654
@@ -80,12 +68,16 @@ In Google Cloud Console:
8068
- **TPU type:** `v5e-8` (or `v6p-8` for newer hardware)
8169
- **Runtime Version:** `tpu-ubuntu-alpha-*` (matches your VM image)
8270

83-
### Step 2: Connect to TPU VM
71+
### Step 2: Connect with Port Forwarding
72+
Run this command to SSH into the TPU VM while simultaneously creating a secure tunnel for Jupyter.
73+
> **Note**: The `--` separator before the `-L` flag is required. This tunnels the remote port 8888 to your local machine securely.
8474
8575
```bash
86-
gcloud compute tpus tpu-vm ssh maxtext-tpu-node --zone=YOUR_ZONE
76+
gcloud compute tpus tpu-vm ssh maxtext-tpu-node --zone=YOUR_ZONE -- -L 8888:localhost:8888
8777
```
8878

79+
> **Note**: If you get a "bind: Address already in use" error, it means port 8888 is busy on your local computer. Change the first number to a different port, e.g., -L 9999:localhost:8888. You will then access Jupyter at localhost:9999.
80+
8981
### Step 3: Install Dependencies
9082

9183
```bash
@@ -100,23 +92,23 @@ pip3 install jupyterlab
10092
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root
10193
```
10294

103-
Copy the URL with token from terminal
104-
105-
### Step 5: Secure Access
106-
107-
#### Option A: SSH Tunnel (Recommended)
108-
109-
```bash
110-
gcloud compute tpus tpu-vm ssh maxtext-tpu-node --zone=YOUR_ZONE -- -L 8888:localhost:8888
111-
```
112-
113-
Then open → `http://localhost:8888`
95+
### Step 5: Access the Notebook
96+
1. Look at the terminal output for a URL that looks like: `http://127.0.0.1:8888/lab?token=...`
97+
2. Copy that URL.
98+
3. Paste it into your **local computer's browser**.
99+
* **Important:** If you changed the port in Step 2 (e.g., to `9999`), you must manually replace `8888` in the URL with `9999`.
100+
* *Example:* `http://127.0.0.1:9999/lab?token=...`
114101

115102

116103
## Method 3: Colab + Local Jupyter Lab Hybrid
117104

118-
Set up Jupyter Lab as in step 2.
119-
Use the link for Jupyter Lab as a link for "Connect to a local runtime" in Collab - at the dropdown where you select the runtime.
105+
Set up Jupyter Lab as in Method 2 (complete Steps 1-5).
106+
107+
### To connect Colab to your local Jupyter Lab:
108+
1. Copy the Jupyter Lab URL from Method 2, Step 5 output (format: `http://127.0.0.1:8888/lab?token=...` or the custom port you used).
109+
2. In Google Colab, click the **arrow next to the RAM/Disk indicator** in the top right corner.
110+
3. Select **"Connect to a local runtime"**.
111+
4. Paste the Jupyter Lab URL and click **Connect**.
120112

121113
## Available Examples
122114

@@ -133,8 +125,13 @@ Use the link for Jupyter Lab as a link for "Connect to a local runtime" in Colla
133125

134126
For interactive GRPO or GSPO training in Google Colab or Jupyter:
135127

136-
1. **Open** `src/MaxText/examples/rl_llama3_demo.ipynb`
137-
2. **Enable TPU runtime** (Runtime → Change runtime type → TPU)
128+
1. **Open the Notebook**
129+
* **Google Colab:** Go to **File****Open Notebook****GitHub**. Paste the URL for `src/MaxText/examples/rl_llama3_demo.ipynb`.
130+
* **Jupyter Lab:** In the file browser, navigate to `src/MaxText/examples/` and open `rl_llama3_demo.ipynb`.
131+
132+
2. **Enable TPU Runtime**
133+
* **Google Colab:** Go to **Runtime****Change runtime type** → Select **TPU**.
134+
* **Jupyter Lab:** Skip this step (the VM is already connected to the TPU).
138135
3. **Set `LOSS_ALGO`** to `"grpo"` for GRPO or `"gspo-token"` for GSPO
139136
4. **Run cells** to train Llama3.1-8B with GRPO or GSPO on GSM8K dataset
140137

0 commit comments

Comments
 (0)