[Fix #648] Pass cell and pbc as args when calling AEVComputer so forward hook works via TorchScript #649
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.
This PR closes #648 by passing
cell
andpbc
as args rather than kwargs when callingself.aev_computer
withinBuiltinModel
andBuiltinEnsemble
. 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.)