Detach conservative inference energy outputs - #2136
wtfPrethiv wants to merge 5 commits into
Conversation
|
Hi @wtfPrethiv! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
frostedoyster
left a comment
There was a problem hiding this comment.
@rayg1234 do we want to support users of this function differentiating energies/forces on their own? Otherwise this PR looks good
|
@frostedoyster The GPU sweep completed all 44 selected tests successfully (1 expected XFAIL), but the job then segfaulted during NCCL shutdown with exit code 139. Could you rerun test_gpu_sweep (3.14, units, uma-s-1p1) to check whether this was a transient runner issue? Thanks ! |
|
Hey @wtfPrethiv, thank you very much for the contribution! We're trying to fix some issues with our tests and CI but I think we will be able to merge this PR relatively soon |
|
Hey @frostedoyster, just wanted to follow up on this PR since it’s been a few weeks. Happy to make any changes or help with anything needed. Thanks ! |
Fix conservative UMA inference outputs retaining autograd graphs
Closes #2072.
Problem statement
Conservative UMA inference (
direct_forces=False) must keep autograd enabled to derive forces from energy. However,MLIPPredictUnit.predict()returned the energy tensor with its complete forward autograd graph still attached.Callers that retain completed predictions across multiple calls; for example TorchSim’s batching/reassembly flow therefore retained one full model forward graph per prediction. Allocated GPU memory grew roughly linearly and could not be reclaimed with
torch.cuda.empty_cache().TorchSim worked around this downstream in TorchSim/torch-sim#590 while awaiting the fairchem-side fix.
Root cause
_run_inference()correctly usesnullcontext()for conservative models soautograd.grad()can compute forces. Forces usecreate_graph=Falseand do not retain a graph, but energy passed through_process_outputs()unchanged after denormalization/reference restoration.Fix
Detach returned conservative-evaluation tensors at the inference output boundary, after all post-processing:
This:
Validation
Before the fix, conservative UMA inference returned graph-bearing energy:
After the fix:
Added regression coverage for:
predict()outputs: every returned tensor is detached.predict()path: remains unaffected.backward()succeeds.Test results
git diff --check: passedThe broader pretrained UMA suite is blocked in this environment by a
401 Unauthorizedresponse from the gatedfacebook/UMAHugging Face repository before model execution.