Skip to content

Commit

Permalink
Log EValue tag names instead of numeric values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GregoryComer authored and facebook-github-bot committed Jan 7, 2025
1 parent a29dc49 commit 6c2529a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
10 changes: 10 additions & 0 deletions runtime/core/evalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const {
return exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>{
unwrapped_vals_, wrapped_vals_.size()};
}

const char* tag_to_string(Tag tag) {
switch (tag) {
#define TAG_CASE(x) case Tag::x: return #x;
EXECUTORCH_FORALL_TAGS(TAG_CASE)
#undef TAG_CASE
default: return "";
}
}

} // namespace runtime
} // namespace executorch
2 changes: 2 additions & 0 deletions runtime/core/evalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ executorch::aten::ArrayRef<T> BoxedEvalueList<T>::get() const {
return executorch::aten::ArrayRef<T>{unwrapped_vals_, wrapped_vals_.size()};
}

const char* tag_to_string(Tag tag);

} // namespace runtime
} // namespace executorch

Expand Down
23 changes: 11 additions & 12 deletions runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,26 +792,25 @@ Method::set_input(const EValue& input_evalue, size_t input_idx) {
ET_CHECK_OR_RETURN_ERROR(
input_idx < inputs_size(),
InvalidArgument,
"Given input index must be less than the number of inputs in method, but got %zu and %zu",
"Input index (%zu) must be less than the number of inputs in method (%zu).",
input_idx,
inputs_size());

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

ET_CHECK_OR_RETURN_ERROR(
e.tag == input_evalue.tag,
InvalidArgument,
"The %zu-th input of method should have the same type as the input_evalue, but get tag %" PRIu32
" and tag %" PRIu32,
"Input %zu was expected to be %s but was %s.",
input_idx,
static_cast<uint32_t>(e.tag),
static_cast<uint32_t>(input_evalue.tag));
tag_to_string(e.tag),
tag_to_string(input_evalue.tag));

if (e.isTensor()) {
const auto& t_dst = e.toTensor();
Expand Down Expand Up @@ -901,7 +900,7 @@ Method::set_input(const EValue& input_evalue, size_t input_idx) {
e.toString().data(),
input_evalue.toString().data());
} else {
ET_LOG(Error, "Unsupported input type: %d", (int32_t)e.tag);
ET_LOG(Error, "Unsupported input type: %s", tag_to_string(e.tag));
return Error::InvalidArgument;
}
return Error::Ok;
Expand Down Expand Up @@ -956,8 +955,8 @@ Method::set_output_data_ptr(void* buffer, size_t size, size_t output_idx) {
ET_CHECK_OR_RETURN_ERROR(
output.isTensor(),
InvalidArgument,
"output type: %zu is not tensor",
(size_t)output.tag);
"output type: %s is not tensor",
tag_to_string(output.tag));

auto tensor_meta = this->method_meta().output_tensor_meta(output_idx);
if (tensor_meta->is_memory_planned()) {
Expand All @@ -973,8 +972,8 @@ Method::set_output_data_ptr(void* buffer, size_t size, size_t output_idx) {
ET_CHECK_OR_RETURN_ERROR(
output.isTensor(),
InvalidArgument,
"output type: %zu is not tensor",
(size_t)output.tag);
"output type: %s is not tensor",
tag_to_string(output.tag));
ET_CHECK_OR_RETURN_ERROR(
t.nbytes() <= size,
InvalidArgument,
Expand Down

0 comments on commit 6c2529a

Please sign in to comment.