[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-109162":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":14,"forks30d":14,"starsTrendScore":18,"compositeScore":19,"rankGlobal":9,"rankLanguage":9,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":9,"pushedAt":25,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":14,"starSnapshotCount":14,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},109162,"terrain-grounded-imagination","leggedrobotics\u002Fterrain-grounded-imagination","leggedrobotics","Terrain Grounded Imagination: a recipe for training humanoid locomotion on sparse and rough terrain through a world model with differentiable heightmap lookups.",null,"Python",148,7,68,0,8,27,61,29,78.14,"MIT License",false,"main",true,[],"2026-11-11 16:49:30","2026-11-23 19:14:50","# Terrain-Grounded Imagination\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"media\u002Fmethod.gif\" width=\"640\" alt=\"Method overview: rollout in simulation, terrain-grounded imagination, a poorly supported touchdown, backpropagating the imagined return, event-gated return, policy update\">\n\u003C\u002Fp>\n\nCode for *Terrain-Grounded Imagination: A Recipe for Humanoid Locomotion on Sparse Terrain through World Models* ([citation](#citation)).\n\nTerrain-grounded imagination (TGI) trains a Unitree G1 humanoid to walk over stairs, gaps and stepping stones entirely through a learned world model. The world model learns only how the robot responds to the ground beneath it. The ground itself, the rewards and the robot's perception are read from the simulator's heightmap through cheap, differentiable lookups.\n\n- **Terrain-conditioned world model.** The model predicts the robot's motion from the terrain it reads under the pelvis and the soles, instead of holding the terrain in its weights. The rewards, terminations and critic read the same heightmap, so gaps and edges are exact in imagination, and the gradient flows through the lookups.\n- **Perception without rendering.** The policy uses the foothold-gated perception of [Watch Your Step](https:\u002F\u002Fleggedrobotics.github.io\u002Fwatch-your-step\u002F): a foothold prediction model (FPM) predicts the next footholds from proprioception, and the policy sees the heightmap only around them. In imagination, the FPM runs on the imagined state and the patches are read at the imagined footholds, so the imagined observation is computed as in the simulator. The full height scan is an option.\n- **Gradient cut at poorly supported touchdowns.** The policy backpropagates the return through 32 imagined steps, with a critic after them. The same lookups detect imagined touchdowns on which much of the sole is unsupported. The backpropagated gradient becomes unreliable there, so the return is cut and the critic takes over.\n\n\u003Ctable>\n  \u003Ctr>\n    \u003Ctd width=\"50%\">\u003Cimg src=\"media\u002Fcourse.gif\" width=\"100%\" alt=\"G1 walking a course of tilted slabs, stairs and stepping stones\">\u003C\u002Ftd>\n    \u003Ctd width=\"50%\">\u003Cimg src=\"media\u002Fcorridor.gif\" width=\"100%\" alt=\"G1 walking through a walled corridor of stepping stones, blocks and stairs\">\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd align=\"center\">Course\u003C\u002Ftd>\n    \u003Ctd align=\"center\">Corridor\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd width=\"50%\">\u003Cimg src=\"media\u002Frough.gif\" width=\"100%\" alt=\"G1 walking over rough terrain\">\u003C\u002Ftd>\n    \u003Ctd width=\"50%\">\u003Cimg src=\"media\u002Fwaves.gif\" width=\"100%\" alt=\"G1 walking over steep waves\">\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd align=\"center\">Rough terrain\u003C\u002Ftd>\n    \u003Ctd align=\"center\">Steep waves\u003C\u002Ftd>\n  \u003C\u002Ftr>\n\u003C\u002Ftable>\n\n## Results\n\nThe released recipe (the defaults of `scripts\u002Ftrain.py`, 8192 environments) after 40k iterations, on the `fpm` validation suites (Isaac Lab 3, PhysX; see [Evaluation](#evaluation)). Mean ± standard deviation over five seeds, in %:\n\n| Test | Metric | Result |\n|---|---|---|\n| Locomotion, 13 terrains | success \u002F falls | 81.8 ± 2.5 \u002F 1.7 ± 0.5 |\n| Locomotion with 20 cm stepping stones | success \u002F falls | 77.9 ± 2.1 \u002F 5.5 ± 0.5 |\n| Corridor, 39 sections | crossed \u002F reached \u002F fell | 92.3 ± 3.1 \u002F 75.5 ± 7.3 \u002F 12.3 ± 3.2 |\n\nTraining to 40k takes 0.82 billion simulator transitions: 15.6 h on a Quadro RTX 6000 or 10.9 h on an RTX 3090.\n\n## Installation\n\nThe repository has two packages:\n\n- [`fpm\u002F`](fpm): the foothold prediction model and the G1 locomotion environments of [foothold-prediction-model](https:\u002F\u002Fgithub.com\u002Fleggedrobotics\u002Ffoothold-prediction-model), as an Isaac Lab 3 task package with PPO training, play and the validation suites.\n- [`tgi\u002F`](tgi): the world-model training. It runs the `fpm` environment on Newton physics, and its exported policies use the `fpm` observation and checkpoint formats, so they play and are evaluated in the `fpm` environments.\n\nTested on Linux with Isaac Lab 3.0.0 (Isaac Sim 6.1, Newton 1.6.1, PyTorch 2.11). Install [Isaac Lab 3.0](https:\u002F\u002Fisaac-sim.github.io\u002FIsaacLab\u002F) first, then run the commands below in its Python environment (or use `\u003CIsaacLab>\u002Fisaaclab.sh -p` in place of `python`).\n\n1. Clone the repo and install both packages (`fpm` first):\n\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Fleggedrobotics\u002Fterrain-grounded-imagination\n   cd terrain-grounded-imagination\n   pip install -e fpm --no-deps\n   pip install -e tgi\n   ```\n\n2. Convert the G1 model for Newton (once):\n\n   ```bash\n   cd tgi\n   python scripts\u002Fconvert_g1_usd.py\n   ```\n\n3. Check the installation with a short run through every training phase (about 10 minutes, 12 GB of GPU memory):\n\n   ```bash\n   python scripts\u002Ftrain.py --log_dir logs\u002Fcheck --num_envs 2048 --vram_gb 12 --iterations 400 \\\n       --wm_only_iters 100 --fpm_bootstrap 150 --async_after 200 --ckpt_every 400 --eval_every 0 --quick_every 0\n   python scripts\u002Fexport.py --ckpt logs\u002Fcheck\u002Fckpt_000400.pt\n   ```\n\nThe TGI commands below run from `tgi\u002F`, the `fpm` commands from `fpm\u002F`.\n\n## Training\n\n```bash\nscripts\u002Fpipeline.sh \u003Crun_name>\n```\n\ntrains the full recipe from scratch into `logs\u002F\u003Crun_name>\u002F`, then exports, evaluates and records videos of the final policy. The recipe runs 100k iterations on 8192 environments and needs about 22 GB of GPU memory; on an 11 GB GPU, add `--num_envs 4096 --vram_gb 10.5`. Checkpoints are saved every 1000 iterations, with background course checks every 2k (`quick_\u003Cit>.txt`) and 20k iterations (`check_\u003Cit>.txt`). To train without the pipeline:\n\n```bash\npython scripts\u002Ftrain.py --log_dir logs\u002F\u003Crun_name>\n```\n\nThe first 300 iterations train only the world model. Until iteration 1500 the footholds are fixed under the robot; after that, the FPM places them.\n\nThe [results](#results) are the 40k checkpoint, and they change little after it. To stop there, add `--iterations 40000`; the learning rates decay over `--lr_decay_iters` (100k) whatever `--iterations` is, so this trains exactly the reported runs. The reported runs trained in fp32: on GPUs with native bf16, where the default is mixed precision, add `--amp none` to match them.\n\nMeasured speeds of the recipe:\n\n| GPU | Environments | Speed |\n|---|---|---|\n| Quadro RTX 6000 (24 GB, fp32) | 8192 | 0.71 to 0.75 it\u002Fs (0.61 before the simulator overlap starts at iteration 1600); 15.6 h to 40k |\n| RTX 3090 (24 GB) | 8192 | about 1.1 it\u002Fs; 10.9 h to 40k |\n| RTX 2080 Ti (11 GB, fp32) | 4096 | 0.92 it\u002Fs after iteration 1600 |\n\nTo recover from a crash, `RESUME=1 scripts\u002Fpipeline.sh \u003Crun_name> [the run's extra flags]` continues from `last.pt`. Pass the run's extra flags again (for example `--num_envs 4096 --vram_gb 10.5`): a resume does not read them from the checkpoint. It restores the networks, the normalizers and the optimizers of the world model, policy and critic, but not the FPM's optimizer, the replay buffer or the curriculum statistics, so the terrain level dips for a few thousand iterations after it.\n\n## Export\n\n```bash\npython scripts\u002Fexport.py --ckpt logs\u002F\u003Crun_name>\u002Fckpt_100000.pt\n```\n\nwrites `logs\u002F\u003Crun_name>\u002Fexport_100000\u002F` with `model_100000.pt` (rsl-rl 3.3.0 checkpoint layout, observation normalization baked into the actor) and `foot_model_100000.pt` (TorchScript FPM), the `fpm` formats, plus `exported\u002Fpolicy.onnx`, `exported\u002Ffoot_model.onnx` and `exported\u002Fdeploy.json`. Play it in the `fpm` environment with `python scripts\u002Fplay.py --checkpoint \u003Cexport dir>\u002Fmodel_100000.pt` from `fpm\u002F`.\n\nA `--scan full` checkpoint exports without a foot model. Its policy reads the environment's `height_scan`, so run the `fpm` environments with `FPM_POLICY_SCAN=full` set, which swaps the policy's `foothold_scan` for `height_scan` (for example `FPM_POLICY_SCAN=full bash scripts\u002Fisaac_eval.sh ...`). `sim2sim.py` and the NumPy\u002FONNX controller in `tgi\u002Fdeploy\u002F` support the foothold interface only.\n\n## Evaluation\n\n```bash\npython scripts\u002Fsim2sim.py --export_dir logs\u002F\u003Crun_name>\u002Fexport_100000 --terrains stairs:0.20 fpmstones:0.6 pit:0.30 --repeats 2\nbash scripts\u002Fisaac_eval.sh logs\u002F\u003Crun_name>\u002Fexport_100000\u002Fmodel_100000.pt 520 cuda:0\n```\n\n`sim2sim.py` runs the exported ONNX controller in plain MuJoCo with Unitree's official G1 model, its own 500 Hz PD loop, 20 ms latency and ray-cast perception: stairs (`stairs:rise`), random blocks (`blocks:max_height`), stepping stones over a pit (`stones:gap[:size]`, `fpmstones:difficulty` for the training stones), drops (`drop:h`), and stepping out of a 2 x 2 m pit (`pit:h`). A course counts as crossed if the robot is upright and past it. `isaac_eval.sh` runs the `fpm` locomotion validation (13 terrains at difficulty 0.5, PhysX) as a quick check: 1100 steps with the startup randomization on, so its numbers are not comparable with the [results](#results), which use the full protocol below. `scripts\u002Fcheck.sh \u003Cckpt>` runs both. Our sim2sim runs used MuJoCo 3.16.0; other MuJoCo versions give individual episodes that differ, so compare runs under one version.\n\nThe validation suites behind the [results](#results) are in `fpm\u002Fscripts` (see [fpm\u002FREADME.md](fpm\u002FREADME.md)); run them from `fpm\u002F` with `--save_results` and the startup randomization zeroed (`env.events.base_com.params.com_range.{x,y,z}=[0.0,0.0] env.events.default_joint_pos_offset.params.position_range=[0.0,0.0]`):\n\n- **Locomotion** (13 terrains): `python scripts\u002Fvalidate_locomotion.py --checkpoint \u003Cmodel.pt> --num_envs 520 --num_steps 3300 env.sim.physics.gpu_found_lost_pairs_capacity=16777216 env.sim.physics.gpu_found_lost_aggregate_pairs_capacity=67108864`. Larger env counts overflow PhysX's pair buffers and produce fake falls.\n- **Locomotion with 20 cm stepping stones**: the same, plus `env.scene.terrain.terrain_generator.sub_terrains.train_stepping_stones.stone_width_range=[0.2,0.2] env.scene.terrain.terrain_generator.sub_terrains.train_stepping_stones.stone_distance_range=[0.2,0.2]`.\n- **Corridor** (13 sections in each of three corridors: straight, stones, blocks): `python scripts\u002Fvalidate_corridor.py --checkpoint \u003Cmodel.pt> --rounds 4`.\n\n## Options\n\nEvery option is a flag of `scripts\u002Ftrain.py`; the defaults are the recipe. The observations below come from our runs. Unless a row says otherwise, they are single seeds, and the smaller tests used 4096 environments on RTX 2080 Ti GPUs, so treat them as indications, not settled results.\n\n**Method**\n\n| Flag | What it changes | Observed |\n|---|---|---|\n| `--scan foothold` \u002F `full` | Policy perception: foothold patches (default), or the whole 1.6 x 1.0 m torso height scan (33 x 21 nodes, the base env's `height_scan`) with no FPM | one seed: behind the foothold patches at every checkpoint up to 50k; at 40k, locomotion success 75.0 vs 81.8 %, 20 cm stones 16.1 vs 29.0 %, corridor crossed 83.3 vs 92.3 % (foothold patches: five-seed mean) |\n| `--fpm 0` | Fixed footholds under the base for the whole run (no learned FPM) | |\n| `--pg_event 0.3`, `--pg_lambda 0` | Cut the gradient through the model at imagined touchdowns with an unsupported sole share above `pg_event`, and bootstrap from the critic there (`--pg_event 0`: plain H-step return) | part of the recipe |\n| `--horizon 32` | Imagination horizon (steps of 20 ms) | 64: policy gradient norms about 10x higher, 27 % slower, no gain |\n| `--lr_coef 0.1` | Weight of the likelihood-ratio (advantage) term next to backpropagation through the model | 0.5 together with `--w_foothold -6` was worse on the corridor and stepping stones |\n| `--wm_opt muon` \u002F `adam` | Optimizer of the world model's hidden weight matrices (Muon, RMS-matched to the Adam learning rate; Adam for biases, norms and small layers) | in an earlier short test (two seeds), Muon halved the world model's 8-step error and the policy learned faster early; about 10 % slower per iteration |\n| `--pi_opt adam` \u002F `muon` | The same for the policy | Muon on the policy learned clearly slower |\n| `--sym_coef 2` | Left\u002Fright mirror-consistency loss on the policy | part of the recipe |\n\n**Curriculum and environment**\n\n| Flag | What it changes | Observed |\n|---|---|---|\n| `--sgs_target 0.8` | Success rate the terrain sampler aims for | 0.5 was not better (corridor stepping stones worse at 26k iterations) |\n| `--straight_frac 0` | Share of episodes with no yaw command and no heading control, as in the evaluations | 0.05 made no measurable difference |\n| `--stepping_stones 0.6`, `--pit_step 0.05` | Terrain mix | defaults |\n| `--w_*`, `--term_hole`, `--term_angle` | Reward weights and imagined terminations | defaults |\n\n**Heightmap resolution.** `--hm_res 0.04` is the tested resolution. At `--hm_res 0.01` the policy gradients explode (norms of 1e5 to 1e14 once the policy trains; clipping hides it, but learning stalls). `--grad_blur \u003Csigma>` keeps the exact heights in the forward pass and takes the gradient from a Gaussian-blurred map; it does not fix 1 cm training, from scratch or warm-started (also with `--resume_wm_only`). `--hm_exact 1` computes the sole support from nearest-node heights; bilinear heights smear stone edges over a cell, so a centered foot on a 20 cm stone would read as unsupported.\n\n**Speed** (none of these change the objective)\n\n| Flag | What it does | Observed |\n|---|---|---|\n| `--compile 1`, `--cudagraphs 1` | `torch.compile`, CUDA graphs for the world-model update | default |\n| `--cg_imag 1` | CUDA graph for the imagination step | together with fewer host syncs: +6 % (RTX 5080) to +24 % (RTX 2080 Ti) in the policy phase |\n| `--async_collect 1` | Simulator collection in a thread, overlapping the updates; the simulator acts with a copy of the policy and FPM that is one iteration old. Starts at `--async_after` (1600: after the FPM bootstrap, so the CUDA graphs are recorded without the thread) | on top of `--cg_imag`: +12 % (RTX 2080 Ti) to +32 % (RTX 5080); the world model's error over training matches a run without it |\n| `--amp bf16` | Mixed precision; on GPUs without native bf16 (compute capability below 8.0, e.g. RTX 2080 Ti, Quadro RTX 6000) training switches to fp32 by itself, since compiled bf16 graphs would fall back to eager | on a Quadro RTX 6000 (8192 environments, policy phase), the current code in fp32 ran at 0.61 it\u002Fs against 0.44 for the previous code in eager bf16 (this includes the other speedups) |\n| `--vram_gb 22` | GPU memory budget of the whole run (simulator + torch); leaves the rest of the card free | 8192 environments need about 20 GB, 4096 fit in 10.5 GB |\n| `TGI_PROF=1` | Environment variable: per-phase timing (ms per iteration) in the log | |\n\n**Resuming.** `--resume \u003Cckpt>` continues a run; `--resume_wm_only N` trains only the world model and FPM for the first N iterations after it (for example after changing the terrain features). `--max_hours` counts the current job's time only.\n\n## Repository structure\n\n```\nfpm\u002F                    Isaac Lab 3 task package (see fpm\u002FREADME.md)\n  src\u002Ffpm\u002F\n    tasks\u002Flocomotion\u002F   G1 locomotion tasks: mdp terms, env and PPO configs (config\u002Fg1)\n    terrains\u002F           training, validation and corridor terrains\n    foot_pred\u002F          FPM network, foothold labels, supervised training\n    assets\u002F             G1 USD and articulation config\n  scripts\u002F              PPO train and play, validation suites\ntgi\u002F\n  src\u002Ftgi\u002F\n    world_model\u002F        world model, policy and critic networks, replay buffer\n    foot_pred\u002F          the FPM with a running normalizer, labels from the replay buffer, continual trainer\n    mdp\u002F                differentiable state, rewards, kinematics, heightmap lookups, the fpm observation interface\n    env\u002F                the fpm environment on Newton, domain randomization, success-guided curriculum, terrains\n    training\u002F           options, trainer, simulator collection, optimizers, logging\n    deploy\u002F             NumPy\u002FONNX controller (policy + FPM + foothold scan) and the G1 PD gains\n    assets\u002F             G1 kinematics MJCF, Unitree's G1 MJCF for sim2sim\n    policy_io.py        closed-loop execution in the simulator, checkpoint loading\n  scripts\u002F\n    train.py            training entry point (options: python scripts\u002Ftrain.py --help)\n    pipeline.sh         train from scratch, then final export, evaluation and videos\n    export.py, sim2sim.py, stand_check.py, check.sh, isaac_eval.sh, convert_g1_usd.py\n```\n\n## Citation\n\nIf you use this code, please cite:\n\n```bibtex\n@misc{heyrman2026tgi,\n  author = {Heyrman, Matthias and Hutter, Marco},\n  title  = {Terrain-Grounded Imagination: A Recipe for Humanoid Locomotion on Sparse Terrain through World Models},\n  year   = {2026},\n  note   = {Code: \\url{https:\u002F\u002Fgithub.com\u002Fleggedrobotics\u002Fterrain-grounded-imagination}},\n  url    = {https:\u002F\u002Fgithub.com\u002Fleggedrobotics\u002Fterrain-grounded-imagination}\n}\n```\n\nIf you use the foothold prediction model or the G1 environments in `fpm\u002F`, please also cite:\n\n```bibtex\n@misc{heyrman2026watch,\n  author        = {Heyrman, Matthias and Li, Chenhao and Dadiotis, Ioannis and Hutter, Marco},\n  title         = {Watch Your Step: Anticipated Perception for Humanoid Locomotion},\n  year          = {2026},\n  eprint        = {2610.29612},\n  archivePrefix = {arXiv}\n}\n```\n\n## License\n\n© 2026 ETH Zurich\u003Cbr>\nCreated by: Matthias Heyrman and Marco Hutter\u003Cbr>\nLicensed under the MIT License (see [LICENSE](LICENSE)).\n\nThird-party files keep their original license (see [licenses\u002Fdependencies](licenses\u002Fdependencies)):\n\n- `fpm\u002Fsrc\u002Ffpm\u002Fassets\u002Fdata\u002FG1\u002F` is the Unitree G1 (29 DoF, rev 1.0) model from [unitree_ros](https:\u002F\u002Fgithub.com\u002Funitreerobotics\u002Funitree_ros), converted to USD, BSD-3-Clause.\n- `tgi\u002Fsrc\u002Ftgi\u002Fassets\u002Fg1_kinematics.xml` is the Unitree G1 model from [mjlab](https:\u002F\u002Fgithub.com\u002Fmujocolab\u002Fmjlab) with the meshes removed, Apache-2.0.\n- `tgi\u002Fsrc\u002Ftgi\u002Fassets\u002Funitree_g1\u002F` is the Unitree G1 (29 DoF) MuJoCo model from [unitree_mujoco](https:\u002F\u002Fgithub.com\u002Funitreerobotics\u002Funitree_mujoco), BSD-3-Clause.\n","这是一个面向非结构化地形下人形机器人运动控制的强化学习训练方法，提出“地形锚定想象”（TGI）框架，通过可微分高度图查表构建轻量级世界模型，实现对楼梯、缝隙、踏石等稀疏粗糙地形的端到端步态学习。核心特点包括：地形条件化世界模型（不显式编码地形，而是实时查表）、基于足点门控的感知机制（避免渲染开销）、以及在支撑不足触地时自动截断梯度以提升训练稳定性。适用于仿真环境中人形机器人在复杂野外或城市障碍地形上的自主步态策略研发。",2,"2026-11-24 04:36:02","CREATED_QUERY"]