Revive DiffMjStep as a lean PyTorch–MuJoCo autograd package - #1
Merged
Conversation
EladSharony
force-pushed
the
revive/minimal-correctness
branch
from
July 5, 2026 11:42
d8d165d to
34c7b4f
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Product scope
This PR is intentionally product-only. It contains:
diffmjstepPython package;00_basic_step.py,03_trajectory_optimization.py, and04_sensor_loss.py);The test suite, CPU benchmarks, CI workflow,
uv.lock, and development configuration live on the linkedrevive/validationbranch. 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
mj_step,mj_rollout, andmj_linearizeAPIs with explicit batch axes.Benchmarks
The README embeds two hand-authored, theme-safe SVG figures (
assets/), rendered from measured runs: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).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_transitionFDreverse-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 buildcompleted successfully.diffmjstepimported successfully and its package source resolved from the installed wheel environment.On the separate
revive/validationbranch:uv run --frozen pytest -q— 110 passed.uv run --frozen ruff check .completed successfully.uv buildcompleted successfully.cirun passed on Ubuntu and macOS.