|
| 1 | +# Build, rebuild, and test at each scale |
| 2 | + |
| 3 | +Keyed on tasks: *I need to build, rebuild or run something at N GPUs, how*. |
| 4 | +[TROUBLESHOOTING.md](TROUBLESHOOTING.md) is keyed on symptoms. Most of this page |
| 5 | +points at the places in TensorRT-LLM that already do these things; read the |
| 6 | +current version there rather than trust this page: |
| 7 | + |
| 8 | +| where | what it owns | |
| 9 | +|---|---| |
| 10 | +| `scripts/build_wheel.py` | the build itself, and every flag below | |
| 11 | +| `.claude/skills/exec-slurm-compile/` | building on a Slurm cluster, and `enroot import` | |
| 12 | +| `.claude/skills/trtllm-test-script-builder/` | generating Slurm test scripts: **the launch rules** | |
| 13 | +| `.claude/skills/exec-local-slurm/` | persistent allocations, container reuse, step cancellation | |
| 14 | +| `tests/integration/test_lists/test-db/*.yml` | which tests run at which GPU count | |
| 15 | +| `scripts/test_to_stage_mapping.py` | which CI stage a given test lands in | |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 0. First ask: do you need to build at all? |
| 20 | + |
| 21 | +**For a modeling_v2 onboard, almost certainly not.** |
| 22 | + |
| 23 | +| what you changed | rebuild? | |
| 24 | +|---|---| |
| 25 | +| a target's `modeling.py` / `weights.py` | **no**: pure Python, the editable install picks it up | |
| 26 | +| a catalog entry `.py`, shared or in a target's `ops/` | **no** | |
| 27 | +| a FlashInfer call (sourcing tier 3) | **no**: the package is installed, its kernels JIT | |
| 28 | +| a Triton kernel (sourcing tier 5) | **no**: Triton is JIT | |
| 29 | +| routing, `_router_index.py` | **no** | |
| 30 | +| anything under `cpp/` | yes | |
| 31 | +| a new `torch.ops.trtllm.*` op | yes | |
| 32 | +| pulling a trunk that touched `cpp/` | yes | |
| 33 | + |
| 34 | +None of the five sourcing tiers needs a native rebuild, so the orchestrator |
| 35 | +never builds anything and `environment.python` points at an install someone |
| 36 | +else made. If you are rebuilding during an onboard, confirm why. |
| 37 | + |
| 38 | +### Rebuilding while compute sessions are running |
| 39 | + |
| 40 | +`build_wheel.py` installs `tensorrt_llm/libs/*.so` by rewriting each file in |
| 41 | +place: any process, on any node, that has the old file mapped faults on its |
| 42 | +next page-in, and one attached to its allocation's MPI takes the whole |
| 43 | +allocation with it (measured: a rebuild on one session killed another thirty |
| 44 | +seconds later). Rebuild through the workflow's `incremental_build.sh` (in the |
| 45 | +package's `infra/scripts/`), as a whole-node spool job: |
| 46 | + |
| 47 | +```bash |
| 48 | +spoolctl.py submit --gpus all --wall 3h build-<what> \ |
| 49 | + 'bash <package>/infra/scripts/incremental_build.sh --repo <checkout> --spool <spool A> --spool <spool B>' |
| 50 | +``` |
| 51 | + |
| 52 | +It takes a per-checkout build lock, announces the rebuild on every listed spool |
| 53 | +(each session's scheduler then holds new GPU jobs against that checkout), gives |
| 54 | +every installed library a fresh inode by copy-and-rename so running processes |
| 55 | +keep the file they mapped, builds with ccache, checks the checkout still |
| 56 | +imports, and retracts the announcement, also when the build fails. Spools |
| 57 | +default to `$MV2FLOW_SESSION_SPOOLS`, which every rendered session exports. The |
| 58 | +script runs its helper (`infra/substrate/rebuild.py`) under `$MV2FLOW_PYTHON`, |
| 59 | +else the `python3` on `PATH`, and refuses an interpreter older than 3.7. |
| 60 | + |
| 61 | +## 1. Build |
| 62 | + |
| 63 | +```bash |
| 64 | +python3 ./scripts/build_wheel.py \ |
| 65 | + --use_ccache \ |
| 66 | + --skip_building_wheel \ |
| 67 | + --cuda_architectures "100-real;103-real" |
| 68 | +``` |
| 69 | + |
| 70 | +| flag | when | |
| 71 | +|---|---| |
| 72 | +| `--cuda_architectures` | **always.** `100-real` B200/GB200, `103-real` GB300, `90-real` Hopper, `89-real` L40S, `80-real` A100. Building all of them is the slowest thing you can do | |
| 73 | +| `--use_ccache` | always: a no-op change rebuilds in minutes instead of an hour | |
| 74 | +| `--skip_building_wheel` | development: builds in place, no wheel | |
| 75 | +| `--fast_build` / `-f` | skips some kernels. Development only: **do not gate on a fast build** | |
| 76 | +| `--clean` / `-c` | wipes the build directory | |
| 77 | +| `--configure_cmake` | forces a CMake re-configure when a CMake input changed unnoticed | |
| 78 | +| `-j <N>` | lower it when the build OOMs | |
| 79 | + |
| 80 | +`build_wheel.py` creates its own venv and runs `pip install -e .[devel]` into |
| 81 | +it; that interpreter is the one to put in `environment.python`. ccache does not |
| 82 | +carry across checkouts (absolute paths are baked into the keys): give each |
| 83 | +checkout its own cache, and expect its first build to be cold. A rebuild is |
| 84 | +*not* the fix for `NVRTC ... could not open source file "cuda.h"`; see |
| 85 | +TROUBLESHOOTING.md. |
| 86 | + |
| 87 | +## 2. Build on Slurm |
| 88 | + |
| 89 | +`.claude/skills/exec-slurm-compile/` owns this end to end: `submit_compile.sh` |
| 90 | +submits, `compile.slurm` allocates, `compile.sh` builds inside the container, |
| 91 | +`enroot-import` fetches the image. Two failure modes from its troubleshooting |
| 92 | +table: an `enroot import` **auth** failure (`~/.config/enroot/.credentials`), |
| 93 | +and an **empty or corrupt** `.sqsh` (an image URL with an `https://` prefix it |
| 94 | +should not have). |
| 95 | + |
| 96 | +On a shared cluster `/root/.local` and `/root/.cache` may be symlinked into a |
| 97 | +shared home, so another checkout's develop-install is on the path of every |
| 98 | +container run. Set **`PYTHONNOUSERSITE=1` at runtime**, but **leave the user |
| 99 | +site enabled during the native build**: the CUTLASS kernel CMake runs |
| 100 | +`setup_library.py develop --user` and then imports `cutlass_library`. |
| 101 | + |
| 102 | +## 3. Test — the scale ladder |
| 103 | + |
| 104 | +Scale is declared by `system_gpu_count` in each list's `condition` block, and |
| 105 | +the file name follows it: |
| 106 | + |
| 107 | +| scale | list | `system_gpu_count` | what belongs here | |
| 108 | +|---|---|---|---| |
| 109 | +| **CPU** | `l0_cpu.yml` | `0–0` | anything that needs no device. `backend: generic` | |
| 110 | +| **1–4 GPU** | `l0_gb300.yml`, `l0_b200.yml`, `l0_h100.yml`, … | `1–4` | the ordinary pre-merge matrix | |
| 111 | +| **multi-GPU** | `l0_*_multi_gpus.yml` | `4–4`, `8–8` | collectives, TP/EP topologies | |
| 112 | +| **multi-node** | `l0_*_multi_nodes*.yml` | `8–8`+ | anything spanning nodes | |
| 113 | + |
| 114 | +```bash |
| 115 | +python scripts/test_to_stage_mapping.py --tests "test_modeling_v2_allgather" # where a test runs |
| 116 | +``` |
| 117 | + |
| 118 | +### CPU |
| 119 | + |
| 120 | +`agent-flow`'s own suite is pure CPU, in its own stage |
| 121 | +(`CPU-AgentFlow-UnitTest`), and `AgentFlowRule` narrows CI so an |
| 122 | +agent-flow-only change runs that stage and no GPU stage. For the engine, CPU |
| 123 | +tests are the schema, list and prose audits, including the modeling_v2 claims |
| 124 | +audits. |
| 125 | + |
| 126 | +### Single GPU |
| 127 | + |
| 128 | +```bash |
| 129 | +pytest tests/unittest/_torch/modeling_v2/norm/test_modeling_v2_flashinfer_rmsnorm.py |
| 130 | +LLM_MODELS_ROOT=/path/to/models pytest tests/integration/defs/accuracy/test_modeling_v2_gpt_oss.py |
| 131 | +``` |
| 132 | + |
| 133 | +Unit tests need no models. Integration tests need `LLM_MODELS_ROOT` **and** a |
| 134 | +GPU; without the variable the failure reads like a missing model. |
| 135 | + |
| 136 | +### Multi-GPU: two mechanisms, and they are not interchangeable |
| 137 | + |
| 138 | +**`mpi_pool_executor`**, a fixture with the worker count by indirect |
| 139 | +parametrization: |
| 140 | + |
| 141 | +```python |
| 142 | +@pytest.mark.parametrize("mpi_pool_executor", [2], indirect=True) |
| 143 | +def test_something(mpi_pool_executor): ... |
| 144 | +``` |
| 145 | + |
| 146 | +**A launcher in a fresh interpreter**, which the modeling_v2 collective entries |
| 147 | +use (`tests/unittest/_torch/modeling_v2/comm/_rank_job.py`): a collective that |
| 148 | +breaks hangs rather than raising, and the fixture has no deadline. So a new |
| 149 | +multi-rank test needs a deadline that kills the process group, and an MPI |
| 150 | +launcher cannot start from a pytest process that has already imported |
| 151 | +`tensorrt_llm` (that process initialized MPI): start it in a fresh interpreter, |
| 152 | +by file path. |
| 153 | + |
| 154 | +### Multi-node |
| 155 | + |
| 156 | +The launch rules come from `.claude/skills/trtllm-test-script-builder/`, and |
| 157 | +they are a function of the task count alone: |
| 158 | + |
| 159 | +| | `ntasks == 1` | `ntasks > 1` | |
| 160 | +|---|---|---| |
| 161 | +| `--mpi=` | `none` | `pmix` (or the cluster's variant: `srun --mpi=list`) | |
| 162 | +| payload | clear the MPI environment, then exec | wrap in `trtllm-llmapi-launch` | |
| 163 | + |
| 164 | +```bash |
| 165 | +srun -N 2 --ntasks 8 --ntasks-per-node 4 --mpi=pmix --gres=gpu:4 \ |
| 166 | + --container-image=... --container-name=trtllm-run \ |
| 167 | + bash -c "trtllm-llmapi-launch python3 -m tensorrt_llm.commands.serve $MODEL ..." |
| 168 | +``` |
| 169 | + |
| 170 | +1. **`--ntasks` must match the world size.** Without it `srun` launches one |
| 171 | + task, the MPI world size is 1, and the LLM API spawns the other ranks itself |
| 172 | + (`need_spawn_mpi_workers` in `llmapi/mpi_session.py`), which pyxis forbids: |
| 173 | + `MPI_ERR_SPAWN`. |
| 174 | +2. **`--gres` is per node**, not per world. |
| 175 | +3. **At one task, clear the MPI environment**: mpi4py initializes MPI whenever |
| 176 | + PMI variables are present. Keep `SLURM_PROCID` and `SLURM_LOCALID`, which |
| 177 | + identify the rank. |
| 178 | +4. **`TLLM_WORKER_USE_SINGLE_PROCESS=1` is not the general fix**: it is a |
| 179 | + workaround for TP1 and does not scale past one rank. |
| 180 | + |
| 181 | +Inside a spool session the workflow emits the `mpirun` form of the same rule |
| 182 | +from `environment.py` (`mpirun -n <world> ... trtllm-llmapi-launch`); no agent |
| 183 | +composes it. The container has no `srun` and no sshd: a session declared with |
| 184 | +`nodes: 2` runs one scheduler per node, and `infra/scripts/mn/mn_mpirun.sh` |
| 185 | +starts one `mpirun` across them ([infra/scripts/mn/README.md](infra/scripts/mn/README.md)). |
| 186 | + |
| 187 | +## 4. Iterating without paying full price |
| 188 | + |
| 189 | +| cost | how to stop paying it | |
| 190 | +|---|---| |
| 191 | +| container import, 26 GB / 4–8 min **per job** | `--container-name=<name>`: pyxis skips the import when that name already exists on the node | |
| 192 | +| queue wait per command | a persistent allocation: `salloc` once, then `srun --jobid=<id>` steps into it (see `exec-local-slurm`) | |
| 193 | +| both, plus a transport that cannot reach Slurm at all | a compute session: one long-lived job whose **own main process** is the spool scheduler; work is a file | |
| 194 | +| cold native build | `--use_ccache`, and one cache per checkout | |
| 195 | + |
| 196 | +Work started inside a `slurm_exec_in_job` step does **not** survive the step's |
| 197 | +teardown, `nohup` included (measured): the long-running process has to be the |
| 198 | +job's own main process. Where the Slurm CLI is reachable, prefer the |
| 199 | +persistent-allocation pattern. A session is declared in `task.yaml` |
| 200 | +(`environment.sessions`) and its entry script is rendered, never written by |
| 201 | +hand: |
| 202 | + |
| 203 | +```bash |
| 204 | +trtllm-modeling-v2 session render --task task.yaml --name a # <spool>/session_entry.sh |
| 205 | +trtllm-modeling-v2 session submission --task task.yaml --name a # the broker call that starts it |
| 206 | +trtllm-modeling-v2 session status --task task.yaml # heartbeat, end, queue |
| 207 | +``` |
| 208 | + |
| 209 | +Inside a session, size each job instead of picking devices: |
| 210 | + |
| 211 | +| you run | submit it as | |
| 212 | +|---|---| |
| 213 | +| a single-GPU unit test or microbenchmark | `--gpus 1` | |
| 214 | +| a 4-rank collective test | `--gpus 4` | |
| 215 | +| anything that loads the full model, a gate, a rebuild | `--gpus all` | |
| 216 | +| a worktree's code | add `--tree <worktree>`: it sets the working directory **and** `PYTHONPATH`, and refuses a result whose ranks imported another checkout | |
| 217 | +| the orchestrator, or anything GPU-free and long-lived | a `free-` name, no `--gpus` | |
| 218 | + |
| 219 | +`--wall` counts from the job's start. `spoolctl.py status` says why each |
| 220 | +waiting job waits; `spoolctl.py cancel <name>` is the only way to stop one (the |
| 221 | +safe-kill rule in TROUBLESHOOTING.md). To abort one run without losing a |
| 222 | +persistent allocation: `squeue -s -j <job_id>` lists its steps, and |
| 223 | +`scancel <job_id>.0` cancels one. |
| 224 | + |
| 225 | +## 5. Where a new test belongs |
| 226 | + |
| 227 | +1. **No device?** A CPU list; check whether a CBTS rule already narrows CI for |
| 228 | + your subtree (`jenkins/scripts/cbts/rules/`). |
| 229 | +2. **One device?** The ordinary `l0_<gpu>.yml` for the architecture you |
| 230 | + certified on: certification is per-architecture (`ARCHS`). |
| 231 | +3. **Collectives or a TP/EP topology?** `l0_*_multi_gpus.yml`, with a deadline. |
| 232 | +4. **Spans nodes?** `l0_*_multi_nodes*.yml`, with the launch rules in §3. |
| 233 | + |
| 234 | +Then confirm with `scripts/test_to_stage_mapping.py` that it lands in a stage: |
| 235 | +a test on no list is a test nobody runs. `ModelingV2Rule` excludes `*.md` so a |
| 236 | +documentation-only edit does not pull in multi-GPU stages, which means a check |
| 237 | +that *scans* `.md` files gets no CI trigger from the PRs most likely to break |
| 238 | +it: put text audits in a pre-commit hook, not in a GPU test stage. |
0 commit comments