# Training GR00T on a rented GPU — the complete guide (learned the hard way) This is the end-to-end playbook for fine-tuning **NVIDIA GR00T N1.7-3B** on your own robot demos, on a rented cloud GPU (RunPod-style) or any SLURM cluster. It's written for someone who has **never done this before**, and every step encodes a mistake we already made so you don't repeat it. Read the **Golden Rules** first — they're the whole game. --- ## ⭐ The 5 Golden Rules (if you read nothing else) 1. **Within 2 minutes of launching training, check GPU utilization.** If it's not **>70%**, STOP — you're wasting money on an idle GPU. We once ran for *hours* at 0% GPU before noticing. `nvidia-smi --query-gpu=utilization.gpu --format=csv` is your best friend. 2. **Re-encode your videos to H264 *before* training.** Datasets recorded as AV1 decode ~3–10× slower on CPU and will starve the GPU. This was our #1 hidden bottleneck. 3. **Save your trained checkpoint to HuggingFace BEFORE you terminate the pod.** We lost a checkpoint because the pod's disk vanished on termination. The pod is ephemeral; HF is not. 4. **Don't trust the loss, and don't over-train.** GR00T's flow-matching loss flatlines at ~0.05 by ~step 2000 and means *nothing* about task success. Train ~8k steps, judge by running the policy on the robot — not by the loss curve. 5. **Terminate the pod the moment you're done.** A GPU bills every second, including while it sits idle during setup or after training finishes. --- ## 0. What you're actually doing You have robot demonstrations (a **LeRobot v2.1 dataset**: camera videos + joint states). You fine-tune the 3B GR00T vision-language-action model to imitate them, then deploy the trained policy back onto the robot. Training needs a **modern GPU** (Ampere or newer): | GPU | Full fine-tune of 3B? | Notes | |---|---|---| | H100 / H200 / A100 80GB | ✅ comfortably | what you want | | L40S / A6000 / RTX 6000 Ada (48GB) | ⚠️ tight (~44GB used) | batch=1 + grad checkpointing | | Anything pre-Ampere (e.g. Tesla K40, RTX Turing) | ❌ no | no bf16, no flash-attn, too little VRAM | Budget ~**$2–3/hr** for an H100. Setup is ~20–30 min, training ~1 hr → plan for ~$5–8/run. --- ## 1. Provision the pod (don't skimp here — it caused our worst crashes) - **GPU:** H100 or H200 80GB (A100 80GB fine). 48GB cards work but are tight. - **Disk / volume: ≥ 150–200 GB.** Our first pod had a tiny volume → `Disk quota exceeded` mid-training, producing a **corrupt half-written checkpoint**. The venv (~20GB), model cache (~12GB), and checkpoints (~13–25GB each) add up fast. - **SSH key:** add a *passphrase-less* ed25519 key to your cloud account before booting (`ssh-keygen -t ed25519 -f ~/.ssh/runpod`). A key with a passphrase can't be used for automation. On a *migrated* container the key sometimes isn't injected — paste your pubkey into `/root/.ssh/authorized_keys` via the web terminal if direct SSH is refused. --- ## 2. Environment setup (the part that fights you) Fresh containers have **nothing** — and these get wiped on every new pod / migration: ```bash # system deps — MISSING THESE CAUSES SILENT TRAINING CRASHES: apt-get update && apt-get install -y python3.10-dev ffmpeg git git-lfs curl build-essential # python3.10-dev -> Triton JIT-compiles CUDA at runtime; without Python.h it dies # with a cryptic "gcc ... -lcuda ... exit 1" # ffmpeg -> torchcodec (video decode) won't load without libav*; training dies # at dataset setup with "Video backend 'torchcodec' is not available" # uv (the package manager GR00T uses) curl -LsSf https://astral.sh/uv/install.sh | sh ; export PATH="$HOME/.local/bin:$PATH" # clone GR00T + fetch its LFS wheels (CRITICAL) cd /workspace && git clone https://github.com/NVIDIA/Isaac-GR00T cd Isaac-GR00T && git lfs install && git lfs pull # ^ GR00T's pyproject does a UNIVERSAL multi-platform resolve and references local # aarch64 flash-attn/torchcodec wheels tracked by git-LFS. A plain clone leaves them # as LFS *pointers*, so `uv sync` fails: "Invalid zip file structure". `git lfs pull` # makes them real. (You're on x86_64; uv still reads the aarch64 metadata to resolve.) # build the env (~10–20 min — the long pole) uv sync ``` **HuggingFace auth:** the GR00T backbone (`nvidia/Cosmos-Reason2-2B`) is **gated**. Set a token, and point the cache at the big volume: ```bash export HF_HOME=/workspace/hf HF_TOKEN=hf_xxx # a token with access to the gated model ``` Note: `HF_HUB_OFFLINE=1` does **not** fall back to cache for gated models — it errors. Keep it online with a token. --- ## 3. Prepare the data (this is where the speed comes from) **Re-encode AV1 → all-intra H264.** This single step is the difference between a 1-hour run and a 5-hour one, because AV1 decode (not the GPU) is the bottleneck. ```bash # scripts/prep_h264.sh — re-encodes every video, preserves frame counts, # flips meta/info.json codec to h264. ~2 min on many cores. bash scripts/prep_h264.sh /workspace/uf850_data ``` Then **audit the data** (we found dead/never-grasped episodes that teach the policy to do nothing, and IK-flip glitch frames): use `scripts/drop_episodes.py` to remove bad episodes (it re-indexes the LeRobot metadata correctly) and `scripts/data_viz.py` to eyeball them. **Stage the dataset in RAM** right before training — the network volume has high I/O latency: ```bash cp -r /workspace/uf850_data /dev/shm/uf850_data # ~1 GB fits in RAM trivially ``` --- ## 4. Launch training (the fast recipe) ```bash cd /workspace/Isaac-GR00T export PATH="$HOME/.local/bin:$PATH" HF_HOME=/workspace/hf HF_TOKEN=hf_xxx PYTHONUNBUFFERED=1 uv run --no-sync python gr00t/experiment/launch_finetune.py \ --base-model-path nvidia/GR00T-N1.7-3B \ --dataset-path /dev/shm/uf850_data --embodiment-tag NEW_EMBODIMENT \ --modality-config-path examples/UF850/uf850_config.py \ --num-gpus 1 --output-dir /workspace/uf850_ckpt \ --dataloader-num-workers 8 \ # default is 2 — way too few; 8–16 once data is H264 --max-steps 8000 \ # loss converges ~2k; 8k is plenty, half the cost of 15k --save-steps 2000 --save-total-limit 2 # few checkpoint writes (each ~13–25GB to slow disk) ``` (`scripts/train_fast.sh` wraps all of this.) Keep it running across SSH drops with **`tmux`** or `nohup`. Note: naive backgrounding over SSH (`cmd &`) often dies on channel-close, and opening many SSH connections gets you rate-limited (`kex_exchange_identification: Connection reset`). Use one `tmux` session. --- ## 5. ⭐ THE SANITY GATE — do this every single run (2 minutes) This is Golden Rule #1 made concrete. ~2 min after launch (past the first-epoch shard-cache warmup), run `scripts/train_sanity.sh`. It measures over ~60s and tells you: - **GPU util < 30%** → you're **data-bound** (decode / I/O / too few workers / augmentation). Stop and fix the input pipeline. Don't let it crawl for hours. - **GPU util > 70% but memory low** → GPU under-fed; raise `--global-batch-size`. - **GPU util > 70%, memory high** → healthy, it's compute-bound. Let it run. Also: **measure real it/s yourself** (`step` delta over 90s). The tqdm `it/s` is optimistic — it ignores the periodic stalls, so it can read 2.16 while the true rate is 0.77. --- ## 6. Monitor & checkpoint - Watch loss drop, but remember **it flatlines fast and means little** (Golden Rule #4). - Checkpoints land in `--output-dir`. Each is large and writing it to a network volume **pauses training** for a minute or two — keep `--save-steps` moderate. - If the pod migrates, training dies but a **persistent network volume** usually survives (check the cloud console under *Storage → Network Volumes*, not just *Pods*). To resume: point `--output-dir` at the dir with the latest checkpoint; the HF Trainer auto-resumes. Caveat: `save_steps` is read from the checkpoint's `trainer_state.json` on resume and can override your CLI flag. --- ## 7. ⭐ Save the model to HuggingFace BEFORE terminating We lost a checkpoint by terminating a pod whose volume didn't persist. Don't. ```bash HF_TOKEN=hf_xxx HF_HUB_DISABLE_XET=1 hf upload / \ /workspace/uf850_ckpt/checkpoint-8000 checkpoint-8000 --repo-type model # (HF_HUB_DISABLE_XET=1 avoids the xet uploader writing a big local cache to a full disk) ``` Wait for it to hit 100% before you touch the pod. --- ## 8. Terminate (stop the bleed) In the cloud console: **Stop**, then **Terminate** (Stop alone keeps billing for storage). Confirm in *Storage* whether you also want to delete the network volume — if your model is on HF, you can. The GPU stops billing only when fully terminated. --- ## 9. Evaluating — the part everyone gets wrong **Low loss ≠ a working policy.** Test on rollouts: - Long-horizon, multi-stage tasks (pick→place→empty) suffer **compounding error** — small deviations snowball. Modest data (~100 demos) often isn't enough; **more demos** is usually the biggest quality lever. - Deploy must match training **exactly**: same observation format (GR00T wants *nested* `video`/`state`/`language` dicts, not flat keys), same units (radians + gripper mm here), absolute vs relative action consistency, camera mapping, and action-chunk execution rate (~30 Hz). A perfect policy fails if any of these differ at deploy. - If a 20%-trained checkpoint behaves badly, that's expected — **test a converged one** before concluding anything. --- ## Appendix — every error we hit, and the fix | Symptom | Cause | Fix | |---|---|---| | `Disk quota exceeded`, half-written checkpoint | volume too small | provision ≥150–200 GB | | `gcc ... -lcuda ... exit status 1` | missing `Python.h` | `apt install python3.10-dev` | | `Video backend 'torchcodec' is not available` | missing ffmpeg libs | `apt install ffmpeg` | | `uv sync`: `Invalid zip file structure` (flash-attn) | LFS wheels not fetched | `git lfs install && git lfs pull` | | `tool.uv.sources ... Must provide at least one source` | over-edited pyproject | don't strip sources; use `git lfs pull` instead | | gated model 401 / offline error | no token / `HF_HUB_OFFLINE=1` | set `HF_TOKEN`, stay online | | GPU at 0%, slow training | AV1 decode / network I/O / 2 workers | H264 + `/dev/shm` + `--dataloader-num-workers 8` | | tqdm says 2 it/s but it crawls | tqdm ignores stalls | measure real `step` delta over 90s | | backgrounded SSH job dies | SSH channel close SIGHUP | use `tmux`; don't open many SSH conns | | lost checkpoint after terminate | ephemeral pod volume | `hf upload` the checkpoint first | | policy "doesn't learn" | tested 20% ckpt / trusted loss / deploy mismatch | train to converge, test rollouts, audit deploy | --- *Companion docs in this repo: `FAST_TRAINING.md` (bottleneck deep-dive), and scripts `prep_h264.sh`, `train_fast.sh`, `train_sanity.sh`, `drop_episodes.py`, `data_viz.py`.*