Noah Nowaczewski commited on
Commit
4c7c0b8
·
verified ·
1 Parent(s): afad141

Add GR00T fine-tuning playbook

Browse files
Files changed (1) hide show
  1. GROOT_TRAINING_FROM_SCRATCH.md +219 -0
GROOT_TRAINING_FROM_SCRATCH.md ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Training GR00T on a rented GPU — the complete guide (learned the hard way)
2
+
3
+ This is the end-to-end playbook for fine-tuning **NVIDIA GR00T N1.7-3B** on your own
4
+ robot demos, on a rented cloud GPU (RunPod-style) or any SLURM cluster. It's written for
5
+ someone who has **never done this before**, and every step encodes a mistake we already
6
+ made so you don't repeat it. Read the **Golden Rules** first — they're the whole game.
7
+
8
+ ---
9
+
10
+ ## ⭐ The 5 Golden Rules (if you read nothing else)
11
+
12
+ 1. **Within 2 minutes of launching training, check GPU utilization.** If it's not **>70%**,
13
+ STOP — you're wasting money on an idle GPU. We once ran for *hours* at 0% GPU before
14
+ noticing. `nvidia-smi --query-gpu=utilization.gpu --format=csv` is your best friend.
15
+ 2. **Re-encode your videos to H264 *before* training.** Datasets recorded as AV1 decode
16
+ ~3–10× slower on CPU and will starve the GPU. This was our #1 hidden bottleneck.
17
+ 3. **Save your trained checkpoint to HuggingFace BEFORE you terminate the pod.** We lost a
18
+ checkpoint because the pod's disk vanished on termination. The pod is ephemeral; HF is not.
19
+ 4. **Don't trust the loss, and don't over-train.** GR00T's flow-matching loss flatlines at
20
+ ~0.05 by ~step 2000 and means *nothing* about task success. Train ~8k steps, judge by
21
+ running the policy on the robot — not by the loss curve.
22
+ 5. **Terminate the pod the moment you're done.** A GPU bills every second, including while
23
+ it sits idle during setup or after training finishes.
24
+
25
+ ---
26
+
27
+ ## 0. What you're actually doing
28
+
29
+ You have robot demonstrations (a **LeRobot v2.1 dataset**: camera videos + joint states).
30
+ You fine-tune the 3B GR00T vision-language-action model to imitate them, then deploy the
31
+ trained policy back onto the robot. Training needs a **modern GPU** (Ampere or newer):
32
+
33
+ | GPU | Full fine-tune of 3B? | Notes |
34
+ |---|---|---|
35
+ | H100 / H200 / A100 80GB | ✅ comfortably | what you want |
36
+ | L40S / A6000 / RTX 6000 Ada (48GB) | ⚠️ tight (~44GB used) | batch=1 + grad checkpointing |
37
+ | Anything pre-Ampere (e.g. Tesla K40, RTX Turing) | ❌ no | no bf16, no flash-attn, too little VRAM |
38
+
39
+ Budget ~**$2–3/hr** for an H100. Setup is ~20–30 min, training ~1 hr → plan for ~$5–8/run.
40
+
41
+ ---
42
+
43
+ ## 1. Provision the pod (don't skimp here — it caused our worst crashes)
44
+
45
+ - **GPU:** H100 or H200 80GB (A100 80GB fine). 48GB cards work but are tight.
46
+ - **Disk / volume: ≥ 150–200 GB.** Our first pod had a tiny volume → `Disk quota exceeded`
47
+ mid-training, producing a **corrupt half-written checkpoint**. The venv (~20GB), model
48
+ cache (~12GB), and checkpoints (~13–25GB each) add up fast.
49
+ - **SSH key:** add a *passphrase-less* ed25519 key to your cloud account before booting
50
+ (`ssh-keygen -t ed25519 -f ~/.ssh/runpod`). A key with a passphrase can't be used for
51
+ automation. On a *migrated* container the key sometimes isn't injected — paste your pubkey
52
+ into `/root/.ssh/authorized_keys` via the web terminal if direct SSH is refused.
53
+
54
+ ---
55
+
56
+ ## 2. Environment setup (the part that fights you)
57
+
58
+ Fresh containers have **nothing** — and these get wiped on every new pod / migration:
59
+
60
+ ```bash
61
+ # system deps — MISSING THESE CAUSES SILENT TRAINING CRASHES:
62
+ apt-get update && apt-get install -y python3.10-dev ffmpeg git git-lfs curl build-essential
63
+ # python3.10-dev -> Triton JIT-compiles CUDA at runtime; without Python.h it dies
64
+ # with a cryptic "gcc ... -lcuda ... exit 1"
65
+ # ffmpeg -> torchcodec (video decode) won't load without libav*; training dies
66
+ # at dataset setup with "Video backend 'torchcodec' is not available"
67
+
68
+ # uv (the package manager GR00T uses)
69
+ curl -LsSf https://astral.sh/uv/install.sh | sh ; export PATH="$HOME/.local/bin:$PATH"
70
+
71
+ # clone GR00T + fetch its LFS wheels (CRITICAL)
72
+ cd /workspace && git clone https://github.com/NVIDIA/Isaac-GR00T
73
+ cd Isaac-GR00T && git lfs install && git lfs pull
74
+ # ^ GR00T's pyproject does a UNIVERSAL multi-platform resolve and references local
75
+ # aarch64 flash-attn/torchcodec wheels tracked by git-LFS. A plain clone leaves them
76
+ # as LFS *pointers*, so `uv sync` fails: "Invalid zip file structure". `git lfs pull`
77
+ # makes them real. (You're on x86_64; uv still reads the aarch64 metadata to resolve.)
78
+
79
+ # build the env (~10–20 min — the long pole)
80
+ uv sync
81
+ ```
82
+
83
+ **HuggingFace auth:** the GR00T backbone (`nvidia/Cosmos-Reason2-2B`) is **gated**. Set a
84
+ token, and point the cache at the big volume:
85
+ ```bash
86
+ export HF_HOME=/workspace/hf HF_TOKEN=hf_xxx # a token with access to the gated model
87
+ ```
88
+ Note: `HF_HUB_OFFLINE=1` does **not** fall back to cache for gated models — it errors. Keep
89
+ it online with a token.
90
+
91
+ ---
92
+
93
+ ## 3. Prepare the data (this is where the speed comes from)
94
+
95
+ **Re-encode AV1 → all-intra H264.** This single step is the difference between a 1-hour run
96
+ and a 5-hour one, because AV1 decode (not the GPU) is the bottleneck.
97
+
98
+ ```bash
99
+ # scripts/prep_h264.sh <dataset_dir> — re-encodes every video, preserves frame counts,
100
+ # flips meta/info.json codec to h264. ~2 min on many cores.
101
+ bash scripts/prep_h264.sh /workspace/uf850_data
102
+ ```
103
+ Then **audit the data** (we found dead/never-grasped episodes that teach the policy to do
104
+ nothing, and IK-flip glitch frames): use `scripts/drop_episodes.py` to remove bad episodes
105
+ (it re-indexes the LeRobot metadata correctly) and `scripts/data_viz.py` to eyeball them.
106
+
107
+ **Stage the dataset in RAM** right before training — the network volume has high I/O latency:
108
+ ```bash
109
+ cp -r /workspace/uf850_data /dev/shm/uf850_data # ~1 GB fits in RAM trivially
110
+ ```
111
+
112
+ ---
113
+
114
+ ## 4. Launch training (the fast recipe)
115
+
116
+ ```bash
117
+ cd /workspace/Isaac-GR00T
118
+ export PATH="$HOME/.local/bin:$PATH" HF_HOME=/workspace/hf HF_TOKEN=hf_xxx PYTHONUNBUFFERED=1
119
+ uv run --no-sync python gr00t/experiment/launch_finetune.py \
120
+ --base-model-path nvidia/GR00T-N1.7-3B \
121
+ --dataset-path /dev/shm/uf850_data --embodiment-tag NEW_EMBODIMENT \
122
+ --modality-config-path examples/UF850/uf850_config.py \
123
+ --num-gpus 1 --output-dir /workspace/uf850_ckpt \
124
+ --dataloader-num-workers 8 \ # default is 2 — way too few; 8–16 once data is H264
125
+ --max-steps 8000 \ # loss converges ~2k; 8k is plenty, half the cost of 15k
126
+ --save-steps 2000 --save-total-limit 2 # few checkpoint writes (each ~13–25GB to slow disk)
127
+ ```
128
+ (`scripts/train_fast.sh` wraps all of this.)
129
+
130
+ Keep it running across SSH drops with **`tmux`** or `nohup`. Note: naive backgrounding over
131
+ SSH (`cmd &`) often dies on channel-close, and opening many SSH connections gets you
132
+ rate-limited (`kex_exchange_identification: Connection reset`). Use one `tmux` session.
133
+
134
+ ---
135
+
136
+ ## 5. ⭐ THE SANITY GATE — do this every single run (2 minutes)
137
+
138
+ This is Golden Rule #1 made concrete. ~2 min after launch (past the first-epoch shard-cache
139
+ warmup), run `scripts/train_sanity.sh`. It measures over ~60s and tells you:
140
+
141
+ - **GPU util < 30%** → you're **data-bound** (decode / I/O / too few workers / augmentation).
142
+ Stop and fix the input pipeline. Don't let it crawl for hours.
143
+ - **GPU util > 70% but memory low** → GPU under-fed; raise `--global-batch-size`.
144
+ - **GPU util > 70%, memory high** → healthy, it's compute-bound. Let it run.
145
+
146
+ Also: **measure real it/s yourself** (`step` delta over 90s). The tqdm `it/s` is optimistic —
147
+ it ignores the periodic stalls, so it can read 2.16 while the true rate is 0.77.
148
+
149
+ ---
150
+
151
+ ## 6. Monitor & checkpoint
152
+
153
+ - Watch loss drop, but remember **it flatlines fast and means little** (Golden Rule #4).
154
+ - Checkpoints land in `--output-dir`. Each is large and writing it to a network volume
155
+ **pauses training** for a minute or two — keep `--save-steps` moderate.
156
+ - If the pod migrates, training dies but a **persistent network volume** usually survives
157
+ (check the cloud console under *Storage → Network Volumes*, not just *Pods*). To resume:
158
+ point `--output-dir` at the dir with the latest checkpoint; the HF Trainer auto-resumes.
159
+ Caveat: `save_steps` is read from the checkpoint's `trainer_state.json` on resume and can
160
+ override your CLI flag.
161
+
162
+ ---
163
+
164
+ ## 7. ⭐ Save the model to HuggingFace BEFORE terminating
165
+
166
+ We lost a checkpoint by terminating a pod whose volume didn't persist. Don't.
167
+
168
+ ```bash
169
+ HF_TOKEN=hf_xxx HF_HUB_DISABLE_XET=1 hf upload <user>/<model-repo> \
170
+ /workspace/uf850_ckpt/checkpoint-8000 checkpoint-8000 --repo-type model
171
+ # (HF_HUB_DISABLE_XET=1 avoids the xet uploader writing a big local cache to a full disk)
172
+ ```
173
+ Wait for it to hit 100% before you touch the pod.
174
+
175
+ ---
176
+
177
+ ## 8. Terminate (stop the bleed)
178
+
179
+ In the cloud console: **Stop**, then **Terminate** (Stop alone keeps billing for storage).
180
+ Confirm in *Storage* whether you also want to delete the network volume — if your model is
181
+ on HF, you can. The GPU stops billing only when fully terminated.
182
+
183
+ ---
184
+
185
+ ## 9. Evaluating — the part everyone gets wrong
186
+
187
+ **Low loss ≠ a working policy.** Test on rollouts:
188
+ - Long-horizon, multi-stage tasks (pick→place→empty) suffer **compounding error** — small
189
+ deviations snowball. Modest data (~100 demos) often isn't enough; **more demos** is usually
190
+ the biggest quality lever.
191
+ - Deploy must match training **exactly**: same observation format (GR00T wants *nested*
192
+ `video`/`state`/`language` dicts, not flat keys), same units (radians + gripper mm here),
193
+ absolute vs relative action consistency, camera mapping, and action-chunk execution rate
194
+ (~30 Hz). A perfect policy fails if any of these differ at deploy.
195
+ - If a 20%-trained checkpoint behaves badly, that's expected — **test a converged one** before
196
+ concluding anything.
197
+
198
+ ---
199
+
200
+ ## Appendix — every error we hit, and the fix
201
+
202
+ | Symptom | Cause | Fix |
203
+ |---|---|---|
204
+ | `Disk quota exceeded`, half-written checkpoint | volume too small | provision ≥150–200 GB |
205
+ | `gcc ... -lcuda ... exit status 1` | missing `Python.h` | `apt install python3.10-dev` |
206
+ | `Video backend 'torchcodec' is not available` | missing ffmpeg libs | `apt install ffmpeg` |
207
+ | `uv sync`: `Invalid zip file structure` (flash-attn) | LFS wheels not fetched | `git lfs install && git lfs pull` |
208
+ | `tool.uv.sources ... Must provide at least one source` | over-edited pyproject | don't strip sources; use `git lfs pull` instead |
209
+ | gated model 401 / offline error | no token / `HF_HUB_OFFLINE=1` | set `HF_TOKEN`, stay online |
210
+ | GPU at 0%, slow training | AV1 decode / network I/O / 2 workers | H264 + `/dev/shm` + `--dataloader-num-workers 8` |
211
+ | tqdm says 2 it/s but it crawls | tqdm ignores stalls | measure real `step` delta over 90s |
212
+ | backgrounded SSH job dies | SSH channel close SIGHUP | use `tmux`; don't open many SSH conns |
213
+ | lost checkpoint after terminate | ephemeral pod volume | `hf upload` the checkpoint first |
214
+ | policy "doesn't learn" | tested 20% ckpt / trusted loss / deploy mismatch | train to converge, test rollouts, audit deploy |
215
+
216
+ ---
217
+
218
+ *Companion docs in this repo: `FAST_TRAINING.md` (bottleneck deep-dive), and scripts
219
+ `prep_h264.sh`, `train_fast.sh`, `train_sanity.sh`, `drop_episodes.py`, `data_viz.py`.*