Struggling with debugging. Meaningless error messages, can't inspect tensors, etc

I’m currently trying to port a model that works fine in python to c++ but I’m having trouble with the backwards() of a custom autograd function and I’m struggling to make progress.

I’m just getting a “std::system_error at memory location 0x000000FD532FE7C0.” error when calling torch::autograd::grad.

I probably would have solved it by now by comparing to the python version, but debugging the python backward method is difficult because it’s called from C.

Although this post is primarily about this specific error, in general I’m finding the Libtorch dev experience to be a PITA. Can anyone suggest any tips to get:

  • Useful error messages
  • Useful inspection of tensors (without having to litter couts everywhere in the code)


You could try to use export TORCH_SHOW_CPP_STACKTRACES=1 to (hopefully) get a better stacktrace. Besides that you could also use gdb to try to isolate the issue.