Microduck policy export: ONNX contract, test and deploy

Export a Microduck RL checkpoint through the official ONNX path, verify the 61-to-14 contract, rehearse it in simulation and load or reset the policy safely.
Nov 29, 2026

A developer workstation showing a robot simulation beside a Microduck robot on a test stand and a controller

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.

What does a Microduck policy export contain?

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.

How do you export a Microduck policy?

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.onnx

You 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.onnx

Use 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.

Why not convert the checkpoint by hand?

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:

  • The observation normalizer.
  • The action clipping or inference wrapper.
  • A recurrent or model-API-specific state contract.
  • Task metadata used to identify the trained environment.
  • The expected input and output names or batch dimensions.

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.

What should you verify before loading the file?

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:

  1. The file was produced by scripts/export.py.
  2. The task ID matches the trained behaviour.
  3. The repository revision and dependency lock are recorded.
  4. The input and output shapes are [1, 61] and [1, 14], or the documented equivalent batch shape.
  5. The ONNX file opens in ONNX Runtime without a compatibility error.
  6. The policy has a reviewed manifest when you publish it as a repository or skill.

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.

How do you rehearse the policy in simulation?

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.onnx

For 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:

  • Whether the policy starts from the pose it expects.
  • Whether command signs and axes produce the intended movement.
  • Whether the gait remains stable for more than a few seconds.
  • How it recovers after a push or fall.
  • Whether the action trace is smooth or contains clipping and spikes.
  • How it behaves outside the condition you trained it on.

Run a short smoke test before a long evaluation. A smoke test answers whether the export runs; it does not establish transfer to hardware.

How does the robot decide whether a policy can load?

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.

How do you load a local policy on Microduck?

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 list

Load a local walking policy into the walking slot:

sudo robotctl policy load walk /home/microduck/walk-lab-a.onnx

The 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 walk

Reset all seven slots with:

sudo robotctl policy reset

The built-in reset returns to the official policy set. Community and local overrides are not reset targets.

How do you test a new policy safely?

Use staged exposure:

  1. Confirm the ONNX interface and manifest.
  2. Rehearse in simulation.
  3. Start with the robot supported or on a stand.
  4. Keep the test area clear and use a low-energy command first.
  5. Watch for falls, dragging joints, abnormal heat, battery sag and repeated resets.
  6. Stop at the first result you cannot explain.
  7. Record the failure, not just the successful run.
  8. Reset to the official policy before leaving the robot unattended.

A good policy result includes held-out scenarios, repeat counts, safety stops and interventions. A short video without those records is a demonstration.

What are the most common export mistakes?

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.

Microduck policy export FAQ

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.

Key takeaways

  • Export through microduck_rl/scripts/export.py; do not hand-convert the checkpoint.
  • The current policy contract is 61 observations to 14 actions at 50 Hz.
  • The observation normalizer is part of the exported ONNX graph.
  • Rehearse in simulation, then test on a stand or supported robot.
  • A manifest describes compatibility and runtime role; it does not replace evaluation.
  • Load writes a persistent slot override; robotctl policy reset is the recovery path.
  • Keep the training run, repository commit, checkpoint and export record together.

Where to go next

Microduck policy export: ONNX contract, test and deploy