[BUG FIX] Fix invalid gradients in differentiable rigid-body simulation. - #3087
Conversation
…th the testing conventions.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f289cfeaf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…ody backward pass.
…ody backward pass.
… coding guidelines.
…ody backward pass.
…ody backward pass.
…ody backward pass.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48e1afb11d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…repin the spherical multistep fp32 tolerance to the CUDA floor.
…ody backward pass.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Description
Follow-up to #2842, fixing the gradient defects surfaced by a full audit of the differentiable rigid-body backward pass, plus the maintainability and convention issues found along the way.
Gradient fixes:
RigidSolver.load_ckpt) reran the cartesian-space update but not the forward velocity pass, while the replayed substeps skip both; every backward primal in the window then carried stale link velocities, injecting an eps-independent error into every multi-step gradient.Jdot @ qvelfolded intoaref(CONNECT and WELD position rows) and the WELD rotation rows' quaternion-derivative bias.d(jac_qvel)/d(vel)once per chain visit, double-counting shared ancestor dofs of same-root pairs.impratioin the regularized friction-cone coefficient ofefc_D.dofs.pos.grad(position control, joint stiffness) was never consumed; it now folds back intoqpos.gradfor all joint types.attach()withrequires_grad=True.rows_per_contactinstead of a hardcoded 4.Maintainability: the duplicated impedance-derivative, velocity-contraction, and plane-contact-frame blocks collapse into shared funcs; dead code is removed; grad shuffles on the backward hot path go through zero-copy torch views with the kernels as fallback.
Tests: existing tests are strengthened to fail on each defect above (same-root four-bar connect and nested skew-axis weld fixtures, offset-slide chain, joint stiffness, non-default
impratio, split-subset force control, larger equality velocities), and the suite is aligned with the testing conventions. All finite-difference tolerances are re-pinned to floors measured on darwin cpu/Metal and linux cpu/CUDA after the fixes, at a x1.5-5 margin over the worst platform: most fp64 checks tighten by 1 to 5 orders of magnitude (the old floors were these bugs, not physics). Two multistep arms whose position loss was constant now read the quaternion instead of passing vacuously.Related Issue
Follow-up to #2842.
Addresses #2069: the control-force gradient path it reports broken is fixed and validated per-step by the strengthened multistep tests.
Addresses #2150: the forward-kinematics backward pass it exercises is audited and fixed here; the specific Franka scene remains to be confirmed.
Motivation and Context
The audit found gradient errors ranging from 2e-2 relative down to 3e-7 that finite-difference validation had missed because the scenarios or tolerances did not excite them. Wrong gradients silently break any downstream optimization.
How Has This Been / Can This Be Tested?
pytest tests/grad/ --backend cpu: 46 passed, 10 skipped (Apple Metal reverse-mode skips) on macOS M4 Max; 56/56 with the Metal skip lifted locally against a Quadrants build containing the issue [BUG FIX] better handling saved terrain #805 fix. Full suite also validated on linux CPU (fp64) and CUDA (fp32) with the tightened tolerances.Checklist:
Submitting Code Changessection of CONTRIBUTING document.