Skip to content

feat(training): add DreamerV3 world-model package, mjlab GPU driver, ONNX export, and PPO benchmark - #903

Draft
M-Colley wants to merge 1 commit into
MyoHub:devfrom
M-Colley:feat/training-dreamerv3
Draft

M-Colley wants to merge 1 commit into
MyoHub:devfrom
M-Colley:feat/training-dreamerv3

Conversation

@M-Colley

@M-Colley M-Colley commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Draft (Post-3.0) — Candidate wm Family & Shared Infra Gate (#953, Discussion #965): Converted to Draft and deferred from Milestone 3.2 pending maintainer alignment in Discussion #965 on canonical world-model organization (training/wm/ alongside training/supermimic/), adoption of training/common/ (#953 / #977) evaluation, PPO baseline invocation, and artifact APIs, and full 4-task CPU+GPU PPO benchmark completion (myoElbowPose1D6MRandom-v0, myoChallengeRelocateP1-v0, myoFullBodyDirectional-v0, myoMimic-v0).

Summary

  • Add self-contained training/dreamerv3/ (myosuite-dreamerv3) package integrating DreamerV3 world-model reinforcement learning (Hafner, Pasukonis, Ba & Lillicrap, Nature 2025; danijar/dreamerv3, MIT License preserved in LICENSE-dreamerv3.txt) per docs/wiki/training-guidelines.md, with zero changes to myosuite/ or the root pyproject.toml.
  • Implement adapters and deployment tooling across all simulation paths:
    1. CPU Gymnasium Adapter (DreamerEnv, dreamerv3-train): wraps myosuite.make_env (5-tuple Gymnasium step, EnvConfig.features muscle-condition wrappers --feature fatigue|sarcopenia|motor-noise|reafferentation, offscreen mujoco.Renderer 64x64 RGB CNN observations, and solved / rwd_dense / rwd_sparse logging).
    2. GPU mjlab Driver (MjlabDriver, dreamerv3-train-mjlab): wraps MyoSuite's registered GPU MuJoCo Warp twins (ManagerBasedRlEnv), handling same-step auto-reset, jax.prealloc=False VRAM sharing, in-place bfloat16 JAX recurrent carry selection, and peak deterministic checkpoint (best_ckpt) tracking with zero-shot evaluation on CPU make_env.
    3. Experimental GPU MJX Driver (MJXDriver, dreamerv3-train-mjx): steps num_envs environments inside jax.jit(jax.vmap(...)) using jax.lax.cond step-vs-reset staging so terminal observations (is_last=True, is_terminal) are preserved prior to episode reset.
    4. Standalone PyTorch / TorchScript / ONNX Export & Deployment Manifests (dreamerv3-export, export.py, hf.py): reconstructs the proprioceptive encoder, block-GRU RSSM posterior, and bounded-normal actor directly from saved checkpoint NumPy arrays (atol < 1e-5 vs. JAX across resets), writes <policy>.onnx.manifest.json physical provenance sidecars so myosuite.utils.export_onnx.verify_onnx_on_cpu passes strictly (allow_provenance_mismatch=False), and enforces pinned @<commit_or_tag> hf:// resolution.

Benchmark Against PPO (size12m, Seeds 0, 1, 2, NVIDIA GeForce RTX 5090, Zero-Shot CPU make_env Eval)

Difference summary: Across all four evaluated tasks, DreamerV3 (size12m, mjlab) achieves higher sample efficiency and peak task return than registered mjlab RSL-RL PPO on 6-muscle myoElbowPose1D6MRandom-v0 (100.0 ± 0.0% vs. 75.0 ± 8.2% solved; 735.71 ± 24.86 vs. 281.25 ± 121.26 return at 36,864 steps), under --feature fatigue (100.0 ± 0.0% vs. 66.7 ± 2.4% solved; 732.57 ± 18.91 vs. 226.56 ± 11.51 return), on 39-muscle myoHandPoseRandom-v0 (-276.76 ± 15.28 vs. -300.81 ± 2.56 return at 294,912 steps), and on 80-muscle myoLegWalk-v0 (231.43 ± 41.67 vs. 211.49 ± 15.11 return at 196,608 steps), whereas massively parallel on-policy mjlab PPO runs 7.8×–15.8× faster in wall-clock time (3.7–22.2 s vs. 41.3–351.6 s).

Task (env_id) Method Env Steps CPU make_env Return CPU Solved Rate Wall Time (s)
myoElbowPose1D6MRandom-v0 DreamerV3 (size12m, mjlab) 36,864 735.71 ± 24.86 100.0 ± 0.0% 41.3 ± 1.3
myoElbowPose1D6MRandom-v0 PPO (mjlab / RSL-RL) 36,864 281.25 ± 121.26 75.0 ± 8.2% 3.7 ± 0.3
myoElbowPose1D6MRandom-v0 (--feature fatigue) DreamerV3 (size12m, mjlab) 36,864 732.57 ± 18.91 100.0 ± 0.0% 43.5 ± 0.3
myoElbowPose1D6MRandom-v0 (--feature fatigue) PPO (mjlab / RSL-RL) 36,864 226.56 ± 11.51 66.7 ± 2.4% 5.6 ± 2.7
myoHandPoseRandom-v0 DreamerV3 (size12m, mjlab, best_ckpt) 294,912 -276.76 ± 15.28 0.0 ± 0.0% 351.6 ± 33.9
myoHandPoseRandom-v0 PPO (mjlab / RSL-RL) 294,912 -300.81 ± 2.56 0.0 ± 0.0% 22.2 ± 6.4
myoLegWalk-v0 DreamerV3 (size12m, mjlab, best_ckpt) 196,608 231.43 ± 41.67 0.0 ± 0.0% 266.3 ± 7.5
myoLegWalk-v0 PPO (mjlab / RSL-RL) 196,608 211.49 ± 15.11 0.0 ± 0.0% 20.0 ± 1.2

Full learning curves vs. environment steps and wall-clock time are documented in training/dreamerv3/README.md.

Extended 8.6-Hour GPU Runs (6.0M–6.2M Steps, v0.2.0 seed0 Checkpoints)

Bounding DreamerV3's bounded_normal exploration std (--minstd 0.02 --maxstd 0.12..0.15 --actent 0.0, preventing entropy-driven stddev -> 1.0 drift on saturated off-muscles as in #566) and training ~8.6h per task (train_ratio=256, RTX 5090):

Task (env_id) Env Steps (Grad Updates) CPU make_env ONNX Return CPU Episode Length CPU Solved Rate
myoLegWalk-v0 (80 muscles) 6,000,000 (750k) 9,961.76 (4,130.9 random starts) 1,000.0 / 1,000 (38% random) 0.0% (upright 10s balance; speed < 0.7 m/s)
myoHandPoseRandom-v0 (39 muscles) 6,200,000 (1.55M) +100.03 ± 135.92 (+115.11 val) 100.0 / 100 18.8% any / 15.6% final (25.0% val, 64/32 eps)

All trained size12m checkpoints (agent.pkl, TorchScript .pt, and stateful .onnx + .onnx.manifest.json) and raw evaluation JSON logs are published on Hugging Face at maco018/myosuite-dreamerv3 (pinned at tag v0.2.0 / commit ea6ca03a75eb3bfc7c1899232e445332ee7427ac).

Verification

  • PYTHONPATH=../dreamerv3 pytest training/dreamerv3/tests/test_dreamerv3.py -v (12 passed, including strict verify_onnx_on_cpu(..., allow_provenance_mismatch=False), [0, 1] twin action-range mapping, Warp NaN guard, and silu activation parity)
  • pre-commit run --all-files

Ownership & Reuse (REVIEW.md)

  • Owner: MyoSuite training/dreamerv3/ (self-contained world-model package with pyproject.toml and LICENSE-dreamerv3.txt; zero files in myosuite/).
  • Existing primitives reused: Consumes myosuite.make_env, myosuite.core.hf_io, myosuite.utils.checkpoint_manifest, and myosuite.utils.export_onnx.
  • Code removed/simplified: None (standalone training/ package; evaluation, PPO baseline runner, and artifact helpers slated for training/common/ per Consolidate shared training infrastructure while keeping methods independently installable #953).

Compatibility & Checks

@M-Colley
M-Colley force-pushed the feat/training-dreamerv3 branch from 0133fa5 to 8cd24e9 Compare November 21, 2026 20:08
@M-Colley M-Colley changed the title feat(training): add DreamerV3 world-model package and PPO benchmark feat(training): add DreamerV3 world-model package, mjlab GPU driver, and PPO benchmark Nov 21, 2026
@M-Colley
M-Colley force-pushed the feat/training-dreamerv3 branch from 8cd24e9 to c06bba5 Compare November 22, 2026 03:12
@M-Colley M-Colley changed the title feat(training): add DreamerV3 world-model package, mjlab GPU driver, and PPO benchmark feat(training): add DreamerV3 world-model package, mjlab GPU driver, ONNX export, and PPO benchmark Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Automated cross-repo audit (compatibility, composition, reuse) of myosuite#903 at c06bba5, run on MyoSuite dev as of 2026-11-22.

  • Tests: no test module under myosuite/tests imports the changed code, so nothing ran here (the training/<method>/ package tests were not run by this audit).

Nothing here blocks merging on its own; the items are for the next revision.


Generated by Claude Code

@M-Colley
M-Colley force-pushed the feat/training-dreamerv3 branch 2 times, most recently from cb543d3 to 8fe47b8 Compare November 22, 2026 22:25
@M-Colley

Copy link
Copy Markdown
Collaborator Author

Pushed 0af65f54 with three fixes found while running longer myoLegWalk-v0 / myoHandPoseRandom-v0 trainings:

  1. Action range on the mjlab twins. MjlabDriver now maps DreamerV3's [-1, 1] actions linearly onto each action term's action_range, as the CPU NormalizeAction wrapper does. The leg-walk twins use action_range=(0, 1) and clamp, so before this change half of the action range was zero activation during training, and CPU playback saw other muscle commands than training. Pose/reach twins ([-1, 1]) are unaffected.
  2. Diverged Warp worlds. Non-finite or extreme (|x| > 1e4) observations and rewards are replaced before they reach the replay buffer. One such transition turned every DreamerV3 parameter into NaN after ~1M myoLegWalk-v0 steps. The driver counts replaced values (sanitized_values).
  3. CPU evaluation. The torch/ONNX evaluators apply the same linear action map, report solved_final_rate (solved on the last step, as docs/baseline_checkpoints.md measures) next to solved_rate (any step), and cap torch threads at 4 for batch-1 inference (70x faster next to a running trainer).

New tier1 test test_mjlab_driver_action_range_map_and_sanitize; tier1 suite passes (6/6), pre-commit clean.

Note: the myoLegWalk-v0 checkpoints in maco018/myosuite-dreamerv3@f1d6f86 were trained with the old clamp, and none of them walk (they fall within ~0.5 s). They will be replaced after longer runs; the elbow and hand checkpoints are unaffected.

@M-Colley

M-Colley commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed two follow-ups (7e085948 and the v0.2.0 checkpoint pin) after ~17 hours of size12m GPU runs on myoLegWalk-v0 and myoHandPoseRandom-v0:

  1. silu activation propagation & JAX-free package import (7e085948 + __init__.py): evaluate_dreamer_agent now propagates enc_act, dyn_act, pol_act, blocks, and symlog from agent.config (and DreamerV3TorchPolicy defaults to DreamerV3's silu rather than gelu), matching exported ONNX playback bit-for-bit. myosuite_dreamerv3.__init__ also loads embodied/jax drivers lazily so from myosuite_dreamerv3 import evaluate_exported_onnx_stateful, resolve_dreamerv3_checkpoint works without JAX or dreamerv3 installed.
  2. Bounded exploration std (--minstd, --maxstd, --actent): DreamerV3's default bounded_normal (maxstd=1.0, actent=3e-4) drives stddev to 0.97–1.00 on saturated off-muscles (the DreamerV3 counterpart of mjlab PPO defaults for MuscleMimic (and Chase-Tag / table tennis) let the action std grow without bound: 99% bang-bang muscle controls, learning rate at its floor #566). Exposing --minstd, --maxstd, --actent, --horizon, --imag-length, and --replay-size on dreamerv3-train-mjlab (std=[0.02, 0.12..0.15], actent=0.0) closed the stochastic-vs-deterministic playback gap.
  3. Updated Hugging Face release maco018/myosuite-dreamerv3@ea6ca03a75eb3bfc7c1899232e445332ee7427ac (v0.2.0):
    • myoLegWalk-v0 (seed0, 6.0M steps / 750k updates, ~8.6h): 9,961.8 deterministic CPU ONNX return and 1,000 / 1,000 steps (full 10 s upright balance vs. 231.4 / ~45 steps in v0.1.0; 4,130.9 mean return and 38% 1,000-step survival across 16 reset_type='random' starts; 0% solved_final_rate as marching speed stays below 1.2 ± 0.5 m/s). Obsolete old-clamp seed1/seed2 walk files from v0.1.0 were removed.
    • myoHandPoseRandom-v0 (seed0, 6.2M steps / 1.55M updates, ~8.7h): +100.03 ± 135.92 CPU ONNX return (18.8% any-step / 15.6% final-step solved over 64 held-out seeds; +115.11 / 25.0% solved over 32 validation seeds, up from -276.8 / 0% in v0.1.0).

Full test suite (12/12 pytest) and pre-commit pass.

…ONNX export, and PPO benchmark

- Add self-contained training/dreamerv3/ (myosuite-dreamerv3) package
  per docs/wiki/training-guidelines.md across CPU Gymnasium (DreamerEnv),
  GPU mjlab MuJoCo Warp twins (MjlabDriver, mapping [-1, 1] onto each
  term's action_range and sanitizing diverged Warp worlds), and
  experimental GPU MJX (MJXDriver).
- Add standalone JAX-free PyTorch / TorchScript / ONNX policy export
  (export.py) with MyoSuite deployment manifests (.onnx.manifest.json),
  silu activation parity, and pinned Hugging Face checkpoint resolution
  (maco018/myosuite-dreamerv3@ea6ca03a75eb3bfc7c1899232e445332ee7427ac,
  v0.2.0).
- Expose bounded exploration std flags (--minstd, --maxstd, --actent) on
  dreamerv3-train-mjlab and add multi-seed PPO vs. DreamerV3 benchmark
  harness and 12-test pytest suite.
@M-Colley
M-Colley force-pushed the feat/training-dreamerv3 branch from d05b730 to 8f59a5e Compare December 2, 2026 11:43
@M-Colley
M-Colley marked this pull request as draft December 2, 2026 12:40
@M-Colley M-Colley added this to the Post-3.0 milestone Dec 2, 2026
@M-Colley M-Colley added enhancement New feature or request stack:standalone Targets dev directly with no open PR or unreleased prerequisites area:training-ci RL training scripts/PPO configs, performance cards & CI workflows labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training-ci RL training scripts/PPO configs, performance cards & CI workflows enhancement New feature or request stack:standalone Targets dev directly with no open PR or unreleased prerequisites

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants