|
| 1 | +<!-- |
| 2 | +# Copyright 2023–2025 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +# Update MaxText dependencies |
| 18 | + |
| 19 | +## Introduction |
| 20 | + |
| 21 | +This document provides a guide to updating dependencies in MaxText using the |
| 22 | +[seed-env](https://github.com/google-ml-infra/actions/tree/main/python_seed_env) |
| 23 | +tool. `seed-env` helps generate deterministic and reproducible Python |
| 24 | +environments by creating fully-pinned `requirements.txt` files from a base set |
| 25 | +of requirements. |
| 26 | + |
| 27 | +Please keep dependencies updated throughout development. This will allow each |
| 28 | +commit to work properly from both a feature and dependency perspective. We will |
| 29 | +periodically upload commits to PyPI for stable releases. But it is also critical |
| 30 | +to keep dependencies in sync for users installing MaxText from source. |
| 31 | + |
| 32 | +## Overview of the process |
| 33 | + |
| 34 | +To update dependencies, you will follow these general steps: |
| 35 | + |
| 36 | +1. **Modify base requirements**: Update the desired dependencies in |
| 37 | + `src/dependencies/requirements/base_requirements/requirements.txt` or the hardware-specific files |
| 38 | + (`src/dependencies/requirements/base_requirements/tpu-base-requirements.txt`, |
| 39 | + `src/dependencies/requirements/base_requirements/gpu-base-requirements.txt`). |
| 40 | +2. **Find the JAX build commit hash**: The dependency generation process is |
| 41 | + pinned to a specific nightly build of JAX. You need to find the commit hash |
| 42 | + for the desired JAX build. |
| 43 | +3. **Generate the requirement files**: Run the `seed-env` CLI tool to generate |
| 44 | + new, fully-pinned requirements files based on your changes. |
| 45 | +4. **Update project files**: Copy the newly generated files into the |
| 46 | + `src/dependencies/requirements/generated_requirements/` directory. If |
| 47 | + necessary, also update any dependencies that are installed directly from |
| 48 | + GitHub from the generated files to `src/dependencies/extra_deps`. |
| 49 | +5. **Verify the new dependencies**: Test the new dependencies to ensure the |
| 50 | + project installs and runs correctly. |
| 51 | + |
| 52 | +The following sections provide detailed instructions for each step. |
| 53 | + |
| 54 | +## Step 0: Install `seed-env` |
| 55 | + |
| 56 | +First, you need to install the `seed-env` command-line tool. We recommend |
| 57 | +installing `uv` first following |
| 58 | +[uv's official installation instructions](https://docs.astral.sh/uv/getting-started/installation/) |
| 59 | +and then using it to install `seed-env`: |
| 60 | + |
| 61 | +```bash |
| 62 | +uv venv --python 3.12 --seed seed_venv |
| 63 | +source seed_venv/bin/activate |
| 64 | +uv pip install seed-env |
| 65 | +``` |
| 66 | + |
| 67 | +Alternatively, follow the instructions in the |
| 68 | +[seed-env repository](https://github.com/google-ml-infra/actions/tree/main/python_seed_env#install-the-seed-env-tool) |
| 69 | +if you want to build `seed-env` from source. |
| 70 | + |
| 71 | +## Step 1: Modify base requirements |
| 72 | + |
| 73 | +Update the desired dependencies in |
| 74 | +`src/dependencies/requirements/base_requirements/requirements.txt` or the |
| 75 | +hardware-specific files |
| 76 | +(`src/dependencies/requirements/base_requirements/tpu-base-requirements.txt`, |
| 77 | +`src/dependencies/requirements/base_requirements/gpu-base-requirements.txt`). |
| 78 | + |
| 79 | +## Step 2: Find the JAX build commit hash |
| 80 | + |
| 81 | +The dependency generation process is pinned to a specific nightly build of JAX. |
| 82 | +You need to find the commit hash for the desired JAX build. |
| 83 | + |
| 84 | +You can find the latest commit hashes in the |
| 85 | +[JAX `build/` folder](https://github.com/jax-ml/jax/commits/main/build). Choose |
| 86 | +a recent, successful build and copy its full commit hash. |
| 87 | + |
| 88 | +## Step 3: Generate the requirements files |
| 89 | + |
| 90 | +Next, run the `seed-env` CLI to generate the new requirements files. You will |
| 91 | +need to do this separately for the TPU and GPU environments. The generated files |
| 92 | +will be placed in a directory specified by `--output-dir`. |
| 93 | + |
| 94 | +### For TPU |
| 95 | + |
| 96 | +Run the following command, replacing `<jax-build-commit-hash>` with the hash you |
| 97 | +copied in the previous step. |
| 98 | + |
| 99 | +```bash |
| 100 | +seed-env \ |
| 101 | + --local-requirements=src/dependencies/requirements/base_requirements/tpu-base-requirements.txt \ |
| 102 | + --host-name=MaxText \ |
| 103 | + --seed-commit=<jax-build-commit-hash> \ |
| 104 | + --python-version=3.12 \ |
| 105 | + --requirements-txt=tpu-requirements.txt \ |
| 106 | + --output-dir=generated_tpu_artifacts |
| 107 | +``` |
| 108 | + |
| 109 | +### For GPU |
| 110 | + |
| 111 | +Similarly, run the command for the GPU requirements. |
| 112 | + |
| 113 | +```bash |
| 114 | +seed-env \ |
| 115 | + --local-requirements=src/dependencies/requirements/base_requirements/gpu-base-requirements.txt \ |
| 116 | + --host-name=MaxText \ |
| 117 | + --seed-commit=<jax-build-commit-hash> \ |
| 118 | + --python-version=3.12 \ |
| 119 | + --requirements-txt=cuda12-requirements.txt \ |
| 120 | + --hardware=cuda12 \ |
| 121 | + --output-dir=generated_gpu_artifacts |
| 122 | +``` |
| 123 | + |
| 124 | +## Step 4: Update project files |
| 125 | + |
| 126 | +After generating the new requirements, you need to update the files in the |
| 127 | +MaxText repository. |
| 128 | + |
| 129 | +1. **Copy the generated files:** |
| 130 | + |
| 131 | + - Move `generated_tpu_artifacts/tpu-requirements.txt` to `generated_requirements/tpu-requirements.txt`. |
| 132 | + - Move `generated_gpu_artifacts/cuda12-requirements.txt` to `generated_requirements/cuda12-requirements.txt`. |
| 133 | + |
| 134 | +2. **Update `src/dependencies/extra_deps` (if necessary):** |
| 135 | + Currently, MaxText uses a few dependencies, such as `mlperf-logging` and |
| 136 | + `google-jetstream`, that are installed directly from GitHub source. These are |
| 137 | + defined in `base_requirements/requirements.txt`, and the `seed-env` tool will |
| 138 | + carry them over to the generated requirements files. |
| 139 | + |
| 140 | +## Step 5: Verify the new dependencies |
| 141 | + |
| 142 | +Finally, test that the new dependencies install correctly and that MaxText runs |
| 143 | +as expected. |
| 144 | + |
| 145 | +1. **Install MaxText:** Follow the instructions to |
| 146 | + [install MaxText from source](install-from-source). |
| 147 | + |
| 148 | +2. **Run tests:** Run MaxText tests to ensure there are no regressions. |
0 commit comments