Skip to content

Commit 1264bfb

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Log dtype names on input dtype mismatch (#7537)
Summary: Update the error message when input tensor scalar type is incorrect. We've seen this get hit a few times and it should be easier to debug than it is. New Message: ``` [method.cpp:825] Input 0 has unexpected scalar type: expected Byte but was Float. ``` Old Message: ``` [method.cpp:826] The 0-th input tensor's scalartype does not meet requirement: found 0 but expected 6 ``` Test Plan: Built executorch bento kernel locally and tested with an incorrect scalar type to view the new error message. ``` [method.cpp:825] Input 0 has unexpected scalar type: expected Byte but was Float. ``` Reviewed By: digantdesai Differential Revision: D67887770 Pulled By: GregoryComer
1 parent a29b208 commit 1264bfb

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
2+
3+
namespace executorch {
4+
namespace runtime {
5+
6+
const char* scalar_type_to_string(::executorch::aten::ScalarType t) {
7+
#define DEFINE_CASE(unused, name) \
8+
case ::executorch::aten::ScalarType::name: \
9+
return #name;
10+
11+
switch (t) {
12+
ET_FORALL_SCALAR_TYPES(DEFINE_CASE)
13+
default:
14+
return "Unknown";
15+
}
16+
17+
#undef DEFINE_CASE
18+
}
19+
20+
} // namespace runtime
21+
} // namespace executorch

runtime/core/exec_aten/util/scalar_type_util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,11 @@ struct promote_types {
12941294
CTYPE_ALIAS, \
12951295
__VA_ARGS__))
12961296

1297+
/**
1298+
* Return a string representation of a ScalarType value.
1299+
*/
1300+
const char* scalar_type_to_string(::executorch::aten::ScalarType t);
1301+
12971302
} // namespace runtime
12981303
} // namespace executorch
12991304

runtime/core/exec_aten/util/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def define_common_targets():
1919

2020
runtime.cxx_library(
2121
name = "scalar_type_util" + aten_suffix,
22-
srcs = [],
22+
srcs = ["scalar_type_util.cpp"],
2323
exported_headers = [
2424
"scalar_type_util.h",
2525
],

runtime/core/portable_type/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def define_common_targets():
4949
"scalar_type.h",
5050
"qint_types.h",
5151
"bits_types.h",
52+
"string_view.h",
5253
],
5354
visibility = [
5455
"//executorch/extension/...",

runtime/executor/method.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,10 @@ Method::set_input(const EValue& input_evalue, size_t input_idx) {
819819
ET_CHECK_OR_RETURN_ERROR(
820820
t_dst.scalar_type() == t_src.scalar_type(),
821821
InvalidArgument,
822-
"The %zu-th input tensor's scalartype does not meet requirement: found %" PRId8
823-
" but expected %" PRId8,
822+
"Input %zu has unexpected scalar type: expected %s but was %s.",
824823
input_idx,
825-
static_cast<int8_t>(t_src.scalar_type()),
826-
static_cast<int8_t>(t_dst.scalar_type()));
824+
scalar_type_to_string(t_src.scalar_type()),
825+
scalar_type_to_string(t_dst.scalar_type()));
827826
// Reset the shape for the Method's input as the size of forwarded input
828827
// tensor for shape dynamism. Also is a safety check if need memcpy.
829828
Error err = resize_tensor(t_dst, t_src.sizes());

runtime/executor/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def define_common_targets():
8282
"//executorch/runtime/core:evalue" + aten_suffix,
8383
"//executorch/runtime/core:event_tracer" + aten_suffix,
8484
"//executorch/runtime/core/exec_aten:lib" + aten_suffix,
85+
"//executorch/runtime/core/exec_aten/util:scalar_type_util" + aten_suffix,
8586
"//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
8687
"//executorch/runtime/kernel:kernel_runtime_context" + aten_suffix,
8788
"//executorch/runtime/kernel:operator_registry",

0 commit comments

Comments
 (0)