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

A better PyTorch wrapper #19

Merged
merged 14 commits into from
Apr 26, 2021
Merged

A better PyTorch wrapper #19

merged 14 commits into from
Apr 26, 2021

Conversation

raimis
Copy link
Contributor

@raimis raimis commented Nov 9, 2020

  • Refactor the wrapper to reuse ANISymmetryFunctions object
  • Fix serialization
  • Update the benchmarks
  • Update the build instructions

@@ -61,12 +63,13 @@ class TorchANISymmetryFunctions(torch.nn.Module):

>>> print(energy, forces)
"""
holder: Optional[torch.classes.NNPOps.CustomANISymmetryFunctions]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it something more descriptive like symmetryFunctions? In my example, the name holder was a ValueHolder object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still working on cleaning up the code, but to call an instance symmetryFunctions is misleading and might be confused with an actual reference to the function symFunc.

@raimis
Copy link
Contributor Author

raimis commented Nov 12, 2020

Benchmarks

Molecule: 46 atoms (pytorch/molecules/2iuz_ligand.mol2)
Model: ANI-2x
GPU: GTX 1080 Ti
Script: pytorch/BenchmarkTorchANISymmetryFunctions.py
Mode: forward and backward passes

Original TorchANI: 5.0 ms
Current NNPOps: 1.1 ms
New NNPOps: 0.4 ms

@peastman
Copy link
Member

Very nice!

@peastman
Copy link
Member

What's the status of this PR? It would be really good if we could get it finished up and merged in.

@raimis
Copy link
Contributor Author

raimis commented Feb 1, 2021

It works, but needs some tests. I will finish it after more or less two weeks, when the paper is done.

@peastman
Copy link
Member

peastman commented Mar 4, 2021

Any more updates? Until this is done, we can't use this kernel in OpenMM.

@raimis
Copy link
Contributor Author

raimis commented Mar 8, 2021

Ping @giadefa

@raimis raimis marked this pull request as ready for review March 31, 2021 13:55
@raimis
Copy link
Contributor Author

raimis commented Mar 31, 2021

@peastman I have managed to fix the serialization issue. Could you review?

@peastman
Copy link
Member

peastman commented Apr 2, 2021

Looks much better! Can we use a more meaningful name than "Holder", for example, ANISymmetryFunctions? That will make the code easier to understand.

Have you tested this to see if compiling to TorchScript works?

@raimis
Copy link
Contributor Author

raimis commented Apr 20, 2021

Looks much better! Can we use a more meaningful name than "Holder", for example, ANISymmetryFunctions? That will make the code easier to understand.

PyTorch wrapper implement four classes/functions:

  • NNPOps::ANISymmetryFunctions::Holder (Python side: torch.classes.NNPOpsANISymmetryFunctions.Holder)
  • NNPOps::ANISymmetryFunctions::AutogradFunctions::forward
  • NNPOps::ANISymmetryFunctions::AutogradFunctions::backward
  • NNPOps::ANISymmetryFunctions::operation (Python side: torch.ops.NNPOpsANISymmetryFunctions.operation)

I doubt that renaming NNPOps::ANISymmetryFunctions::Holder to NNPOps::ANISymmetryFunctions::ANISymmetryFunctions will make code easier to understand. Anyone wanting understand what is going on here most likely will have to refer to PyTorch C++ API documentation, which uses such class names as "Holder". Also, there is already ANISymmetryFunctions class in ani/ANISymmetryFunctions.h

Have you tested this to see if compiling to TorchScript works?

Yes, test_model_serialization in pytorch/TestSymmetryFunctions.py does that.

@giadefa
Copy link
Member

giadefa commented Apr 26, 2021

can we merge this?

@peastman
Copy link
Member

Ok!

@peastman peastman merged commit 3d0bab6 into openmm:master Apr 26, 2021
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.

3 participants