This example is a 4-dimensional geometric brownian motion. The code
for the torchsde version is pulled directly from the
torchsde README
so that it would be a fair comparison against the author's own code.
The only change to that example is the addition of a dt
choice so that
the simulation method and time step matches between the two different programs.
The SDE is solved 100 times. The summary of the results is as follows:
- torchsde: 1.87 seconds
- DifferentialEquations.jl: 0.00115 seconds
This demonstrates a 1,600x performance difference in favor of Julia on the Python library's README example. Further testing against torchsde was not able to be completed because of these performance issues.
We note that the performance difference in the context of neural SDEs is likely smaller due to the ability to time spent in matrix multiplication kernels. However, given that full SDE training examples like demonstrated here generally take about a minute, we still highly expect a major performance difference but currently do not have the compute time to run a full demonstration.
Thanks for these benchmarks. We just added a new Brownian motion implementation in C++, which can be imported as
from torchsde.brownian_lib import BrownianPath
for torch==1.5.0/1.5.1 (it currently breaks in 1.6.0 due to some changes in PyTorch C++ API for generators, but I'll fix it this weekend). You'll likely see improvements with this version.Also for
method="srk"
, you could feed tosdeint
the additional inputoptions={'trapezoidal_approx': False}
for performance. This will give a big difference. This option was there since the first release, but I didn't fully document it. This will also be fixed soon.Overall, we are still working on Python-end micro-optimization and porting more code to C++. Ultimately, for tiny problems that are ran on CPUs, it's not unexpected that the Python interpreter overhead might dominate.