Create PythonTorchForce - #179
Conversation
|
There, I finally got all the tests to pass! The CI workflow was very out of date. |
| } | ||
|
|
||
| vector<string> PythonTorchForceImpl::getKernelNames() { | ||
| return {CalcCustomCPPForceKernel::Name()}; |
There was a problem hiding this comment.
Should this be CalcPythonTorchForceKernel::Name()?
|
The test failure looks strange... It's crashing in a kernel inside the GPU minimizer. Is it running with some CPU OpenCL implementation that's getting installed in the CI environment? I can't reproduce it locally with either NVIDIA (GPU) or Intel CPU OpenCL; everything passes on my machine. |
|
I've been trying to reproduce it, also without success. It's using pocl, which is a very buggy OpenCL. That might or might not be the problem. |
|
After switching from pocl to Intel OpenCL (which is still buggy, but not quite as buggy), the test passes. And I can see it running OpenCL tests, so it's not just that the platform gets skipped. |
epretti
left a comment
There was a problem hiding this comment.
Looks good. I tried installing pocl on my machine and could reproduce the failure from before; the minimizer test and several others from the main OpenMM test suite failed with it, so I think it is just a broken implementation. In any case, it seems not to be a problem with PythonTorchForce or the minimizer.
This adds PythonTorchForce. It's very similar to PythonForce, except that the positions are passed as a Tensor instead of a State, and the forces are returned as a Tensor instead of a NumPy array. When using the CUDA platform, this lets us skip some data copies between host and device, reducing overhead.
In principle we could do the same with HIP, but I haven't managed to compile anything against the HIP build of PyTorch. See pytorch/pytorch#181939.
So how much does it help? I tried using AceFF 1.1 (a pretty fast potential as ML models go) to simulate a 2 nm water box with 774 atoms on a RTX 4080. With the current PythonForce implementation, 100 time steps take 1.92 seconds. Switching to PythonTorchForce reduces it to 1.88 seconds. Oh well. Looking at the profiler I can see that each invocation of the model takes about 18 ms. In between there's a gap where it does data transfers and integration. With PythonForce, that gap is about 1 ms. PythonTorchForce reduces it to 0.5 ms.
So this is only going to be signficant for really fast models. Still, it's something.