1 #include <torch/csrc/autograd/python_anomaly_mode.h> 2 #include <torch/csrc/python_headers.h> 3 #include <torch/csrc/utils/auto_gil.h> 4 #include <torch/csrc/utils/python_strings.h> 5 #include <torch/csrc/utils/object_ptr.h> 6 #include <torch/csrc/Exceptions.h> 10 namespace torch {
namespace autograd {
12 void PyAnomalyMetadata::store_stack() {
19 THPObjectPtr list(PyObject_CallMethod(mod.get(),
"format_stack",
""));
24 if (PyDict_SetItemString(dict(), ANOMALY_TRACE_KEY, list.get())) {
29 void PyAnomalyMetadata::print_stack() {
31 if (!PyDict_Check(dict())) {
32 throw std::runtime_error(
"Anomaly metadata is not a python dictionary.");
36 PyObject* stack(PyDict_GetItemString(dict(), ANOMALY_TRACE_KEY));
38 AT_WARN(
"No forward pass information available. Enable detect anomaly " 39 "during forward pass for more information.");
55 AT_WARN(
"Traceback of forward call that caused the error:\n",
56 THPUtils_unpackString(msg.get()));