@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.

  
      github.com
  
  
    pytorch/pytorch/blob/master/android/pytorch_android/src/main/cpp/pytorch_jni_jit.cpp#L28 1

#include <android/asset_manager_jni.h>
#include <android/log.h>
#endif


namespace pytorch_jni {


namespace {


struct JITCallGuard {
  // AutoGrad is disabled for mobile by default.
  torch::autograd::AutoGradMode no_autograd_guard{false};
  // Disable graph optimizer to ensure list of unused ops are not changed for
  // custom mobile build.
  torch::jit::GraphOptimizerEnabledGuard no_optimizer_guard{false};
};


} // namespace


class MemoryReadAdapter final : public caffe2::serialize::ReadAdapterInterface {
 public:
  explicit MemoryReadAdapter(const void* data, off_t size)