Metadata-Version: 2.4
Name: gr00t-bonsai
Version: 0.1.3
Summary: Fine-tune NVIDIA Isaac-GR00T N1.7 on a single 24 GB GPU — LowMemAdamW (about 7 bytes/param), online multi-noise flow matching, Lance streaming from S3/GCS, and Spot resume that restores the data order.
Author: gr00t-bonsai contributors
License: Apache-2.0
Project-URL: Homepage, https://github.com/hly000/gr00t-bonsai
Project-URL: Repository, https://github.com/hly000/gr00t-bonsai
Project-URL: Issues, https://github.com/hly000/gr00t-bonsai/issues
Project-URL: Benchmarks, https://github.com/hly000/gr00t-bonsai/blob/main/docs/BENCHMARKS.md
Keywords: robotics,gr00t,vla,low-memory-optimizer,triton,24gb,flow-matching,lerobot,lancedb,spot-training,s3
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: numpy>=1.24
Requires-Dist: torch>=2.1
Provides-Extra: lance
Requires-Dist: lerobot-lancedb>=0.3.0; extra == "lance"
Requires-Dist: lancedb>=0.42.0b26; extra == "lance"
Requires-Dist: pandas>=2.0; extra == "lance"
Requires-Dist: pyarrow>=15.0; extra == "lance"
Provides-Extra: s3
Requires-Dist: gr00t-bonsai[lance]; extra == "s3"
Requires-Dist: boto3>=1.28; extra == "s3"
Provides-Extra: gcs
Requires-Dist: gr00t-bonsai[lance]; extra == "gcs"
Requires-Dist: gcsfs>=2024.2; extra == "gcs"
Provides-Extra: cloud
Requires-Dist: gr00t-bonsai[gcs,s3]; extra == "cloud"
Provides-Extra: vision
Requires-Dist: transformers>=4.40; extra == "vision"
Provides-Extra: plots
Requires-Dist: matplotlib>=3.7; extra == "plots"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.8; extra == "dev"
Requires-Dist: moto[server]>=5.0; extra == "dev"
Requires-Dist: av>=12.0; extra == "dev"
Requires-Dist: transformers>=4.40; extra == "dev"
Requires-Dist: accelerate>=0.30; extra == "dev"
Requires-Dist: psutil>=5.9; extra == "dev"
Dynamic: license-file

<div align="center">

# gr00t-bonsai

### Fine-tune NVIDIA GR00T N1.7 on one 24 GB GPU

NVIDIA recommends 40 GB+ to fine-tune GR00T N1.7: the default recipe peaks at **37 GB**.<br>
This repo runs it in **18 GB** on an RTX 4090, at the same batch of 32.

<p>
  <a href="https://github.com/hly000/gr00t-bonsai/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg" alt="License: Apache-2.0"></a>
  <img src="https://img.shields.io/badge/Python-3.10%2B-3776AB.svg" alt="Python 3.10+">
  <img src="https://img.shields.io/badge/PyTorch-tested%20on%202.8%20%2F%202.9-EE4C2C.svg" alt="PyTorch: tested on 2.8 and 2.9">
  <a href="https://github.com/hly000/gr00t-bonsai/actions/workflows/tests.yml"><img src="https://github.com/hly000/gr00t-bonsai/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
</p>

