Solved by IvanKobzarev in post #4 
              
              
                @vishalagarwal 
Java binding works for forward only and auto grad is disabled all the time. 
Details: 
It has torch::autograd::AutoGradMode g{false} before every forward operation.