Solved by yf225 in post #2 
              
              
                This will work: 
#include <torch/torch.h>
#include <iostream>
#include <torch/csrc/autograd/function.h>

int main(int argc, const char* argv[]) {
    auto x = torch::randn({2, 3});
    x.set_requires_grad(true);
    auto z = x + x;
    torch::autograd::Variable y = torch::autograd::as_variable_ref(z…