Skip to content

Commit 6c2529a

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Log EValue tag names instead of numeric values
Summary: Update error log messages that include EValue tags to use a string representation of the tag rather than the numerical index. This improves readability for users. Example Old Message: ``` [method.cpp:814] The 0-th input of method should have the same type as the input_evalue, but get tag 1 and tag 4 ``` Example New Message: ``` [method.cpp:813] Input 0 was expected to be Tensor but was Int. ``` Differential Revision: D67888756
1 parent a29dc49 commit 6c2529a

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

runtime/core/evalue.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,15 @@ BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const {
2727
return exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>{
2828
unwrapped_vals_, wrapped_vals_.size()};
2929
}
30+
31+
const char* tag_to_string(Tag tag) {
32+
switch (tag) {
33+
#define TAG_CASE(x) case Tag::x: return #x;
34+
EXECUTORCH_FORALL_TAGS(TAG_CASE)
35+
#undef TAG_CASE
36+
default: return "";
37+
}
38+
}
39+
3040
} // namespace runtime
3141
} // namespace executorch

runtime/core/evalue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ executorch::aten::ArrayRef<T> BoxedEvalueList<T>::get() const {
550550
return executorch::aten::ArrayRef<T>{unwrapped_vals_, wrapped_vals_.size()};
551551
}
552552

553+
const char* tag_to_string(Tag tag);
554+
553555
} // namespace runtime
554556
} // namespace executorch
555557

runtime/executor/method.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -792,26 +792,25 @@ Method::set_input(const EValue& input_evalue, size_t input_idx) {
792792
ET_CHECK_OR_RETURN_ERROR(
793793
input_idx < inputs_size(),
794794
InvalidArgument,
795-
"Given input index must be less than the number of inputs in method, but got %zu and %zu",
795+
"Input index (%zu) must be less than the number of inputs in method (%zu).",
796796
input_idx,
797797
inputs_size());
798798

799799
const auto& e = get_value(get_input_index(input_idx));
800800
ET_CHECK_OR_RETURN_ERROR(
801801
e.isTensor() || e.isScalar(),
802802
InvalidArgument,
803-
"The %zu-th input in method is expected Tensor or prim, but received %" PRIu32,
803+
"Input %zu was expected to be a Tensor or primitive but was %s.",
804804
input_idx,
805-
static_cast<uint32_t>(e.tag));
805+
tag_to_string(e.tag));
806806

807807
ET_CHECK_OR_RETURN_ERROR(
808808
e.tag == input_evalue.tag,
809809
InvalidArgument,
810-
"The %zu-th input of method should have the same type as the input_evalue, but get tag %" PRIu32
811-
" and tag %" PRIu32,
810+
"Input %zu was expected to be %s but was %s.",
812811
input_idx,
813-
static_cast<uint32_t>(e.tag),
814-
static_cast<uint32_t>(input_evalue.tag));
812+
tag_to_string(e.tag),
813+
tag_to_string(input_evalue.tag));
815814

816815
if (e.isTensor()) {
817816
const auto& t_dst = e.toTensor();
@@ -901,7 +900,7 @@ Method::set_input(const EValue& input_evalue, size_t input_idx) {
901900
e.toString().data(),
902901
input_evalue.toString().data());
903902
} else {
904-
ET_LOG(Error, "Unsupported input type: %d", (int32_t)e.tag);
903+
ET_LOG(Error, "Unsupported input type: %s", tag_to_string(e.tag));
905904
return Error::InvalidArgument;
906905
}
907906
return Error::Ok;
@@ -956,8 +955,8 @@ Method::set_output_data_ptr(void* buffer, size_t size, size_t output_idx) {
956955
ET_CHECK_OR_RETURN_ERROR(
957956
output.isTensor(),
958957
InvalidArgument,
959-
"output type: %zu is not tensor",
960-
(size_t)output.tag);
958+
"output type: %s is not tensor",
959+
tag_to_string(output.tag));
961960

962961
auto tensor_meta = this->method_meta().output_tensor_meta(output_idx);
963962
if (tensor_meta->is_memory_planned()) {
@@ -973,8 +972,8 @@ Method::set_output_data_ptr(void* buffer, size_t size, size_t output_idx) {
973972
ET_CHECK_OR_RETURN_ERROR(
974973
output.isTensor(),
975974
InvalidArgument,
976-
"output type: %zu is not tensor",
977-
(size_t)output.tag);
975+
"output type: %s is not tensor",
976+
tag_to_string(output.tag));
978977
ET_CHECK_OR_RETURN_ERROR(
979978
t.nbytes() <= size,
980979
InvalidArgument,

0 commit comments

Comments
 (0)