Repository navigation
Avoid NaN stress gradients for zero-volume molecular cells - #181
Merged
vsimkus merged 2 commits intoNov 9, 2026
Merged
Conversation
davrens101
requested review from
benrhodes26,
jg8610,
reactiv and
vsimkus
as code owners
November 6, 2026 09:20
vsimkus
approved these changes
Nov 9, 2026
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.
Problem
Stress for a zero-volume molecular cell is divided by
abs(det(cell))before invalid results are masked to zero. The forward result looks valid, but backward through a stress loss still divides by zero and can poison the force-training gradients. Both conservative stress and the direct ZBL stress path have this ordering.Change
Use a safe denominator for cells without volume, then retain the existing zero-stress output for those cells. Finite positive-volume calculations, cell-handedness handling and checkpoint parameters are unchanged. Document the zero-volume gradient behavior.
The three regression cases are necessary here because forward-only tests miss the defect: all-molecular and mixed-periodicity force-loss parameter gradients, plus the positional derivative of molecular ZBL stress. All three fail before this patch.
Validation
E = k * sum(edge_vectors**2)returns zero molecular stress before and after; the force-plus-stress loss derivative changes fromNaNto the analytic31.36.ConservativeForcefieldRegressor.loss(...).loss.backward()on a small nonperiodic H2O graph: upstream has 42 non-finite parameter-gradient tensors on the first step; patched has zero non-finite tensors across four Adam steps, with loss3.1429 -> 2.3833. No pretrained checkpoint or model-quality claim.Upstream Ubuntu CI subsequently completed successfully: Python 3.12, 3.13 and 3.14 test jobs, the aggregate
allchecksjob, and both Socket Security checks are green.Local compilation limitation: the broader Windows CPU run fails during Dynamo tracing; a separate untouched upstream checkout also fails with recursion in
compute_differentiable_edge_vectors. Compiled-model and GPU behavior are not claimed as verified.AI-assisted implementation and validation, with an additional review by a second coding agent. I supervised and checked the AI-assisted work as it progressed.