pytorch/torch/csrc/jit/python
David Berard 272890998e [JIT] pass more exception info through the JIT interpreter
If TORCH_SHOW_CPP_STACKTRACES=1, then dump e.what() into the RuntimeError, which should make it easier to debug exceptions that happen within interpreted sections.

Test:
```patch
diff --git a/test/cpp/jit/test_dce.cpp b/test/cpp/jit/test_dce.cpp
index 6f9161d0d9..7c574787cf 100644
--- a/test/cpp/jit/test_dce.cpp
+++ b/test/cpp/jit/test_dce.cpp
@@ -3,6 +3,10 @@
 #include <torch/csrc/jit/ir/irparser.h>
 #include <torch/csrc/jit/passes/dead_code_elimination.h>
 #include <torch/csrc/jit/testing/file_check.h>
+#include <torch/csrc/jit/runtime/interpreter.h>
+#include <test/cpp/jit/test_utils.h>
+
+#include <ATen/ATen.h>

 namespace torch {
 namespace jit {
@@ -48,5 +52,30 @@ graph():
   // Check that dead code elimin
   testing::FileCheck().run(input, *graph);
 }
+
+TEST(EliminateDeadCodeTest, interpreterfailure) {
+  const std::string input = R"IR(
+graph(%x.1 : Tensor):
+  %2 : int = prim::Constant[value=128]() # /data/users/dberard/scripts/DGB/sz.py:4:38
+  %3 : int = prim::Constant[value=256]() # /data/users/dberard/scripts/DGB/sz.py:4:43
+  %5 : int = prim::Constant[value=1]() # /data/users/dberard/scripts/DGB/sz.py:4:53
+  %4 : int[] = prim::ListConstruct(%2, %3)
+  %6 : Tensor[] = aten::split_with_sizes(%x.1, %4, %5) # /data/users/dberard/scripts/DGB/sz.py:4:11
+  return (%6)
+)IR";
+  auto graph = std::make_shared<Graph>();
+  parseIR(input, graph.get());
+
+  //auto stack = createStack({at::randn({2, 383}, at::kCPU)});
+  auto stack = createStack({at::Tensor{}});
+
+  Code code(graph, "");
+  InterpreterState interpreter{code};
+  interpreter.run(stack);
+ ASSERT_EQ(2, stack.size());
+  ASSERT_FALSE(stack[0].toTensor().defined());
+  ASSERT_FALSE(stack[1].toTensor().defined());
+}
+
 } // namespace jit
 } // namespace torch
```

^ use this to repro the interpreter issue: `TORCH_SHOW_CPP_STACKTRACES=1 ./bin/test_jit --gtest_filter="EliminateDeadCodeTest.interpreterfailure"` and the stack trace is shown.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75682

Approved by: https://github.com/eellison
2022-04-21 18:26:49 +00:00
..
init.cpp [JIT] pass more exception info through the JIT interpreter 2022-04-21 18:26:49 +00:00
init.h
module_python.h
pybind_utils.cpp Introducing SymInt to Pytorch (for tracing size arithmetic) (master rebase) (#74861) 2022-03-31 21:59:59 +00:00
pybind_utils.h Get rid of TorchScript sparse tensor is experimental warning. (#73874) 2022-03-09 15:45:24 +00:00
pybind.h [AutoAccept][Codemod][FBSourceClangFormatLinter] Daily arc lint --take CLANGFORMAT 2021-12-19 16:38:25 -08:00
python_arg_flatten.cpp
python_arg_flatten.h
python_custom_class.cpp
python_custom_class.h
python_dict.cpp
python_dict.h
python_interpreter.cpp
python_ir.cpp Introducing SymInt to Pytorch (for tracing size arithmetic) (master rebase) (#74861) 2022-03-31 21:59:59 +00:00
python_ir.h
python_ivalue.h
python_list.cpp [BE] Fix pybind deprecation warnings (#72376) 2022-02-07 18:33:32 +00:00
python_list.h Fix sign-compare violations in python_list.h 2022-04-01 19:15:51 +00:00
python_sugared_value.cpp sup torch script parameterlist 2022-04-20 20:53:07 +00:00
python_sugared_value.h sup torch script parameterlist 2022-04-20 20:53:07 +00:00
python_tracer.cpp
python_tracer.h
python_tree_views.cpp Reland "Make debug_pkl smaller by only emitting unique traces." (#73368) 2022-04-18 22:34:21 +00:00
python_tree_views.h
script_init.cpp sup torch script parameterlist 2022-04-20 20:53:07 +00:00
script_init.h
update_graph_executor_opt.cpp
update_graph_executor_opt.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00