Run MaxText Python Notebooks on TPUs#

This guide provides clear, step-by-step instructions for running MaxText Python notebooks on TPUs using three supported methods: Google Colab, Visual Studio Code, and a local JupyterLab environment.

📑 Table of Contents#

Prerequisites#

Get Hugging Face Token#

To access model checkpoint from the Hugging Face Hub, you need to authenticate with a personal access token. Follow these steps to get your token:

  • Navigate to the Access Tokens page in your Hugging Face account settings. You can go there directly by visiting this url.

  • Create a new token by clicking the “+ Create new token” button.

  • Give your token a name and assign it a read role. The read role is sufficient for downloading models.

Method 1: Google Colab with TPU#

This is the fastest way to run MaxText python notebooks without managing infrastructure.

⚠️ IMPORTANT NOTE ⚠️ The free tier of Google Colab provides access to v5e-1 TPU, but this access is not guaranteed and is subject to availability and usage limits.

Currently, this method only supports the sft_qwen3_demo.ipynb notebook, which demonstrates Qwen3-0.6B SFT training and evaluation on OpenAI’s GSM8K dataset. If you want to run other notebooks, please use the other methods below.

Before proceeding, please verify that the specific notebook you are running works reliably on the free-tier TPU resources. If you encounter frequent disconnections or resource limitations, you may need to:

  • Upgrade to a Colab Pro or Pro+ subscription for more stable and powerful TPU access.

  • Try Method 2 or Method 3 with access to a more powerful TPU machine.

Step 1: Import Notebook into Google Colab#

  • Visit the MaxText examples directory on Github.

  • Find the notebook you want to run (e.g., sft_qwen3_demo.ipynb) and copy its URL.

  • Go to Google Colab and sign in.

  • Go to File -> Open Notebook.

  • Select the GitHub tab.

  • Paste the target .ipynb link you copied and press Enter.

Step 2: Enable TPU Runtime#

  • Go to RuntimeChange runtime type.

  • Select your desired TPU under Hardware accelerator.

  • Click Save.

Step 3: Run the Notebook#

Follow the instructions within the notebook cells to install dependencies and run the training/inference.

Available Examples#

Supervised Fine-Tuning (SFT)#

Reinforcement Learning (GRPO/GSPO) Training#

Common Pitfalls & Debugging#

Issue

Solution

❌ Colab disconnects

Save checkpoints to GCS regularly

❌ “RESOURCE_EXHAUSTED” errors

Use smaller batch size or change BASE_OUTPUTDIRECTORY to GCS

❌ Firewall blocked

Ensure port 8888 open, or always use SSH tunneling

Support and Resources#