File size: 11,100 Bytes
d6b3397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | # RLinf Integration for IsaacLab
This module integrates [RLinf](https://github.com/RLinf/RLinf.git)'s distributed RL training framework with IsaacLab, enabling **reinforcement learning fine-tuning of Vision-Language-Action (VLA) models** (e.g., GR00T, OpenVLA) on IsaacLab simulation tasks.
## Overview
RLinf is a flexible and scalable open-source RL infrastructure designed for Embodied and Agentic AI. This integration allows IsaacLab users to:
- Fine-tune pretrained VLA models on IsaacLab tasks using PPO / Actor-Critic / SAC
- Leverage RLinf's FSDP-based distributed training across multiple GPUs/nodes
- Define observation/action mappings from IsaacLab to GR00T format via a single YAML config
- Register IsaacLab tasks into RLinf without modifying RLinf source code
## Architecture
```
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RLinf Runner β
β (EmbodiedRunner / EvalRunner) β
ββββββββββββββββββ¬βββββββββββββββββββββββ¬βββββββββββββββββββββββββ€
β Actor Worker β Rollout Worker β Env Worker β
β (FSDP) β (HF Inference) β (IsaacLab Sim) β
β β β β
β Policy β Multi-step rollout β IsaacLabGenericEnv β
β Update β with VLA model β ββ _make_env_function β
β β β ββ _wrap_obs β
β β β ββ _wrap_action β
ββββββββββββββββββ΄βββββββββββββββββββββββ΄βββββββββββββββββββββββββ
```
**Data flow:**
1. `EnvWorker` runs IsaacLab simulation and converts observations to RLinf format
2. `RolloutWorker` runs VLA model inference (e.g., GR00T) to produce actions
3. Actions are converted back to IsaacLab format and stepped in the environment
4. `ActorWorker` updates the VLA model with PPO/actor-critic loss via FSDP
## Directory Structure
```
scripts/reinforcement_learning/rlinf/
βββ README.md # This file
βββ train.py # Training entry point (launches RLinf distributed training)
βββ play.py # Evaluation entry point (launches RLinf eval runner)
βββ cli_args.py # Shared CLI argument definitions
```
**Extension module** (in `source/isaaclab_contrib/`):
```
source/isaaclab_contrib/isaaclab_contrib/rl/rlinf/
βββ __init__.py
βββ extension.py # RLinf extension: task registration, obs/action conversion
```
**Task-specific config** (in `source/isaaclab_tasks/`):
```
source/isaaclab_tasks/isaaclab_tasks/manager_based/manipulation/assemble_trocar/
βββ config/
β βββ isaaclab_ppo_gr00t_assemble_trocar.yaml # Single YAML config (Hydra)
βββ g129_dex3_env_cfg.py # IsaacLab environment config
```
## Prerequisites
- **IsaacLab** installed and configured
- **RLinf** available in the parent directory (expected at `../` relative to IsaacLab root, overridable via `RLINF_ROOT`)
- **GR00T** model and Isaac-GR00T repo (for VLA inference and data transforms)
- A **pretrained VLA checkpoint** in HuggingFace format
- Multi-GPU setup recommended (FSDP requires at least 1 GPU)
## Quick Start
### Training
```bash
# Basic training (uses default config)
python train.py
# Training with a specific config
python train.py --config_name isaaclab_ppo_gr00t_assemble_trocar
# Training with task override
python train.py --task Isaac-Assemble-Trocar-G129-Dex3-v0
# Training with custom settings
python train.py --num_envs 64 --max_epochs 1000
# List available tasks
python train.py --list_tasks
```
### Evaluation
```bash
# Evaluate a trained checkpoint
python play.py --task Isaac-Assemble-Trocar-G129-Dex3-Eval-v0 --model_path /path/to/checkpoint
# Evaluate with video recording
python play.py --task Isaac-Assemble-Trocar-G129-Dex3-Eval-v0 --model_path /path/to/checkpoint --video
# Evaluate with specific number of environments
python play.py --task Isaac-Assemble-Trocar-G129-Dex3-Eval-v0 --model_path /path/to/checkpoint --num_envs 8
```
## Configuration
All configuration lives in a **single YAML file** loaded by [Hydra](https://hydra.cc/). By default, `train.py` and `play.py` use `isaaclab_ppo_gr00t_assemble_trocar.yaml`. Override with `--config_path` and `--config_name`.
### Config Structure Overview
```yaml
cluster:
num_nodes: 1
component_placement:
actor,env,rollout: all # Co-locate all workers
runner:
max_epochs: 1000
logger:
logger_backends: ["tensorboard"] # Options: tensorboard, wandb, swanlab
algorithm:
loss_type: actor_critic # Options: actor_critic, embodied_sac
update_epoch: 4
clip_ratio_high: 0.2
gamma: 0.99
gae_lambda: 0.95
env:
train:
total_num_envs: 4
max_episode_steps: 256
init_params:
id: "Isaac-Assemble-Trocar-G129-Dex3-v0"
isaaclab: &isaaclab_config # IsaacLab β RLinf mapping (see below)
...
eval:
isaaclab: *isaaclab_config # Reuse via YAML anchor
rollout:
backend: "huggingface"
model:
model_path: "/path/to/pretrained/model"
obs_converter_type: ${env.train.isaaclab.obs_converter_type}
embodiment_tag: ${env.train.isaaclab.embodiment_tag}
actor:
training_backend: "fsdp"
micro_batch_size: 2
global_batch_size: 4
model:
obs_converter_type: ${env.train.isaaclab.obs_converter_type}
embodiment_tag: ${env.train.isaaclab.embodiment_tag}
optim:
lr: 5e-6
```
### IsaacLab β RLinf Observation/Action Mapping
The `env.train.isaaclab` section defines how IsaacLab observations are converted to GR00T format. This is the key configuration block for adapting new tasks:
```yaml
isaaclab: &isaaclab_config
# Task description for language conditioning
task_description: "assemble trocar from tray"
# --- IsaacLab β RLinf observation mapping ---
main_images: "front_camera" # Single main camera β (B, H, W, C)
extra_view_images: # Extra cameras β (B, N, H, W, C)
- "left_wrist_camera"
- "right_wrist_camera"
states: # State specs with optional slicing
- key: "robot_joint_state"
slice: [15, 29] # Take indices 15..29
- key: "robot_dex3_joint_state" # Full tensor (no slice)
# --- RLinf β GR00T format conversion ---
gr00t_mapping:
video:
main_images: "video.room_view"
extra_view_images:
- "video.left_wrist_view"
- "video.right_wrist_view"
state: # Slice concatenated state into GR00T keys
- gr00t_key: "state.left_arm"
slice: [0, 7]
- gr00t_key: "state.right_arm"
slice: [7, 14]
- gr00t_key: "state.left_hand"
slice: [14, 21]
- gr00t_key: "state.right_hand"
slice: [21, 28]
# --- GR00T β IsaacLab action conversion ---
action_mapping:
prefix_pad: 15 # Pad zeros for uncontrolled joints
suffix_pad: 0
# --- GR00T model configuration (single source of truth) ---
# Referenced by actor.model and rollout.model via Hydra ${} interpolation
obs_converter_type: "dex3"
embodiment_tag: "new_embodiment"
embodiment_tag_id: 31
data_config_class: "gr00t_config:IsaacLabDataConfig"
```
## CLI Arguments
### Common Arguments
| Argument | Description |
|---|---|
| `--config_path` | Path to config directory (defaults to task config dir) |
| `--config_name` | Name of the Hydra config file (without `.yaml`) |
| `--task` | IsaacLab task ID (overrides YAML config if set) |
| `--num_envs` | Number of parallel environments |
| `--seed` | Random seed |
| `--model_path` | Path to pretrained VLA checkpoint |
### Training-Specific
| Argument | Description |
|---|---|
| `--max_epochs` | Maximum training epochs |
| `--resume_dir` | Directory to resume training from |
| `--only_eval` | Run evaluation only (no training) |
| `--list_tasks` | List available tasks and exit |
### Evaluation-Specific
| Argument | Description |
|---|---|
| `--num_episodes` | Number of evaluation episodes |
| `--video` | Enable video recording |
### Logger & Experiment
| Argument | Description |
|---|---|
| `--logger` | Logger backend: `tensorboard`, `wandb`, or `swanlab` |
| `--experiment_name` | Experiment name for log directory |
| `--run_name` | Run name suffix |
## Adding a New Task
To add a new IsaacLab task for RLinf training:
### 1. Create a YAML Config
Create a new YAML config file (e.g., `isaaclab_ppo_gr00t_my_task.yaml`) in your task's `config/` directory. Use the existing `isaaclab_ppo_gr00t_assemble_trocar.yaml` as a template.
Key sections to customize:
- `env.train.init_params.id` β your task's gymnasium ID
- `env.train.isaaclab` β observation/action mapping for your embodiment
- `actor.model.model_path` / `rollout.model.model_path` β your pretrained checkpoint
- `actor.model.action_dim` β total action dimensions
### 2. Create GR00T Data Config (if needed)
If your embodiment differs from the default, create a new data config class in your config directory (e.g., `gr00t_config.py`):
```python
class MyTaskDataConfig(BaseDataConfig):
video_keys = ["video.front_view"]
state_keys = ["state.arm"]
action_keys = ["action.arm"]
# ... define modality_config() and transform()
```
Reference it in your YAML config:
```yaml
data_config_class: "gr00t_config:MyTaskDataConfig"
```
### 3. Register the Task
The task is registered automatically at runtime via the extension module. Task IDs are read from `env.train.init_params.id` and `env.eval.init_params.id` in the YAML config. You can also override with `--task`.
### 4. Run Training
```bash
python train.py --config_path /path/to/your/config/dir \
--config_name isaaclab_ppo_gr00t_my_task
```
## Logging
Logs are saved to `logs/rlinf/<timestamp>-<task_name>/` and include:
- TensorBoard / WandB / SwanLab logs (based on `--logger`)
- Video recordings (when `--video` is enabled or `video_cfg.save_video: True`)
- Model checkpoints (saved every `save_interval` epochs)
## Key Environment Variables
These are set automatically by `train.py` / `play.py` β you typically do not need to set them manually:
| Variable | Description |
|---|---|
| `RLINF_EXT_MODULE` | Extension module path (`isaaclab_contrib.rl.rlinf.extension`) |
| `RLINF_CONFIG_FILE` | Full path to the Hydra config YAML |
| `RLINF_ROOT` | (Optional) Override RLinf repo location (defaults to IsaacLab's parent directory) |
|