Skip to content

Commit 84f3139

Browse files
committed
Fix MaxText installation instructions in all jupyter notebooks and update doc
1 parent 00ef5de commit 84f3139

9 files changed

Lines changed: 113 additions & 64 deletions

File tree

.github/workflows/run_jupyter_notebooks.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ jobs:
6464
6565
# 2. Install MaxText package and all the post training dependencies
6666
uv pip install ${maxtext_wheel}[tpu-post-train] --resolution=lowest
67-
#TODO: @mazumdera: replace this with the following after release
68-
# uv pip install maxtext[tpu-post-train] --resolution=lowest
6967
install_maxtext_tpu_post_train_extra_deps
7068
.venv/bin/python3 -m ipykernel install --user --name maxtext_venv
7169

docs/guides/run_python_notebook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ To install, click the `Extensions` icon on the left sidebar (or press `Ctrl+Shif
103103

104104
### Step 4: Install MaxText and Dependencies
105105

106-
To execute post-training notebooks on your TPU-VM, follow the official [MaxText installation guides](https://maxtext.readthedocs.io/en/latest/tutorials/posttraining/rl.html#create-virtual-environment-and-install-maxtext-dependencies) to install MaxText and its dependencies inside a dedicated virtual environment.
106+
To execute post-training notebooks on your TPU-VM, follow the official [MaxText installation guides](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source) and specifically follow `Option 3: Installing [tpu-post-train]`. This will ensure all post-training dependencies are installed inside your virtual environment.
107107

108108
### Step 5: Install the necessary library for Jupyter
109109

@@ -162,7 +162,7 @@ pip3 install jupyterlab
162162

163163
### Step 4: Install MaxText and Dependencies
164164

165-
To execute post-training notebooks on your TPU-VM, follow the official [MaxText installation guides](https://maxtext.readthedocs.io/en/latest/tutorials/posttraining/rl.html#create-virtual-environment-and-install-maxtext-dependencies) to install MaxText and its dependencies inside a dedicated virtual environment.
165+
To execute post-training notebooks on your TPU-VM, follow the official [MaxText installation guides](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source) and specifically follow `Option 3: Installing [tpu-post-train]`. This will ensure all post-training dependencies are installed inside your virtual environment.
166166

167167
### Step 5: Register virtual environment as a Jupyter Kernel
168168

docs/install_maxtext.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ MaxText offers three installation modes:
2424
3. maxtext[tpu-post-train]. Used for post-training on TPUs. Currently, this option should also be used for running vllm_decode on TPUs.
2525

2626
## From PyPI (Recommended)
27+
2728
This is the easiest way to get started with the latest stable version.
2829

2930
```bash
@@ -38,24 +39,26 @@ source maxtext_venv/bin/activate
3839
# installation option from this list to fit your use case.
3940

4041
# Option 1: Installing maxtext[tpu]
41-
uv pip install maxtext[tpu] --resolution=lowest
42+
uv pip install "maxtext[tpu]>=0.2.0" --resolution=lowest
4243
install_maxtext_tpu_github_deps
4344

4445
# Option 2: Installing maxtext[cuda12]
45-
uv pip install maxtext[cuda12] --resolution=lowest
46+
uv pip install "maxtext[cuda12]>=0.2.0" --resolution=lowest
4647
install_maxtext_cuda12_github_dep
4748

4849
# Option 3: Installing maxtext[tpu-post-train]
49-
uv pip install maxtext[tpu-post-train] --resolution=lowest
50+
uv pip install "maxtext[tpu-post-train]>=0.2.0" --resolution=lowest
5051
install_maxtext_tpu_post_train_extra_deps
5152
```
53+
5254
> **Note:** The `install_maxtext_tpu_github_deps`, `install_maxtext_cuda12_github_dep`, and
53-
`install_maxtext_tpu_post_train_extra_deps` commands are temporarily required to install dependencies directly from GitHub
54-
that are not yet available on PyPI. As shown above, choose the one that corresponds to your use case.
55+
> `install_maxtext_tpu_post_train_extra_deps` commands are temporarily required to install dependencies directly from GitHub
56+
> that are not yet available on PyPI. As shown above, choose the one that corresponds to your use case.
5557
5658
> **Note:** The maxtext package contains a comprehensive list of all direct and transitive dependencies, with lower bounds, generated by [seed-env](https://github.com/google-ml-infra/actions/tree/main/python_seed_env). We highly recommend the `--resolution=lowest` flag. It instructs `uv` to install the specific, tested versions of dependencies defined by MaxText, rather than the latest available ones. This ensures a consistent and reproducible environment, which is critical for stable performance and for running benchmarks.
5759
5860
## From Source
61+
5962
If you plan to contribute to MaxText or need the latest unreleased features, install from source.
6063

6164
```bash
@@ -98,11 +101,11 @@ Please keep dependencies updated throughout development. This will allow each co
98101

99102
To update dependencies, you will follow these general steps:
100103

101-
1. **Modify Base Requirements**: Update the desired dependencies in `base_requirements/requirements.txt` or the hardware-specific files (`base_requirements/tpu-base-requirements.txt`, `base_requirements/gpu-base-requirements.txt`).
102-
2. **Generate New Files**: Run the `seed-env` CLI tool to generate new, fully-pinned requirements files based on your changes.
103-
3. **Update Project Files**: Copy the newly generated files into the `generated_requirements/` directory.
104-
4. **Handle GitHub Dependencies**: Move any dependencies that are installed directly from GitHub from the generated files to `src/install_maxtext_extra_deps/extra_deps_from_github.txt`.
105-
5. **Verify**: Test the new dependencies to ensure the project installs and runs correctly.
104+
1. **Modify Base Requirements**: Update the desired dependencies in `base_requirements/requirements.txt` or the hardware-specific files (`base_requirements/tpu-base-requirements.txt`, `base_requirements/gpu-base-requirements.txt`).
105+
2. **Generate New Files**: Run the `seed-env` CLI tool to generate new, fully-pinned requirements files based on your changes.
106+
3. **Update Project Files**: Copy the newly generated files into the `generated_requirements/` directory.
107+
4. **Handle GitHub Dependencies**: Move any dependencies that are installed directly from GitHub from the generated files to `src/install_maxtext_extra_deps/extra_deps_from_github.txt`.
108+
5. **Verify**: Test the new dependencies to ensure the project installs and runs correctly.
106109

107110
The following sections provide detailed instructions for each step.
108111

@@ -154,25 +157,26 @@ seed-env \
154157

155158
After generating the new requirements, you need to update the files in the MaxText repository.
156159

157-
1. **Copy the generated files:**
158-
- Move `generated_tpu_artifacts/tpu-requirements.txt` to `generated_requirements/tpu-requirements.txt`.
159-
- Move `generated_gpu_artifacts/cuda12-requirements.txt` to `generated_requirements/cuda12-requirements.txt`.
160+
1. **Copy the generated files:**
161+
162+
- Move `generated_tpu_artifacts/tpu-requirements.txt` to `generated_requirements/tpu-requirements.txt`.
163+
- Move `generated_gpu_artifacts/cuda12-requirements.txt` to `generated_requirements/cuda12-requirements.txt`.
160164

161-
2. **Update `extra_deps_from_github.txt` (if necessary):**
162-
Currently, MaxText uses a few dependencies, such as `mlperf-logging` and `google-jetstream`, that are installed directly from GitHub source. These are defined in `base_requirements/requirements.txt`, and the `seed-env` tool will carry them over to the generated requirements files.
165+
2. **Update `extra_deps_from_github.txt` (if necessary):**
166+
Currently, MaxText uses a few dependencies, such as `mlperf-logging` and `google-jetstream`, that are installed directly from GitHub source. These are defined in `base_requirements/requirements.txt`, and the `seed-env` tool will carry them over to the generated requirements files.
163167

164168
## Step 5: Verify the New Dependencies
165169

166170
Finally, test that the new dependencies install correctly and that MaxText runs as expected.
167171

168-
1. **Create a clean environment:** It's best to start with a fresh Python virtual environment.
172+
1. **Create a clean environment:** It's best to start with a fresh Python virtual environment.
169173

170174
```bash
171175
uv venv --python 3.12 --seed maxtext_venv
172176
source maxtext_venv/bin/activate
173177
```
174178

175-
2. **Run the setup script:** Execute `bash setup.sh` to install the new dependencies.
179+
2. **Run the setup script:** Execute `bash setup.sh` to install the new dependencies.
176180

177181
```bash
178182
pip install uv
@@ -183,4 +187,4 @@ uv pip install -e .[tpu] --resolution=lowest
183187
install_maxtext_github_deps
184188
```
185189

186-
3. **Run tests:** Run MaxText tests to ensure there are no regressions.
190+
3. **Run tests:** Run MaxText tests to ensure there are no regressions.

docs/tutorials/posttraining/rl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ source ${VENV_NAME?}/bin/activate
5757
Run the following commands to get all the necessary installations.
5858

5959
```bash
60-
uv pip install maxtext[tpu-post-train] --resolution=lowest
60+
uv pip install "maxtext[tpu-post-train]>=0.2.0" --resolution=lowest
6161
install_maxtext_tpu_post_train_extra_deps
6262
```
6363

docs/tutorials/posttraining/sft.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ source ${VENV_NAME?}/bin/activate
3737
Run the following commands to get all the necessary installations.
3838

3939
```bash
40-
uv pip install maxtext[tpu-post-train] --resolution=lowest
40+
uv pip install "maxtext[tpu-post-train]>=0.2.0" --resolution=lowest
4141
install_maxtext_tpu_post_train_extra_deps
4242
```
4343

src/maxtext/examples/rl_llama3_demo.ipynb

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,38 @@
8989
"source": [
9090
"## Installation: MaxText and Post training Dependencies\n",
9191
"\n",
92-
"**Running the notebook on Visual Studio or JupyterLab:** Create an virtual environment and install dependencies outside of the notebook using the commands in [MaxText installation and dependency setup guide](../../../docs/guides/run_python_notebook.md#step-4-install-maxtext-and-dependencies) before proceeding. And then run the notebook using that virtual environment.\n",
93-
"\n",
94-
"\n",
95-
"**Running the notebook on Google Colab:** Run the above-mentioned commands in the Colab and then restart session\n",
92+
"**Running the notebook on Visual Studio or JupyterLab:** Before proceeding, create a virtual environment and install the required post-training dependencies by following `Option 3: Installing [tpu-post-train]` in the [MaxText installation guide](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source). Once the environment is set up, ensure the notebook is running within it."
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": null,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"if IN_COLAB:\n",
102+
" # Clone the MaxText repository\n",
103+
" !git clone https://github.com/AI-Hypercomputer/maxtext.git\n",
104+
" %cd maxtext\n",
96105
"\n",
106+
" # Install uv, a fast Python package installer\n",
107+
" !pip install uv\n",
108+
" \n",
109+
" # Install MaxText and post-training dependencies\n",
110+
" !uv pip install -e .[tpu-post-train] --resolution=lowest\n",
111+
" !install_maxtext_tpu_post_train_extra_deps"
112+
]
113+
},
114+
{
115+
"cell_type": "markdown",
116+
"metadata": {},
117+
"source": [
97118
"**Session restart Instructions for Colab:**\n",
98119
"1. Navigate to the menu at the top of the screen.\n",
99120
"2. Click on **Runtime**.\n",
100121
"3. Select **Restart session** from the dropdown menu.\n",
101122
"\n",
102-
"You will be asked to confirm the action in a pop-up dialog. Click on **Yes**.\n"
123+
"You will be asked to confirm the action in a pop-up dialog. Click on **Yes**."
103124
]
104125
},
105126
{
@@ -119,20 +140,19 @@
119140
"import os\n",
120141
"import sys\n",
121142
"from pathlib import Path\n",
122-
"import MaxText\n",
123143
"from huggingface_hub import login\n",
124144
"from etils import epath\n",
125145
"import jax\n",
126146
"\n",
127147
"from maxtext.trainers.post_train.rl.train_rl import rl_train, setup_configs_and_devices\n",
148+
"from maxtext.utils.globals import MAXTEXT_REPO_ROOT, MAXTEXT_PKG_DIR\n",
128149
"\n",
129150
"os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"0\"\n",
130151
"os.environ[\"SKIP_JAX_PRECOMPILE\"] = \"1\" # Faster startup for vLLM\n",
131152
"# Suppress vLLM logging with a severity level below ERROR\n",
132153
"os.environ[\"VLLM_LOGGING_LEVEL\"] = \"ERROR\"\n",
133154
"\n",
134-
"MAXTEXT_PKG_DIR = os.path.dirname(MaxText.__file__)\n",
135-
"MAXTEXT_REPO_ROOT = os.sep.join([\"maxtext\" if p == \"MaxText\" else p for p in MAXTEXT_PKG_DIR.split(os.sep)])\n",
155+
"\n",
136156
"print(f\"MaxText installation path: {MAXTEXT_PKG_DIR}\")"
137157
]
138158
},
@@ -154,9 +174,10 @@
154174
"metadata": {},
155175
"outputs": [],
156176
"source": [
157-
"if IN_COLAB:\n",
177+
"try:\n",
178+
" from google.colab import userdata\n",
158179
" HF_TOKEN = userdata.get(\"HF_TOKEN\")\n",
159-
"else:\n",
180+
"except ImportError:\n",
160181
" HF_TOKEN = os.environ.get(\"HF_TOKEN\", \"\")\n",
161182
"\n",
162183
"# If not found in the environment, prompt the user for input securely\n",
@@ -191,7 +212,7 @@
191212
"RUN_NAME = datetime.datetime.now().strftime(\"%Y-%m-%d-%H-%M-%S\")\n",
192213
"LOSS_ALGO=\"grpo\" # or \"gspo-token\" if you want to use GSPO\n",
193214
"\n",
194-
"CHAT_TEMPLATE_PATH = f\"{MAXTEXT_REPO_ROOT}/examples/chat_templates/gsm8k_rl.json\"\n",
215+
"CHAT_TEMPLATE_PATH = f\"{MAXTEXT_REPO_ROOT}/src/maxtext/examples/chat_templates/gsm8k_rl.json\"\n",
195216
"if not os.path.exists(CHAT_TEMPLATE_PATH):\n",
196217
" raise FileNotFoundError(f\"Chat template not found: {CHAT_TEMPLATE_PATH}\")\n",
197218
"\n",

src/maxtext/examples/sft_llama3_demo_tpu.ipynb

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,38 @@
101101
"source": [
102102
"## Installation: MaxText and Post training Dependencies\n",
103103
"\n",
104-
"**Running the notebook on Visual Studio or JupyterLab:** Create an virtual environment and install dependencies outside of the notebook using the commands in [MaxText installation and dependency setup guide](../../../docs/guides/run_python_notebook.md#step-4-install-maxtext-and-dependencies) before proceeding. And then run the notebook using that virtual environment.\n",
105-
"\n",
106-
"\n",
107-
"**Running the notebook on Google Colab:** Run the above-mentioned commands in the Colab and then restart session\n",
108-
"\n",
104+
"**Running the notebook on Visual Studio or JupyterLab:** Before proceeding, create a virtual environment and install the required post-training dependencies by following `Option 3: Installing [tpu-post-train]` in the [MaxText installation guide](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source). Once the environment is set up, ensure the notebook is running within it."
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": [
113+
"if IN_COLAB:\n",
114+
" # Clone the MaxText repository\n",
115+
" !git clone https://github.com/AI-Hypercomputer/maxtext.git\n",
116+
" %cd maxtext\n",
117+
"\n",
118+
" # Install uv, a fast Python package installer\n",
119+
" !pip install uv\n",
120+
" \n",
121+
" # Install MaxText and post-training dependencies\n",
122+
" !uv pip install -e .[tpu-post-train] --resolution=lowest\n",
123+
" !install_maxtext_tpu_post_train_extra_deps"
124+
]
125+
},
126+
{
127+
"cell_type": "markdown",
128+
"metadata": {},
129+
"source": [
109130
"**Session restart Instructions for Colab:**\n",
110131
"1. Navigate to the menu at the top of the screen.\n",
111132
"2. Click on **Runtime**.\n",
112133
"3. Select **Restart session** from the dropdown menu.\n",
113134
"\n",
114-
"You will be asked to confirm the action in a pop-up dialog. Click on **Yes**.\n"
135+
"You will be asked to confirm the action in a pop-up dialog. Click on **Yes**."
115136
]
116137
},
117138
{
@@ -166,9 +187,10 @@
166187
},
167188
"outputs": [],
168189
"source": [
169-
"if IN_COLAB:\n",
190+
"try:\n",
191+
" from google.colab import userdata\n",
170192
" HF_TOKEN = userdata.get(\"HF_TOKEN\")\n",
171-
"else:\n",
193+
"except ImportError:\n",
172194
" HF_TOKEN = os.environ.get(\"HF_TOKEN\", \"\")\n",
173195
"\n",
174196
"# If not found in the environment, prompt the user for input securely\n",
@@ -250,7 +272,6 @@
250272
" print(\"Converting checkpoint from HuggingFace...\")\n",
251273
" env = os.environ.copy()\n",
252274
" env[\"JAX_PLATFORMS\"] = \"cpu\"\n",
253-
" # env[\"PYTHONPATH\"] = MAXTEXT_PKG_DIR\n",
254275
"\n",
255276
" subprocess.run(\n",
256277
" [\n",

src/maxtext/examples/sft_qwen3_demo.ipynb

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,46 @@
9595
" IN_COLAB = False"
9696
]
9797
},
98+
{
99+
"cell_type": "markdown",
100+
"metadata": {
101+
"id": "D9ms-jTSZUQL"
102+
},
103+
"source": [
104+
"## Installation: MaxText and Post training Dependencies\n",
105+
"\n",
106+
"**Running the notebook on Visual Studio or JupyterLab:** Before proceeding, create a virtual environment and install the required post-training dependencies by following `Option 3: Installing [tpu-post-train]` in the [MaxText installation guide](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source). Once the environment is set up, ensure the notebook is running within it."
107+
]
108+
},
98109
{
99110
"cell_type": "code",
100111
"execution_count": null,
101112
"metadata": {},
102113
"outputs": [],
103114
"source": [
104-
"try:\n",
105-
" import google.colab\n",
106-
" print(\"Running the notebook in Google Colab\")\n",
107-
" IN_COLAB = True\n",
108-
"except ImportError:\n",
109-
" print(\"Running the notebook on JupyterLab\")\n",
110-
" IN_COLAB = False"
115+
"if IN_COLAB:\n",
116+
" # Clone the MaxText repository\n",
117+
" !git clone https://github.com/AI-Hypercomputer/maxtext.git\n",
118+
" %cd maxtext\n",
119+
"\n",
120+
" # Install uv, a fast Python package installer\n",
121+
" !pip install uv\n",
122+
" \n",
123+
" # Install MaxText and post-training dependencies\n",
124+
" !uv pip install -e .[tpu-post-train] --resolution=lowest\n",
125+
" !install_maxtext_tpu_post_train_extra_deps"
111126
]
112127
},
113128
{
114129
"cell_type": "markdown",
115-
"metadata": {
116-
"id": "D9ms-jTSZUQL"
117-
},
130+
"metadata": {},
118131
"source": [
119-
"## Installation: MaxText and Post training Dependencies\n",
120-
"\n",
121-
"**Running the notebook on Visual Studio or JupyterLab:** Create an virtual environment and install dependencies outside of the notebook using the commands in [MaxText installation and dependency setup guide](../../../docs/guides/run_python_notebook.md#step-4-install-maxtext-and-dependencies) before proceeding. And then run the notebook using that virtual environment.\n",
122-
"\n",
123-
"\n",
124-
"**Running the notebook on Google Colab:** Run the above-mentioned commands in the Colab and then restart session\n",
125-
"\n",
126132
"**Session restart Instructions for Colab:**\n",
127133
"1. Navigate to the menu at the top of the screen.\n",
128134
"2. Click on **Runtime**.\n",
129135
"3. Select **Restart session** from the dropdown menu.\n",
130136
"\n",
131-
"You will be asked to confirm the action in a pop-up dialog. Click on **Yes**.\n"
137+
"You will be asked to confirm the action in a pop-up dialog. Click on **Yes**."
132138
]
133139
},
134140
{
@@ -153,7 +159,6 @@
153159
"import sys\n",
154160
"import transformers\n",
155161
"\n",
156-
"import MaxText\n",
157162
"from maxtext.configs import pyconfig\n",
158163
"from maxtext.examples.sft_train_and_evaluate import evaluate_model, get_test_dataset\n",
159164
"from maxtext.integration.tunix.tunix_adapter import TunixMaxTextAdapter\n",

src/maxtext/examples/sft_train_and_evaluate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
# Run the following commands to get all the necessary installations.
3232
33-
uv pip install maxtext[tpu-post-train] --resolution=lowest
33+
uv pip install "maxtext[tpu-post-train]>=0.2.0" --resolution=lowest
3434
install_maxtext_tpu_post_train_extra_deps
3535
3636

0 commit comments

Comments
 (0)