add smooth contact autodifferentation and freejoin zerograd fix 3/3#2
Open
mar-yan24 wants to merge 24 commits intomark/autodifferentiation2from
Open
add smooth contact autodifferentation and freejoin zerograd fix 3/3#2mar-yan24 wants to merge 24 commits intomark/autodifferentiation2from
mar-yan24 wants to merge 24 commits intomark/autodifferentiation2from
Conversation
* Fix multi flex indexing * Fix kernel order * Add multiflex test * Move flex test, fix types ordering * Fix kernel args ordering * Add newline EOF * Cleanup multiflex xml
* Optimize qderiv_actuator_passive_actuation * Add a UT for sparse and coupled actuator * Autoformatter * Address PR review comment * Address PR review comment (2) * fix merge --------- Co-authored-by: Taylor Howell <[email protected]>
benchmark/humanoid -> benchmarks/humanoid in testspeed, viewer, and render docstrings.
* Add 1d flex rendering, and add flex to bvh * WIP refactor of flex rendering * Fix and cleanup post merge * Minor fixes and ruff * More cleanup of io for new flex * Remove unused values * Add multi flex test xml * Fix multiflex bug * Fix multi flex indexing * Fix kernel order * Add multiflex test * Move flex test, fix types ordering * Fix kernel args ordering * Add newline EOF * Cleanup multiflex xml * Update rope flex test * Fix model arg * Small fixes * Ruff * Kernel args ordering * Render kernel args ordering * Cleanup tid naming in render/bvh kernels * Restructure accumulate vertex normals * Fix formatting * Cleanup * Fix bvh tests
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.
Smooth Contact Autodifferentiation 3/3
Overview
Third and final PR in the autodiff chain. Depends on PR google-deepmind#1226 and PR (2/3) merging first.
mark/autodifferentiation->main)mark/autodifferentiation2->mark/autodifferentiation)mark/autodifferentiation3->mark/autodifferentiation2)This phase, makes contact geometry differentiable. During a taped forward pass, the discrete collision results (
dist,pos,frame) get overwritten by smooth analytic distance functions Warp can differentiate, and constraint assembly (efc.J,efc.pos) is recomputed on a differentiable path. Custom adjoint kernels then push efc-level gradients back through the KKT system into contact geometry.Smooth Collision Recomputation
collision_smooth.pyreplaces the collision pipeline's contact geometry with differentiable versions. It runs after the discrete pipeline and overwritescontact.{dist, pos, frame}with smooth values from analytic distance functions.Supported geom type pairs:
Unsupported types (box, mesh, convex, ellipsoid, SDF) keep their discrete contact values with zero gradient.
Only runs when the Warp tape is active and
qpos.requires_gradis set, so non-AD forward paths have no overhead.EFC-Level Adjoint Kernels
Two new kernels in
adjoint.pyconnect the solver adjoint (Phase 2) to collision geometry:_efc_J_grad_kernel: computesadj_efc_J[i,j] = v[j] * efc_force[i]from the KKT adjoint vector_efc_pos_grad_kernel: computesadj_efc_posfromadj_efc_arefvia the impedance chain ruled(aref)/d(pos) = -k * impBoth are launched at the end of
solver_implicit_adjointwhen collision grad fields are active.Gradient Field Registry
COLLISION_GRAD_FIELDSingrad.pylists the contact/efc arrays that needrequires_grad=Truefor the collision AD chain._resolve_fieldhandles dotted field paths like"contact.dist"and"efc.J".Bug Fixes (carried forward)
smooth.py): replacedcontinuein the kinematics kernel's freejoint branch with anis_freeinteger flag. Warp's AD replay forcontinueinside dynamic for-loops emits a goto that skips all adjoint code for that iteration, zeroing gradients.solver_h,solver_hfactor,solver_Jaref).Limitations
efc_posgradient.Test Plan
test_enable_backward_module_flags: verifiescollision_smoothhasenable_backward=Truetest_euler_step_grad_free: full Euler step AD gradient for freejoint+hinge modeltest_enable_grad_all_smooth_fields: all registered fields toggled correctly via_resolve_fieldtest_kinematics_grad("free", ...): freejoint kinematics gradienttest_forward_without_grad_no_error: non-AD path unaffectedtest_diff_step_produces_nonzero_gradients: end to end