fix(electrostatics): compile explicit single-system batches - #133
fix(electrostatics): compile explicit single-system batches#133zubatyuk wants to merge 5 commits into
Conversation
Specialize explicit B=1 reductions to avoid size-one scatter operations rejected by Inductor. Materialize reciprocal PME cotangents and add CPU/CUDA regression coverage. Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
Greptile SummaryThis PR fixes
Important Files Changed
Reviews (5): Last reviewed commit: "Merge remote-tracking branch 'refs/remot..." | Re-trigger Greptile |
Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
Add default CPU compiler canaries for PME and slab, cover non-neutral Ewald reciprocal corrections, and document the fix. Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
|
/ok to test 6d283cd |
laserkelvin
left a comment
There was a problem hiding this comment.
One performance suggestion; left inline.
Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
…single-system-compile Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
|
/ok to test 2fabd9a |
ALCHEMI Toolkit-Ops Pull Request
Description
Fix
torch.compilefor a logically single Ewald/PME/slab system when callers provide an explicitbatch_idx=zeros(N).Without this change, the backward path treats explicit
B=1input as a segmented batch and reduces atom values withindex_addor scatter operations into a tensor whose leading dimension is one. PyTorch Inductor's CPU vector-atomic code generation can reject that size-one destination, even though the equivalent unbatched call (batch_idx=None) compiles because it uses a direct mean.The same atom-to-system pattern appears in energy cotangents, double backward, cell and virial gradients, charge corrections, direct-k Ewald, and slab correction. The fix centralizes those operations and specializes only the structural
num_systems == 1case:Explicit
batch_idxremains intact, so batched custom-op and Warp-kernel dispatch does not change. Multi-system inputs continue to use segmented reductions.The reciprocal PME autograd chain also materializes the Hermitian-weighted RFFT cotangent before passing it to the opaque convolution backward:
This prevents Inductor from scheduling the interior-frequency weighting after the custom backward has already consumed the cotangent.
Type of Change
Related Issues
Merge this PR before #132: fix(electrostatics): avoid per-system backward recomputation.
Changes Made
B=1PME, Ewald, and slab energy, position/charge/cell gradients, direct outputs, and supported higher-order derivatives.B=2segmentation with unequal atom counts and non-uniform cotangents.Testing
make pytest)make lint)Focused CPU/CUDA validation passed 302 tests covering helper contracts, compile paths, first- and second-order derivatives, batch consistency, q(R), and empty inputs. The supplied explicit-
B=1reproducer reports successful compilation for bothbatch_idx=zeros(N)andbatch_idx=None.make interrogateandgit diff --checkalso pass.Checklist
Additional Notes
Faster B-spline test
Optimized
test_weight_n_fold_convolution_parityfor spline orders 5 and 6 by replacing repeatednp.convolvecalls with an equivalent prefix-sum calculation. These cases now take about 1–2 ms instead of 4–10 seconds, with less than1e-14numerical difference. This improves test runtime only; production PME code is unchanged.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.