Skip to content
tkdyun.xyz

MuJoCo-G1 Sim-to-Sim Deployment

A C++ ONNX Runtime deployment layer for URMA-style attention policies.

Reinforcement Learning

Year
2026
Role
Solo · KIST
Stack
MuJoCo · ONNX Runtime · C++ · Eigen · IsaacLab · CMake
View on GitHub

Overview

This project verifies humanoid locomotion policies — trained in IsaacLab with a FastSAC agent — by loading them as ONNX graphs into a real-time MuJoCo C++ simulator (“sim-to-sim”: IsaacLab training → MuJoCo playback). The repository started as a fork of the lab's Franka-Panda arm simulator and was rewritten from the ground up for humanoid whole-body control.

1 — Real-time control architecture

The runtime is split into a GUI thread (the vendor mj::Simulate viewer) and a separate physics thread, synchronized with a mutex around mjData. Physics integration runs every tick (2 ms); policy inference is throttled to a much lower rate (~50 Hz) via a decimation counter, while PD torque is recomputed every physics step from the latest target joint positions.

For live experimentation, I exposed velocity commands and gain scales as MuJoCo GUI sliders.

2 — Policy inference: from a flat MLP to a URMA-style attention policy

I implemented the ONNX Runtime integration twice, at increasing levels of generality.

  • v1 — flat policy (policy.h / policy.cpp). A single flattened observation vector (stacked joint-history, ~275-dim) in, a single tensor of target joint deltas out. This was the first working ONNX inference path in the project.
  • v2 — attention policy (attention_policy.h / attention_policy.cpp). A URMA (morphology-agnostic policy)–style interface with five explicitly named input tensors — joint_desc, joint_obs, feet_desc, feet_obs, global_obs — and one output, actions. The C++ side inspects the ONNX graph's input names and shapes at load time (GetInputNameAllocated, dynamic-dimension handling) to automatically infer joint count and foot count, so the same binary can drive different robot morphologies without a recompile.
Overview of URMA Architecture
Overview of URMA Architecture (Source: Bohlinger et al., One Policy to Run Them All, 2024)

Scope note: the attention mechanism itself — the network that turns per-joint/per-foot descriptors into a morphology-agnostic latent — lives in the training code and is only ever consumed here as a black-box ONNX graph. My contribution is the entire deployment layer around it: splitting the runtime observation into the joint/foot/global tensors the graph expects, running inference in a 1-thread-pinned ONNX Runtime session for real-time determinism, and remapping the output actions back to actuator order.

3 — Observation pipeline

The observation code went through the same flat → structured evolution as the policy:

  • Flat (observation.cpp). Concatenates base angular velocity, projected gravity, velocity commands, relative joint pos/vel, last action, and a sin/cos gait phase into one vector, then stacks a fixed-length history.
  • Attention (attention_observation.cpp, g1_attention_observation.cpp). Splits observation into computeJointObs() (per-joint [q − q_home, q̇, last action] rows), computeFeetObs() (per-foot relative height/velocity in the torso frame), and computeGlobalObs() (base velocities, projected gravity, command, CoM offset — 15-dim). The joint/foot descriptor tensors are precomputed and loaded from small binary files at startup.

The foot-observation transform required converting a world-frame body velocity into a torso-relative frame by hand, using MuJoCo's low-level API (mj_objectVelocity, mju_rotVecQuat, mju_cross) rather than any higher-level convenience function — this is the kind of glue code that has to be exactly right or the policy silently receives corrupted inputs.

4 — Training-side integration: FastSAC via holosoma

I integrated third_party/holosoma into the project via a git submodule, and my work on the training side was to integrate that framework and connect its output checkpoints to this deployment code. I referenced IsaacLab observation configuration (pyfile/mdp.py, pyfile/observation.py) and implemented the MuJoCo-style observation calculation.

5 — Debugging history-order bugs

  • Observation-history stacking order. Stacking the observation history as newest-first / time-major caused the policy to diverge in headless testing; switching to term-major with oldest-first ordering was the fix — a subtle mismatch between how the simulator concatenated history and how the training pipeline expected it, found only by testing both orderings against each other.

Search the site

Choose a destination, or type to search.