Skip to content

Commit ed3c569

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

9 files changed

Lines changed: 93 additions & 48 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) to install MaxText and its dependencies inside a dedicated 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) to install MaxText and its dependencies inside a dedicated virtual environment.
166166

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

docs/install_maxtext.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ source maxtext_venv/bin/activate
3838
# installation option from this list to fit your use case.
3939

4040
# Option 1: Installing maxtext[tpu]
41-
uv pip install maxtext[tpu] --resolution=lowest
41+
uv pip install "maxtext[tpu]>=0.2.0" --resolution=lowest
4242
install_maxtext_tpu_github_deps
4343

4444
# Option 2: Installing maxtext[cuda12]
45-
uv pip install maxtext[cuda12] --resolution=lowest
45+
uv pip install "maxtext[cuda12]>=0.2.0" --resolution=lowest
4646
install_maxtext_cuda12_github_dep
4747

4848
# Option 3: Installing maxtext[tpu-post-train]
49-
uv pip install maxtext[tpu-post-train] --resolution=lowest
49+
uv pip install "maxtext[tpu-post-train]>=0.2.0" --resolution=lowest
5050
install_maxtext_tpu_post_train_extra_deps
5151
```
5252
> **Note:** The `install_maxtext_tpu_github_deps`, `install_maxtext_cuda12_github_dep`, and

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: 31 additions & 10 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:** Create an virtual environment and install post-training dependencies outside of the notebook using the commands in [MaxText installation and dependency setup guide](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source) before proceeding. And then run the notebook using that virtual environment."
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",

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:** Create an virtual environment and install post-training dependencies outside of the notebook using the commands in [MaxText installation and dependency setup guide](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source) before proceeding. And then run the notebook using that virtual environment."
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:** Create an virtual environment and install post-training dependencies outside of the notebook using the commands in [MaxText installation and dependency setup guide](https://maxtext.readthedocs.io/en/latest/install_maxtext.html#from-source) before proceeding. And then run the notebook using that virtual environment."
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)