This project is inspired by CTS: Concurrent Teacher-Student Reinforcement Learning for Legged Locomotion. It implements a concurrent teacher-student training pipeline for blind legged locomotion on top of NVIDIA Isaac Gym and legged_gym. The project uses asymmetric Actor-Critic PPO: during training, the teacher encoder has access to privileged simulation observations, while the student encoder only receives proprioceptive history. At inference time, the student encoder and the shared policy are used.
The repository currently targets Unitree Go2. It includes rough-terrain training, curriculum learning, domain randomization, policy playback, and JIT model export.
This repository is an engineering reproduction and adaptation of the Concurrent Teacher-Student (CTS) algorithm and the
legged_gymframework. It is not an official implementation from the paper authors. The paper, the authors' implementation, and this repository may differ; implementation details in this README describe the current codebase.
- Massively parallel GPU simulation with Isaac Gym, supporting thousands of environments by default.
- Concurrent teacher and student PPO sampling instead of training a teacher first and distilling it offline.
- A Privileged Encoder that maps terrain heights, contact forces, and other simulator-only state to a latent representation.
- A Proprioceptive Encoder that estimates the same latent representation from five consecutive proprioceptive observations.
- Rough-terrain generation and curriculum learning with slopes, stairs, and discrete obstacles.
- Domain randomization for friction, mass, center of mass, inertia, PD gains, motor torque, action delay, and external pushes.
- TensorBoard/W&B logging, checkpoint resumption, and JIT export for the policy and encoder.
flowchart LR
E[Isaac Gym Parallel Environments] --> O[Proprioceptive Observation]
E --> P[Privileged Observation]
O --> H[Five-Frame Observation History]
P --> TE[Privileged Encoder]
H --> SE[Proprioceptive Encoder]
TE --> ZT[Teacher Latent]
SE --> ZS[Student Latent]
ZT --> AC[Shared Actor-Critic]
ZS --> AC
O --> AC
C[Velocity Commands] --> AC
AC --> A[Joint Position Target Actions]
A --> E
ZT -. MSE Reconstruction Target .-> SE
The current PPO implementation partitions environments into teacher and student groups by environment index: three out of every four environments are teacher environments, and one is a student environment.
- Teacher rollout:
privileged_obs -> PrivilegedEncoder -> latent. - Student rollout:
obs_history -> ProprioEncoder -> latent. - Actor: teacher and student share one policy with
obs + commands + latentas input. - Critic: receives
privileged_obs + commands + latent. During PPO updates, the latent is detached in the value branch, so the value loss does not update either encoder. - Teacher update: the Privileged Encoder and Actor-Critic share the PPO optimizer and are primarily updated through the policy objective.
- Student update: the Proprioceptive Encoder has a separate optimizer and uses MSE to match detached teacher latents.
The default rough-terrain configuration uses the following dimensions:
| Data | Dimension | Contents |
|---|---|---|
obs |
42 | Base angular velocity, projected gravity, 12 joint positions, 12 joint velocities, and the previous 12-dimensional action |
obs_history |
210 | Five flattened obs frames |
commands |
3 | Forward velocity, lateral velocity, and yaw velocity |
privileged_obs |
198 | Base linear velocity, obs, 117 terrain-height samples, joint accelerations, torques, and three-axis contact forces for four feet |
latent |
32 | L2-normalized teacher or student latent |
| Actor input | 77 | 42 + 3 + 32 |
| Critic input | 233 | 198 + 3 + 32 |
These dimensions come from the default LeggedRobotCfg. Individual tasks may override them in their own configuration classes.
cts_gym/
├── legged_gym/
│ ├── algorithm/ # Actor-Critic, PPO, CTS encoders, and rollout storage
│ ├── envs/
│ │ ├── base/ # Base legged-robot environment and configuration
│ │ └── go2/ # Unitree Go2 configuration
│ ├── scripts/ # train.py and play.py
│ ├── tests/ # Environment smoke test
│ └── utils/ # Task registry, terrain, logging, and utilities
├── resources/ # URDF, MJCF, meshes, and actuator network
├── logs/ # Generated logs, checkpoints, and exported models
├── setup.py
└── LICENSE
--task |
Environment | Default Experiment Directory | Description |
|---|---|---|---|
go2 |
LeggedRobot |
logs/rough_go2/ |
Go2 rough-terrain training and policy playback |
Tasks are registered in legged_gym/envs/__init__.py.
- Linux, preferably Ubuntu 20.04.
- An NVIDIA GPU and driver with CUDA support.
- NVIDIA Isaac Gym Preview.
- Python, PyTorch, and CUDA versions compatible with the local Isaac Gym binaries.
Isaac Gym is no longer actively maintained, and different Preview releases require different Python and PyTorch versions. This repository does not pin those versions. Follow the documentation included with your Isaac Gym package and first confirm that its bundled examples run correctly.
The following example uses Conda. Adjust the Python version to match your Isaac Gym package:
conda create -n cts_gym python=3.8
conda activate cts_gym
# Install a compatible PyTorch build as described by the Isaac Gym
# documentation, then install Isaac Gym.
cd /path/to/isaacgym/python
pip install -e .
# Verify the bundled Isaac Gym example before installing this project.
cd examples
python 1080_balls_of_solitude.pycd /path/to/cts_gym
pip install -e .
# Direct runtime dependencies that are not currently declared in setup.py.
pip install numpy scipy tensorboard wandbPyTorch is also a direct runtime dependency, but it should be installed manually before this project so that its build matches the local CUDA and Isaac Gym stack. W&B is imported by the current legged_gym.utils package initialization even when TensorBoard is selected, so it is required by the code as currently written.
Start with a small environment smoke test:
python -m legged_gym.tests.test_env --task=go2 --num_envs=10# Train Go2 without rendering.
python -m legged_gym.scripts.train --task=go2 --headless
# Quickly validate the training pipeline with fewer environments and iterations.
python -m legged_gym.scripts.train \
--task=go2 \
--num_envs=256 \
--max_iterations=10 \
--headlessThe default Go2 configuration uses 8,192 parallel environments, collects 24 steps per environment per iteration, and trains for up to 15,000 iterations. Reduce --num_envs if GPU memory is insufficient.
# Load the latest checkpoint from the latest run in the experiment directory.
python -m legged_gym.scripts.train --task=go2 --resume --headless
# Load a specific run and checkpoint.
python -m legged_gym.scripts.train \
--task=go2 \
--resume \
--load_run=Jul13_12-00-00_demo \
--checkpoint=1000 \
--headlessCommon command-line arguments:
| Argument | Description |
|---|---|
--task |
Select a registered task |
--headless |
Disable the viewer for faster training |
--num_envs |
Override the number of parallel environments |
--max_iterations |
Override the number of training iterations |
--seed |
Override the random seed |
--resume |
Resume from a checkpoint |
--load_run |
Select the run directory to resume; defaults to the latest run |
--checkpoint |
Select model_<N>.pt; defaults to the latest checkpoint |
--experiment_name |
Override the experiment directory name |
--run_name |
Set the suffix for the current run |
--sim_device |
Isaac Gym simulation device, such as cuda:0 or cpu |
--rl_device |
PPO device, such as cuda:0 or cpu |
Each training run writes to:
logs/<experiment_name>/<timestamp>_<run_name>/
├── events.out.tfevents.*
├── model_0.pt
├── model_50.pt
└── ...
By default, a model is saved every 50 iterations. Each checkpoint contains the Actor-Critic, Privileged Encoder, Proprioceptive Encoder, PPO optimizer state, and current iteration.
Launch TensorBoard with:
tensorboard --logdir logsThe main metrics include PPO value and surrogate losses, student reconstruction loss, policy noise, sampling throughput, mean reward, and mean episode length.
# Load the latest checkpoint from the latest rough_go2 run.
python -m legged_gym.scripts.play --task=go2
# Load a specific run and checkpoint.
python -m legged_gym.scripts.play \
--task=go2 \
--load_run=Jul13_12-00-00_demo \
--checkpoint=1000EXPORT_POLICY = True in the current play.py, so every playback run exports the inference models to:
logs/rough_go2/exported/policies/
├── policy_1.pt
└── encoder_1.pt
policy_1.pt is the shared Actor, and encoder_1.pt is the Proprioceptive Encoder. Any consumer of these exported models must use inputs that match the training configuration.
Note that play.py overrides several settings for evaluation, including the number of environments, terrain rows and columns, terrain proportions, noise level, and domain-randomization switches. Playback settings therefore do not exactly match the training settings. Check the override block near the top of the script before running controlled comparisons.
The base environment configuration is defined in legged_gym/envs/base/legged_robot_config.py. Robot-specific configurations inherit from it and override selected values, as in legged_gym/envs/go2/go2_config.py.
Common configuration namespaces:
env: number of environments, observation/action/latent dimensions, and episode duration.terrain: mesh type, resolution, terrain categories, and curriculum difficulty.commands: velocity ranges, resampling interval, and command curriculum.control: control mode, PD gains, action scale, and decimation.asset: URDF, foot names, penalized contact links, and termination links.domain_rand: dynamics, actuator, delay, and push randomization.rewards: reward weights, target height, and soft constraints.noise: training noise applied to proprioceptive observations.policy,privileged_encoder, andproprio_encoder: network architecture.algorithm: PPO, encoder learning rates, batches, and loss parameters.runner: iterations, save interval, logging, and checkpoint settings.
Rewards follow the legged_gym convention: each nonzero entry in rewards.scales is matched to a corresponding _reward_<name>() method in LeggedRobot.
- Add URDF/MJCF files and meshes under
resources/robots/<robot>/. - Create a configuration under
legged_gym/envs/<robot>/that inherits fromLeggedRobotCfgandLeggedRobotCfgPPO. - Override at least
asset.file, foot/contact link names, initial joint angles, PD gains, action scale, rewards, and experiment name. - If the base behavior is insufficient, create a
LeggedRobotsubclass and override the required methods. - Register the task in
legged_gym/envs/__init__.py:
task_registry.register("my_robot", MyRobot, MyRobotCfg(), MyRobotCfgPPO())- Run
python -m legged_gym.tests.test_env --task=my_robot --num_envs=10before starting large-scale training.
When changing observations, update and verify the environment observation assembly, configured dimensions, rollout storage, Actor/Critic inputs, and both encoder inputs together.
Confirm that Isaac Gym is installed in the active Python environment and that python -c "import isaacgym" runs successfully. Project entry points import Isaac Gym before PyTorch to satisfy its binary-loading requirements.
Reduce --num_envs first. Complex trimesh terrain also increases PhysX contact-pair and mesh-cooking costs. If necessary, reduce the number of terrain rows and columns or inspect sim.physx.max_gpu_contact_pairs.
Use --headless for training. play.py requires a working display environment; on a remote machine, configure X11/VNC or run only the headless smoke test.
A checkpoint must match the observation dimensions, latent dimension, and network-layer configuration used during training. After changing the working-tree configuration, resume with the matching historical configuration or train a new model.
- CTS: Concurrent Teacher-Student Reinforcement Learning for Legged Locomotion
- CTS Project Page
- leggedrobotics/legged_gym
- Learning to Walk in Minutes Using Massively Parallel Deep Reinforcement Learning
- NVIDIA Isaac Gym
- This Repository
The project code is distributed under the BSD-3-Clause license in the root LICENSE file. Robot assets and third-party dependencies may have their own licenses; see licenses/ and the corresponding resource directories.