mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[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
This commit is contained in:
committed by
PyTorch MergeBot
parent
e5282c3cb8
commit
272890998e
@ -26,6 +26,7 @@
|
||||
#include <torch/csrc/jit/runtime/profiling_record.h>
|
||||
#include <torch/csrc/jit/runtime/script_profile.h>
|
||||
#include <torch/csrc/jit/runtime/vararg_functions.h>
|
||||
#include <torch/csrc/utils/cpp_stacktraces.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef USE_RPC
|
||||
@ -796,7 +797,7 @@ struct InterpreterStateImpl : c10::intrusive_ptr_target {
|
||||
python_class_name = jit_exception->getPythonClassName();
|
||||
}
|
||||
handleError(
|
||||
ExceptionMessage(e),
|
||||
e,
|
||||
(bool)jit_exception,
|
||||
not_implemented_error,
|
||||
python_class_name);
|
||||
@ -816,10 +817,11 @@ struct InterpreterStateImpl : c10::intrusive_ptr_target {
|
||||
}
|
||||
|
||||
void handleError(
|
||||
const ExceptionMessage& msg,
|
||||
const std::exception& e,
|
||||
bool is_jit_exception,
|
||||
c10::NotImplementedError* not_implemented_error,
|
||||
c10::optional<std::string> python_class_name) {
|
||||
ExceptionMessage msg(e);
|
||||
std::ostringstream ss;
|
||||
std::string class_name =
|
||||
python_class_name ? *python_class_name : "RuntimeError";
|
||||
@ -836,6 +838,9 @@ struct InterpreterStateImpl : c10::intrusive_ptr_target {
|
||||
not_implemented_error->backtrace(),
|
||||
not_implemented_error->caller());
|
||||
} else {
|
||||
if (get_cpp_stacktraces_enabled()) {
|
||||
ss << e.what() << "\n";
|
||||
}
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user