From 5db5142204948c056421027adbd40262484ffe97 Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Mon, 13 Jan 2025 16:23:58 -0800 Subject: [PATCH] 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:834] Input 0 has unexpected scalar type: expected Float but was Byte. ``` 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:834] Input 0 has unexpected scalar type: expected Float but was Byte. ``` I also locally patched and built the bento kernel with ET_ENABLE_ENUM_STRINGS=0. ``` [method.cpp:834] Input 0 has unexpected scalar type: expected 6 but was 0. ``` Differential Revision: D67887770 Pulled By: GregoryComer --- runtime/executor/method.cpp | 8 ++++---- runtime/executor/targets.bzl | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 674af6d69f9..146c3640669 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -830,14 +830,14 @@ Method::set_input(const EValue& input_evalue, size_t input_idx) { if (e.isTensor()) { const auto& t_dst = e.toTensor(); const auto& t_src = input_evalue.toTensor(); + ET_CHECK_OR_RETURN_ERROR( t_dst.scalar_type() == t_src.scalar_type(), InvalidArgument, - "The %zu-th input tensor's scalartype does not meet requirement: found %" PRId8 - " but expected %" PRId8, + "Input %zu has unexpected scalar type: expected %s but was %s.", input_idx, - static_cast(t_src.scalar_type()), - static_cast(t_dst.scalar_type())); + executorch::runtime::toString(t_dst.scalar_type()), + executorch::runtime::toString(t_src.scalar_type())); // Reset the shape for the Method's input as the size of forwarded input // tensor for shape dynamism. Also is a safety check if need memcpy. Error err = resize_tensor(t_dst, t_src.sizes()); diff --git a/runtime/executor/targets.bzl b/runtime/executor/targets.bzl index cc91255d7b5..158da5d1087 100644 --- a/runtime/executor/targets.bzl +++ b/runtime/executor/targets.bzl @@ -82,6 +82,7 @@ def define_common_targets(): "//executorch/runtime/core:evalue" + aten_suffix, "//executorch/runtime/core:event_tracer" + aten_suffix, "//executorch/runtime/core/exec_aten:lib" + aten_suffix, + "//executorch/runtime/core/exec_aten/util:scalar_type_util" + aten_suffix, "//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix, "//executorch/runtime/kernel:kernel_runtime_context" + aten_suffix, "//executorch/runtime/kernel:operator_registry",