Solved by albanD in post #4 
              
              
                Here is an implementation that will work for any k1 and k2 and will reduce memory usage as much as possible. 
If k2 is not huge and the one_step_module is relatively big, the slowdown of doing multiple backward should be negligible. 
The code is not super clean and has been tested only against curre…