**English** · [简体中文](https://github.com/hly000/gr00t-bonsai/blob/main/README_ZH.md) · [Results](https://github.com/hly000/gr00t-bonsai/blob/main/docs/RESULTS.md) · [Benchmarks](https://github.com/hly000/gr00t-bonsai/blob/main/docs/BENCHMARKS.md) · [Limitations](https://github.com/hly000/gr00t-bonsai/blob/main/docs/LIMITATIONS.md) · [FAQ](https://github.com/hly000/gr00t-bonsai/blob/main/docs/FAQ.md)

<img src="https://raw.githubusercontent.com/hly000/gr00t-bonsai/main/docs/assets/fig1_hero_summary.png" width="860" alt="Peak GPU memory (stock 37.0 and 39.2 GiB, this repo 18.2 and 20.6 GiB) and LIBERO-10 success after 3,000 steps (72.3 vs 72.0 with one noise draw, 83.0 vs 83.7 with two), stock on an A100 and this repo on an RTX 4090">

</div>

| | Stock Isaac-GR00T | This repo |
|---|---|---|
| Peak GPU memory, batch 32 | 37.0 GB on an A100, out of memory on 24 GB | **18.2 GB** on an RTX 4090 |
| LIBERO-10, 3,000 steps, 3 seeds | 72.3 % | 72.0 % |
| Same, with this repo's two noise draws per frame (`K=2`) | 83 % with fp32 AdamW, 32 × 2 in one pass (1 seed, 39.2 GB) | 83.7 % with 16 × 2 accumulated twice (3 seeds, 20.6 GB) |
| Weights + gradients + optimizer state | 16 bytes/param | 7.07 bytes/param (`FlashAdamW-24`: 7.14) |
| Batches a preempted run sees after resuming | 0/50 match the uninterrupted run | 50/50 match |

**The claim is memory, not accuracy.** In these runs the 24 GB recipe scored the same as stock, not better. Each score is 100 episodes (10 per task, about ±9 points), stock was evaluated on an A100 and this repo on an RTX 4090, and three seeds cannot rule out a gap under about 10 points. "Stock" means upstream's trainer with fp32 AdamW, started through this repo's launcher on the same dataset. Memory is in GiB as `nvidia-smi` reports it. Every number comes from a file in [`results/`](https://github.com/hly000/gr00t-bonsai/tree/main/results): see the [results ledger](https://github.com/hly000/gr00t-bonsai/blob/main/docs/RESULTS.md) and the [limitations](https://github.com/hly000/gr00t-bonsai/blob/main/docs/LIMITATIONS.md).

## What is new here, and what is not

- **Fitting N1.7 in 24 GB is not new.** [gr00t-on-4090](https://github.com/VShirokun/gr00t-on-4090) does it in about 21 GiB with paged 8-bit Adam, a bf16 load and gradient checkpointing, and evaluates on its own SO-101 task. In our probes `bitsandbytes.AdamW8bit` on fp32 weights also fits: 20.1 GB at 16 frames per step and 22.5 GB at 16 × 2. We did not probe it at 32 frames, where it probably fits too. Against that route this repo offers more headroom and a faster optimizer step. It has not been shown to be more accurate.
- **The optimizer builds on [FlashOptim](https://arxiv.org/abs/2602.23349).** FlashOptim already takes AdamW from 16 to 7 bytes per parameter with 8-bit moments. The int8 weight compensation here is its weight splitting, and `FlashAdamW-24` fits this job just as well (18.3 GB, 481 ms/step against 18.2 GB, 469 ms). What differs is the encoding of the two moments. The only closed-loop comparison is one batch-16 run each, 38/100 for `FlashAdamW` and 46/100 for `LowMemAdamW`, which is within noise.
- **`K=2` is a known technique** (the `diffusion_batch_mul` of [MAR](https://github.com/LTH14/mar), [Mini Diffuser](https://arxiv.org/abs/2505.09430)). The gain does not come from the memory work: the one fp32 run with `K=2` also scored 83.
- **What this repo adds:** the 24 GB recipe measured over three seeds, a seeded LIBERO evaluator that runs one process per episode, a Lance data layer for GR00T, and resume that restores the data order. It also has optional per-block DiT activation checkpointing (upstream declares a `gradient_checkpointing` flag that its forward pass never reads); that is used in one memory probe and in none of the published runs.

## Quickstart

```bash
pip install gr00t-bonsai                      # torch and numpy only

# or from a clone:
git clone https://github.com/hly000/gr00t-bonsai && cd gr00t-bonsai
pip install -e .                              # torch and numpy only
python examples/standalone_lowmem_adamw.py    # the optimizer on a toy model, CPU or GPU, under a minute
```

## Fine-tune GR00T on 24 GB

Needs one 24 GB NVIDIA GPU, `git-lfs`, `ffmpeg`, [uv](https://docs.astral.sh/uv/), and a Hugging Face login that has accepted the terms of the gated `nvidia/Cosmos-Reason2-2B` ([full requirements](https://github.com/hly000/gr00t-bonsai/blob/main/docs/LIMITATIONS.md#requirements)). It trains what upstream trains by default: the projector and DiT action head (1.62B parameters), with the VLM frozen.

```bash
# 1. Isaac-GR00T, installed its own way (checked at commit 708617f)
git clone https://github.com/NVIDIA/Isaac-GR00T && cd Isaac-GR00T && git lfs pull
uv sync --python 3.12

# 2. this repository, into the same environment
git clone https://github.com/hly000/gr00t-bonsai ../gr00t-bonsai
uv pip install -e ../gr00t-bonsai
.venv/bin/gr00t-bonsai-data-setup     # detects Isaac-GR00T and leaves its packages unchanged

# 3. a dataset: LIBERO-10 in the LeRobot v2.1 format upstream uses
.venv/bin/hf download --repo-type dataset IPEC-COMMUNITY/libero_10_no_noops_1.0.0_lerobot \
  --local-dir examples/LIBERO/libero_10_no_noops_1.0.0_lerobot
cp examples/LIBERO/modality.json examples/LIBERO/libero_10_no_noops_1.0.0_lerobot/meta/

# 4. train
export GR00T_ROOT=$PWD
cd ../gr00t-bonsai
MODE=lowmem24_b32 BACKEND=native EVAL=0 EMA_DECAY=0 MAX_STEPS=3000 TRAIN_SEED=42 OUT_ROOT=$PWD/runs \
  DATASET=$GR00T_ROOT/examples/LIBERO/libero_10_no_noops_1.0.0_lerobot bash scripts/run_online_turbo.sh
```

| `MODE` | Frames × noise draws | Peak memory (RTX 4090) | 3,000 steps take | LIBERO-10, 3 seeds |
|---|---|---:|---:|---:|
| `lowmem24_b32` | 32 × 1 | 18.2 GB | 28 min | 72.0 % |
| `lowmem24_mn2_ga2` | 16 × 2, accumulated twice | 20.6 GB | 32 min | 83.7 % |

The script checks the kernel, runs a 5-step smoke test, then trains; the checkpoint loads in upstream `run_gr00t_server.py`. These steps were run as written on a rented RTX 4090 for 20 steps (peak 18.2 GB).

- `BACKEND=native` reads the LeRobot v2.1 directory with upstream's loader. The published runs used `BACKEND=lance` on a converted dataset, which trains the same way ([data section](#stream-from-s3-or-gcs-resume-in-the-same-data-order)).
- `EVAL=0` skips the LIBERO evaluation, which needs upstream's simulator environment (`gr00t/eval/sim/LIBERO/setup_libero.sh`). With it installed, drop `EVAL=0` and add `N_EPISODES=10` for the 100-episode protocol.
- The launcher patches upstream at run time, so a newer Isaac-GR00T may need fixes.

One 20,000-step run reached 90/100. NVIDIA's released LIBERO checkpoint scored 85 on the same evaluator and 91 and 93 on an A100, so read this as in the same range, not as a win: it is one seed with no 20,000-step stock baseline.

## Use the optimizer anywhere

`LowMemAdamW` works with any PyTorch model that has `bfloat16` weights. It does not need GR00T or Lance.

```python
import torch
from gr00t_bonsai import LowMemAdamW

for p in model.parameters():
    if p.ndim >= 2:
        p.data = p.data.to(torch.bfloat16)          # this snippet keeps 1-D parameters in fp32

optimizer = LowMemAdamW(model.parameters(), lr=1e-4, weight_decay=1e-5, comp_dtype="int8")

with torch.autocast("cuda", dtype=torch.bfloat16):
    loss = model(batch)
loss.backward()
_, scale = optimizer.clip_scale(max_norm=1.0)       # global-norm clip without rewriting the grads
optimizer.step(grad_scale=scale)
optimizer.zero_grad(set_to_none=True)
```

`comp_dtype="int8"` is what the 24 GB modes use; the default `"bf16"` takes one more byte per parameter. On the 1.62B-parameter action head (RTX 4090) it is level with `FlashAdamW-24`: 22.35 ms/step and 7.07 bytes/param against 23.18 ms and 7.14. `bitsandbytes.AdamW8bit` takes 47.90 ms at 10.05 bytes/param on fp32 weights. [Full table](https://github.com/hly000/gr00t-bonsai/blob/main/docs/RESULTS.md#optimizer-microbenchmark-537-action-head-tensors-162b-parameters) · [runnable example with EMA](https://github.com/hly000/gr00t-bonsai/blob/main/examples/standalone_lowmem_adamw.py)

## Stream from S3 or GCS, resume in the same data order

Train from object storage with no download first. After a Spot preemption, the resumed run reads the same batches the uninterrupted run would have (50/50 batch fingerprints matched in one 80-step test; stock reseeds its loader). This is a guarantee about data order, not about bit-identical weights.

```bash
pip install gr00t-bonsai
gr00t-bonsai-data-setup        # installs and verifies the data layer, about 90 seconds
```

The second command exists because two requirements are not on PyPI, so `pip install "gr00t-bonsai[cloud]"` alone cannot resolve them: `lancedb>=0.42.0b26` is a prerelease on LanceDB's own package index, and `lerobot-lancedb` is needed at a GitHub commit newer than its PyPI release. `gr00t-bonsai-data-setup --dry-run` prints the pip commands it runs.

Run the conversion tools from an environment like this one, not from inside Isaac-GR00T's: lerobot needs a newer `huggingface-hub` and `numpy` than GR00T pins. Inside Isaac-GR00T's environment the same command installs only what training from Lance needs.

```bash
# convert a GR00T v2.1 dataset (videos are referenced, not copied)
gr00t-lance-convert --src s3://my-bucket/my-v2-dataset --out s3://my-bucket/my-v2-lance --video-mode external
```

The training script above reads Lance through [`scripts/launch_finetune_lance.py`](https://github.com/hly000/gr00t-bonsai/blob/main/scripts/launch_finetune_lance.py). Measurements: [Benchmarks](https://github.com/hly000/gr00t-bonsai/blob/main/docs/BENCHMARKS.md#lance-data-layer-spot-resume-and-curation-a100).

## How it works

<div align="center">
<img src="https://raw.githubusercontent.com/hly000/gr00t-bonsai/main/docs/assets/architecture.png" width="820" alt="24 GB fine-tuning pipeline: Lance dataset, frozen bf16 VLM backbone, K noise draws per frame, the trainable action head, LowMemAdamW, and optional DiT activation checkpointing">
</div>

- **`LowMemAdamW`** stores weights in bf16 and carries the rounding error of each update in one int8 per weight (FlashOptim's scheme). The second moment is an 8-bit code with a 5-bit exponent and 3-bit mantissa, the first moment is stored as `m/√v` in int8, and both use stochastic rounding.
- **Multi-noise flow matching** runs the frozen VLM once per batch and trains the action head on `K` stratified timesteps and noise draws per frame.
- **DiT activation checkpointing** (5 in the figure) is optional and off in the published modes.
- **`CpuShadowEMA`** keeps an optional fp32 EMA in host RAM instead of on the GPU.

Isaac-GR00T is not forked or patched on disk: everything is applied at run time.

## Limitations

- Measured only on GR00T N1.7-3B with the VLM frozen, on LIBERO-10 and one LIBERO-Spatial run.
- Evaluations are 100 episodes, not the usual 500, and rollouts are not deterministic: the same checkpoint with the same seeds differed on 12 of 100 episodes.
- The stock and 24 GB arms were trained and evaluated on different machines.
- Memory figures are 30-step probes, not peaks over a full run.
- `K=2` costs about 17 % more training time and comes bundled with stratified timestep sampling. Neither an equal-compute `K=1` baseline nor that ablation has been run.
- Keep 32 frames per optimizer step. In one run at the same step count, a batch of 16 scored 36 against 75.
- The Triton kernel is tested against the CPU reference on a GPU, but CI runs on CPU only.

The full list, with negative results and the differences from upstream, is in [docs/LIMITATIONS.md](https://github.com/hly000/gr00t-bonsai/blob/main/docs/LIMITATIONS.md). Commands that reproduce every table are in [docs/BENCHMARKS.md](https://github.com/hly000/gr00t-bonsai/blob/main/docs/BENCHMARKS.md#reproduction-commands).

## Citation

```bibtex
@software{gr00t_bonsai_2026,
  title  = {gr00t-bonsai: 24 GB single-GPU fine-tuning, Lance streaming and Spot resume for NVIDIA Isaac-GR00T},
  author = {{gr00t-bonsai contributors}},
  year   = {2026},
  url    = {https://github.com/hly000/gr00t-bonsai}
}
```

If you use the optimizer, please also cite [FlashOptim](https://arxiv.org/abs/2602.23349).

## Acknowledgments

Built on [NVIDIA Isaac-GR00T](https://github.com/NVIDIA/Isaac-GR00T), [Hugging Face LeRobot](https://github.com/huggingface/lerobot) and [lerobot-lancedb](https://github.com/lancedb/lerobot-lancedb), and evaluated with [LIBERO](https://github.com/Lifelong-Robot-Learning/LIBERO). Parts of the code are adapted from Isaac-GR00T (Apache-2.0); see [NOTICE](https://github.com/hly000/gr00t-bonsai/blob/main/NOTICE). The optimizer follows [FlashOptim](https://github.com/databricks/flashoptim) for weight compensation and uses it and [bitsandbytes](https://github.com/bitsandbytes-foundation/bitsandbytes) as baselines; no code from either is included.

Contributions are welcome: see [CONTRIBUTING.md](https://github.com/hly000/gr00t-bonsai/blob/main/CONTRIBUTING.md) and the [changelog](https://github.com/hly000/gr00t-bonsai/blob/main/CHANGELOG.md).

## License

The code in this repository is licensed under [Apache-2.0](https://github.com/hly000/gr00t-bonsai/blob/main/LICENSE). See also [NOTICE](https://github.com/hly000/gr00t-bonsai/blob/main/NOTICE).

- **NVIDIA Isaac-GR00T** (runtime dependency): the upstream *code* is Apache-2.0. **Model weights** such as `nvidia/GR00T-N1.7-3B` are licensed separately under the [NVIDIA Open Model License](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license/). You must accept that license to download and use the weights; this repository's Apache-2.0 license does not grant it.
- **LIBERO** (evaluation): the [LIBERO](https://github.com/Lifelong-Robot-Learning/LIBERO) *codebase* is MIT; the demonstration *datasets* are [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).

This project is independent and is not affiliated with or endorsed by NVIDIA or LanceDB.
