mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
cpp_wrapper: rethrow Python exceptions, when present (#141369)
When running fallback operations in `cpp_wrapper` mode, Python errors thrown in the fallback should be propagated up the stack. This PR fixes the current situation, which discards all Python errors thrown in the fallback op in favor of an uninformative `RuntimeError`. Pull Request resolved: https://github.com/pytorch/pytorch/pull/141369 Approved by: https://github.com/desertfire ghstack dependencies: #141368, #141580
This commit is contained in:
committed by
PyTorch MergeBot
parent
4613bd393d
commit
dd7debdbe8
@ -2294,13 +2294,16 @@ class CppWrapperCodeCache(CppPythonBindingsCodeCache):
|
||||
std::vector<AtenTensorHandle> output_handles(%s);
|
||||
try {
|
||||
inductor_entry_impl(input_handles.data(), output_handles.data());
|
||||
if (PyErr_Occurred()) {
|
||||
return nullptr;
|
||||
}
|
||||
return pack_tensor_handle_list(output_handles);
|
||||
} catch(std::exception const& e) {
|
||||
PyErr_SetString(PyExc_RuntimeError, e.what());
|
||||
return {};
|
||||
return nullptr;
|
||||
} catch(...) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "unhandled error");
|
||||
return {};
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user