fix(electrostatics): dechain dependent autograd inputs#131
Conversation
Correct Torch electrostatics fallback gradients for connected charges, positions, cell, and alpha inputs. Add derivative regressions across Torch and JAX bindings. Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
Greptile SummaryThis PR fixes double-counted autograd contributions in the Torch custom-backward fallback for energy-only PME and Ewald outputs. The root cause was that returning total connected gradients for all differentiable inputs (positions, charges, cell, alpha) when those inputs share autograd paths caused PyTorch to propagate each returned gradient through its upstream sub-graph a second time.
Important Files Changed
|
ALCHEMI Toolkit-Ops Pull Request
Description
Fix the Torch custom-backward fallback for energy-only PME and Ewald outputs. It is used for non-uniform energy cotangents and when the caller requests a differentiable first derivative (
create_graph=True). When charges depended on positions, positions depended on cell/strain, or both, the fallback returned connected total gradients for multiple inputs. PyTorch then propagated each returned downstream gradient through its upstream dependency again.The bug affected first-order position and cell gradients from weighted energy losses, plus second-order derivatives (HVPs and force-loss/double-backward workloads). It covered the shared Ewald/PME energy connector and PME reciprocal cached-first-gradient connector. Uniform first-order cached gradients and direct force/virial output semantics are unchanged.
Type of Change
Related Issues
None.
Changes Made
Testing
make pytest)make lint)Targeted Torch electrostatics utility and PME suites pass locally.
Checklist
Additional Notes
None.
Tip
This repository uses Greptile, an AI code review service, to help conduct
pull request reviews. We encourage contributors to read and consider suggestions
made by Greptile, but note that human maintainers will provide the necessary
reviews for merging: Greptile's comments are not a qualitative judgement
of your code, nor is it an indication that the PR will be accepted/rejected.
We encourage the use of emoji reactions to Greptile comments, depending on
their usefulness and accuracy.