
Export a Microduck policy with the official microduck_rl exporter, keep the ONNX file produced by that command, verify its [1,61] โ [1,14] interface, rehearse it in MuJoCo, and only then load it on the robot. The exporter bakes the trained observation normalizer into the ONNX graph. Hand-converting a checkpoint can produce a graph of the right shape that fails in reality because the policy receives differently scaled observations.
The commands and contract below are based on the official Microduck RL repository and policy manifest documentation, checked on 29 November 2026. Pin the repository revision you use; main may move.
The current runtime contract is a 61-value observation producing 14 joint-target actions at 50 Hz.
The observation combines 48 proprioceptive values with command slots for twist, head pose and body pose. Every task keeps the same actor observation layout even when a command block is unused and zero-padded. That shared contract is what lets the runtime switch among walking, recovery and episodic skills without a different client API for each network.
The ONNX file contains the trained inference policy. During export, the observation normalizer is embedded before the actor network. The file is not a raw actor checkpoint, and it is not a replay of joint positions.
Use the microduck_rl environment and the official export script. The quickstart command is:
uv run scripts/export.py Mjlab-Velocity-Flat-MicroDuck \
--wandb-run-path <entity/project/run_id>The default output is output.onnx. Choose a stable name when you need to keep several experiments separate:
uv run scripts/export.py Mjlab-Velocity-Flat-MicroDuck \
--wandb-run-path <entity/project/run_id> \
--onnx-file walk-lab-a.onnxYou can identify a local checkpoint instead of a Weights & Biases run:
uv run scripts/export.py Mjlab-Velocity-Flat-MicroDuck \
--checkpoint-file /absolute/path/to/model_29999.pt \
--onnx-file walk-lab-a.onnxUse the task ID that matches the environment and command encoding you trained. A walking policy, a ground-pick policy and a sit-to-stand policy can share tensor dimensions while requiring different runtime slots and command semantics.
The training policy includes the observation normalizer. The official exporter emits the composed inference path so the robot feeds physical observations into the same normalization used during training.
A manual conversion can miss:
If the ONNX graph has the right shape but the normalizer is missing, a shallow shape check will still pass. That is one of the most expensive ways to create a policy that appears valid and behaves incorrectly.
Start with the tensor contract and the file's provenance. Record the source task, repository commit, training run, checkpoint iteration, export time and operator.
Inspect the ONNX session directly:
import onnxruntime as ort
session = ort.InferenceSession("walk-lab-a.onnx")
input_info = session.get_inputs()[0]
output_info = session.get_outputs()[0]
print(input_info.name, input_info.shape)
print(output_info.name, output_info.shape)The actor interface should match the current runtime contract: one observation vector of 61 values and one action vector of 14 values. Confirm:
scripts/export.py.[1, 61] and [1, 14], or the documented equivalent batch shape.Do not infer safety from a successful InferenceSession load alone. It proves that the graph can be opened, not that the observations, actions or command encoding are correct.
The official repository provides an inference script that runs the ONNX policy in CPU MuJoCo:
uv run scripts/infer_policy.py --walking walk-lab-a.onnxFor an episodic or recovery policy, use the matching arguments documented by the current script rather than treating every ONNX file as a walking gait. The export task and runtime role must agree.
Watch the robot in simulation and record:
Run a short smoke test before a long evaluation. A smoke test answers whether the export runs; it does not establish transfer to hardware.
Before changing the running controller, the robot checks the ONNX interface and any manifest fields it can verify. A graph that does not produce the expected observation and action shape is refused. A failed load keeps the policy that was already running.
For a single-policy repository, schema 2 uses fields such as:
{
"schema_version": 2,
"model_api": 1,
"obs_len": 61,
"action_len": 14,
"robot": {
"model": "microduck",
"hw_rev": 1,
"servos": "xl330",
"control_hz": 50
},
"name": "walk-lab-a",
"kind": "perpetual",
"slot": "walk",
"training": {
"task_id": "Mjlab-Velocity-Flat-MicroDuck",
"repo": "pollen-robotics/microduck_rl",
"commit": "<commit>",
"run": "<wandb-run>",
"checkpoint": 29999
}
}Use the manifest fields that describe the exact policy. obs_len and action_len are compatibility checks. model_api prevents a policy requiring a newer daemon from loading. For episodic skills, duration_s, entry_pose, command.encoding and unwind_s affect what the robot does after the network starts.
Do not mark a policy standing when it was trained from the seated pose. Do not put a phase-driven ground pick into the generic one-shot table. The manifest should describe the runtime contract, not the marketing name.
Put the robot on a stand or in a clear test area with the controller within reach. Check the robot first:
robotctl health
robotctl policy listLoad a local walking policy into the walking slot:
sudo robotctl policy load walk /home/microduck/walk-lab-a.onnxThe load is stored in the robot's configuration, so a successful trial survives a reboot. Put the original policy back with:
sudo robotctl policy reset walkReset all seven slots with:
sudo robotctl policy resetThe built-in reset returns to the official policy set. Community and local overrides are not reset targets.
Use staged exposure:
A good policy result includes held-out scenarios, repeat counts, safety stops and interventions. A short video without those records is a demonstration.
Exporting the wrong task.
A walking policy and a ball-kick policy may both fit the tensor contract but expect different commands and runtime roles.
Missing normalization.
Always use the official exporter, not a hand-written checkpoint conversion.
Testing only the shape.
[1,61] and [1,14] are necessary, not sufficient. Replay the policy and inspect behaviour.
Using a moving source revision.
Record the repository commit and dependency lock. A branch name without a commit is not a reproducible experiment.
Loading without a reset path.
Know the slot and its official reset command before starting hardware.
Publishing without provenance.
A manifest that omits training data, checkpoint and export time makes the policy harder to audit and reproduce.
What command exports a Microduck policy?
Use uv run scripts/export.py <task-id> --wandb-run-path <run> or --checkpoint-file <path> in the official microduck_rl repository.
Can I convert a PyTorch checkpoint to ONNX with another tool?
Do not. The official exporter includes the observation normalizer and task-specific inference structure needed by the runtime.
What is the ONNX input and output shape?
The current actor contract is 61 observation values to 14 action values. Confirm the live batch shape in ONNX Runtime.
Can I train without a robot?
Yes. Training and simulation can run before hardware. Physical validation is still required before claiming sim-to-real success.
How do I undo a bad local policy?
Use sudo robotctl policy reset <slot> for one slot or sudo robotctl policy reset for all slots. The reset returns to the official policy set.
Does a successful load prove the policy is safe?
No. The runtime shape and safety gates reduce failure modes, but they do not prove task success, generalization or safe behaviour in your environment.
microduck_rl/scripts/export.py; do not hand-convert the checkpoint.robotctl policy reset is the recovery path.