Skip to content

Conversation

ysiraichi
Copy link
Collaborator

@ysiraichi ysiraichi commented Aug 7, 2025

This PR refactors BuildStatusErrorMessage function, so it's easier to use in other places besides in the MaybeThrow() implementation. For example, when crashing on a status value.

As a practical example, I used it to better show the error information when _get_graph_hash() crashes:

TORCH_SHOW_CPP_STACKTRACES=0

#################################################################
# Before this PR
F0000 00:00:1754594604.459119   30334 init_python_bindings.cpp:3380] Check failed: xtensors_status.ok() _get_graph_hash(): error retrieving the XLA tensors from the given tensor arguments. This is a bug! Please, open an issue in the PyTorch/XLA GitHub repository: https://github.com/pytorch/xla
Status Error: Expected all tensors in the given list to be XLA tensors. Element at index 0 is not an XLA tensor. Got: CPUFloatType
*** Check failure stack trace: ***
    @     0x7497ef2a1159  absl::lts_20230802::log_internal::LogMessageFatal::~LogMessageFatal()
    @     0x7497e3b6bdb8  torch_xla::(anonymous namespace)::InitXlaModuleBindings()::{lambda()#172}::operator()()
    @     0x7497e4225946  pybind11::cpp_function::initialize<>()::{lambda()#3}::_FUN()
    @     0x7497e4204f51  pybind11::cpp_function::dispatcher()
    @     0x74998357aa2e  cfunction_call
Aborted (core dumped)

#################################################################
# After this PR
F0000 00:00:1754593291.250543   19765 init_python_bindings.cpp:3380] Check failed: xtensors_status.ok()

Internal Error:
    _get_graph_hash(): error retrieving the XLA tensors from the given tensor arguments. This is a bug! Please, open an issue in the PyTorch/XLA GitHub repository: https://github.com/pytorch/xla

Status Error:
    Expected all tensors in the given list to be XLA tensors. Element at index 0 is not an XLA tensor. Got: CPUFloatType

*** Check failure stack trace: ***
    @     0x7d80ecea7059  absl::lts_20230802::log_internal::LogMessageFatal::~LogMessageFatal()
    @     0x7d80e176bd76  torch_xla::(anonymous namespace)::InitXlaModuleBindings()::{lambda()#172}::operator()()
    @     0x7d80e1e25276  pybind11::cpp_function::initialize<>()::{lambda()#3}::_FUN()
    @     0x7d80e1e04891  pybind11::cpp_function::dispatcher()
    @     0x7d82acf59a2e  cfunction_call
Aborted (core dumped)

TORCH_SHOW_CPP_STACKTRACES=1

#################################################################
# Before this PR
F0000 00:00:1754594644.896688   30382 init_python_bindings.cpp:3380] Check failed: xtensors_status.ok() _get_graph_hash(): error retrieving the XLA tensors from the given tensor arguments. This is a bug! Please, open an issue in the PyTorch/XLA GitHub repository: https://github.com/pytorch/xla
Status Error: Expected all tensors in the given list to be XLA tensors. Element at index 0 is not an XLA tensor. Got: CPUFloatType

Status Propagation Trace:
    From: GetXlaTensorImpl at torch_xla/csrc/aten_xla_bridge.cpp:88 (error: Failed retrieving the inner XLATensorImpl* from CPUFloatType. It's likely that `tensor` is not an actual XLA tensor, i.e. it wasn't created inside PyTorch/XLA.)
    From: GetXlaTensor at torch_xla/csrc/aten_xla_bridge.cpp:106 (error: Expected XLA tensor. Got: CPUFloatType)
    From: GetXlaTensors at torch_xla/csrc/aten_xla_bridge.cpp:118 (error: Expected all tensors in the given list to be XLA tensors. Element at index 0 is not an XLA tensor. Got: CPUFloatType)

*** Check failure stack trace: ***
    @     0x788d52ca1159  absl::lts_20230802::log_internal::LogMessageFatal::~LogMessageFatal()
    @     0x788d4756bdb8  torch_xla::(anonymous namespace)::InitXlaModuleBindings()::{lambda()#172}::operator()()
    @     0x788d47c25946  pybind11::cpp_function::initialize<>()::{lambda()#3}::_FUN()
    @     0x788d47c04f51  pybind11::cpp_function::dispatcher()
    @     0x788ee6f96a2e  cfunction_call
Aborted (core dumped)

#################################################################
# After this PR
F0000 00:00:1754593329.264671   19813 init_python_bindings.cpp:3380] Check failed: xtensors_status.ok()

Internal Error:
    _get_graph_hash(): error retrieving the XLA tensors from the given tensor arguments. This is a bug! Please, open an issue in the PyTorch/XLA GitHub repository: https://github.com/pytorch/xla

Status Error:
    Expected all tensors in the given list to be XLA tensors. Element at index 0 is not an XLA tensor. Got: CPUFloatType

Status Propagation Trace:
    From: GetXlaTensorImpl at torch_xla/csrc/aten_xla_bridge.cpp:88 (error: Failed retrieving the inner XLATensorImpl* from CPUFloatType. It's likely that `tensor` is not an actual XLA tensor, i.e. it wasn't created inside PyTorch/XLA.)
    From: GetXlaTensor at torch_xla/csrc/aten_xla_bridge.cpp:106 (error: Expected XLA tensor. Got: CPUFloatType)
    From: GetXlaTensors at torch_xla/csrc/aten_xla_bridge.cpp:118 (error: Expected all tensors in the given list to be XLA tensors. Element at index 0 is not an XLA tensor. Got: CPUFloatType)

*** Check failure stack trace: ***
    @     0x73a6bcea7059  absl::lts_20230802::log_internal::LogMessageFatal::~LogMessageFatal()
    @     0x73a6b176bd76  torch_xla::(anonymous namespace)::InitXlaModuleBindings()::{lambda()#172}::operator()()
    @     0x73a6b1e25276  pybind11::cpp_function::initialize<>()::{lambda()#3}::_FUN()
    @     0x73a6b1e04891  pybind11::cpp_function::dispatcher()
    @     0x73a86de37a2e  cfunction_call
Aborted (core dumped)

@ysiraichi ysiraichi force-pushed the ysiraichi/refactor-status-message-builder branch from c00a83b to 0d5dc69 Compare August 7, 2025 19:29
Copy link
Collaborator

@zhanyong-wan zhanyong-wan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ysiraichi ysiraichi merged commit 57cd41c into master Aug 8, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants