Skip to content

Revive DiffMjStep as a lean PyTorch–MuJoCo autograd package - #1

Merged
EladSharony merged 1 commit into
masterfrom
revive/minimal-correctness
Jul 5, 2026
Merged

Revive DiffMjStep as a lean PyTorch–MuJoCo autograd package#1
EladSharony merged 1 commit into
masterfrom
revive/minimal-correctness

Conversation

@EladSharony

@EladSharony EladSharony commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Product scope

This PR is intentionally product-only. It contains:

  • the installable diffmjstep Python package;
  • the native C++ reverse-time VJP implementation;
  • three user-facing examples (00_basic_step.py, 03_trajectory_optimization.py, and 04_sensor_loss.py);
  • the README (with CPU benchmark figures), license/citation files, and package/release metadata.

The test suite, CPU benchmarks, CI workflow, uv.lock, and development configuration live on the linked revive/validation branch. They remain available for maintainers and reproducibility without inflating the product PR.

Relative to master, the product diff is exactly 26 files, 1,795 additions, and 1,971 deletions: a net deletion of 176 lines.

Retained runtime capabilities

  • Public mj_step, mj_rollout, and mj_linearize APIs with explicit batch axes.
  • MuJoCo C rollout plus the automatically selected, bounded-thread native C++ reverse-time VJP on Linux and macOS.
  • Differentiable sensor losses and standalone linearization.
  • Callback-safe replay and isolated, coherent warm-start behavior.

Benchmarks

The README embeds two hand-authored, theme-safe SVG figures (assets/), rendered from measured runs:

  • Hero (benchmark.svg): CPU throughput versus a single-threaded pure-Python reference of the same algorithm — 51× faster forward and 13× faster backward at batch 4096 (transitions/s, log scale).
  • Per-model (speedup_per_model.svg): the out-of-the-box breakdown at batch 256 across nine dm_control models — forward 11–23× (scales with model simplicity), backward a steady ~5–6×.

Measured on an Intel i9-14900K, MuJoCo 3.10, float64. The baseline is the same mjd_transitionFD reverse-time VJP without the native acceleration, so the speedup isolates the native/parallel backend, not a different gradient method.

Validation evidence

On the product branch:

  • uv build completed successfully.
  • The wheel was installed into an isolated environment; diffmjstep imported successfully and its package source resolved from the installed wheel environment.
  • All three retained examples ran successfully.

On the separate revive/validation branch:

  • uv run --frozen pytest -q110 passed.
  • uv run --frozen ruff check . completed successfully.
  • uv build completed successfully.
  • The ci run passed on Ubuntu and macOS.

@EladSharony EladSharony changed the title [codex] Revive DiffMjStep as a lean, high-performance research repo Revive DiffMjStep as a lean PyTorch–MuJoCo autograd package Jun 29, 2026
@EladSharony
EladSharony force-pushed the revive/minimal-correctness branch from d8d165d to 34c7b4f Compare July 5, 2026 11:42
Minimal PyTorch autograd for differentiable MuJoCo stepping on CPU: mujoco.rollout forward
with a custom backward that applies mjd_transitionFD transition Jacobians as a reverse-time
VJP, so losses differentiate w.r.t. initial state and controls without leaving PyTorch.
Native C++ VJP backend, examples, tests scope, and README with CPU benchmark figures.
@EladSharony
EladSharony marked this pull request as ready for review July 5, 2026 11:54
@EladSharony
EladSharony merged commit 5729bd5 into master Jul 5, 2026
@EladSharony
EladSharony deleted the revive/minimal-correctness branch July 5, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant