add implicit differentiation for constraint solver 2/3#1
Open
mar-yan24 wants to merge 1 commit intomark/autodifferentiationfrom
Open
add implicit differentiation for constraint solver 2/3#1mar-yan24 wants to merge 1 commit intomark/autodifferentiationfrom
mar-yan24 wants to merge 1 commit intomark/autodifferentiationfrom
Conversation
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.
Add Implicit Differentiation for Constraint Solver (2/3)
This PR is phase 2/3 for the AD implementation in mjwarp. It depends on PR google-deepmind#1226 merging/passing first.
TLDR
Phase 2 enables reverse-mode automatic differentiation through MuJoCo Warp's constraint solver. Solver uses iterative convergence + discontinuous constraint activation and tile Cholesky operations that cannot be directly differentiated by Warp's tape. Instead, apply implicit differentiation to bridge gradient gap.
The main implementations were:
Retained Solver State
The solver's Hessian and Cholesky factor are retained on
Datafor reuse during the backward pass:Data.solver_h: Hessian matrixH = M + J^T * diag(D_active) * JData.solver_hfactor: Cholesky factor of H (nv > 32 blocked path only)Data.solver_Jaref: Reference force from last Newton iterationThese are allocated in
io.py:make_data()and aliased intoSolverContextduring the forward solve.Implicit Differentiation Adjoint
The
tape.record_funcis the main Warp mechanism focused on. It records a callable into the tape's execution list. When runningtape.backward(), callables execute at their recorded pos in the reversed list.Tape Order
Forward:
Backward:
When the callable executes:
d.qacc.gradalready hasdL/dqaccfrom integration backwardH * v = dL/dqaccd.qacc_smooth.grad = M * vfwd_accelerationbackward readsd.qacc_smooth.gradand propagatesLimitations
There are several known limitations as mentioned in the original PR comment. But this specific PR assumes a fixed active set. Implicit diff assumes small perturbations dont change which constraints are active.