also, there is pytorch JIT compiler that is still experimental in pytorch 0.4, but it works for me - it compiles the python code into C code on the fly with very little changes to your source code. It should also work much faster.