Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #648] Pass cell and pbc as args when calling AEVComputer so forward hook works via TorchScript #649

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lohedges
Copy link

@lohedges lohedges commented Jul 8, 2024

This PR closes #648 by passing cell and pbc as args rather than kwargs when calling self.aev_computer within BuiltinModel and BuiltinEnsemble. This allows a user to add a forward hook to the internal AEVComputer of an ANI model to allow them to get AEVs from the hook at the same time that energies are obtained from the model.

While kwargs work fine with PyTorch, it appears that TorchScript assumes that the input parameter defined in the hook represents all input to the hooked function (AEVComputer.forward) , i.e. both args and kwargs. When recursing to create the scripted version of a module, TorchScript requires that the hooked function is called with args only throughout.

(I have been made aware of the code freeze and appreciate that this won't be merged. Just posting for posterity.)

lohedges added a commit to lohedges/NNPOps that referenced this pull request Jul 8, 2024
peastman added a commit to openmm/NNPOps that referenced this pull request Jul 10, 2024
* Use args when calling self.aev_computer. [ref aiqm/torchani#649]

* Trivial change to try to get CI to run

---------

Co-authored-by: Peter Eastman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass pbc and cell as args to allow use of forward hook with TorchScript
1 participant