Detect anomaly in C++

//
// Created by duane on 10/2/20.
//

#include <torch/torch.h>


int main(int arg, char *argv[]){
    
    torch::autograd::AnomalyMode::set_enabled(true);
    auto x = torch::tensor({5.0}, torch::requires_grad());
    x.backward();
    std::cout << x.grad() << std::endl;
}

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I suppose you need to do a bit more than just set anomaly mode.

1 Like