diff --git a/kernels/portable/cpu/util/activation_ops_util.cpp b/kernels/portable/cpu/util/activation_ops_util.cpp index 195ffaf66d2..908758a2e36 100644 --- a/kernels/portable/cpu/util/activation_ops_util.cpp +++ b/kernels/portable/cpu/util/activation_ops_util.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace torch { namespace executor { @@ -45,9 +46,22 @@ bool check_glu_args(const Tensor& in, int64_t dim, Tensor& out) { for (size_t i = 0; i < in.dim(); ++i) { if (i != non_negative_dim) { - ET_LOG_MSG_AND_RETURN_IF_FALSE( - out.size(i) == in.size(i), - "output tensor must have the same size as the input tensor in all dimensions except for the specified dimension."); + if (out.size(i) != in.size(i)) { +#if ET_LOG_ENABLED + auto out_shape_str = executorch::runtime::tensor_shape_to_c_string( + executorch::runtime::Span( + out.sizes().data(), out.sizes().size())); + auto in_shape_str = executorch::runtime::tensor_shape_to_c_string( + executorch::runtime::Span( + in.sizes().data(), in.sizes().size())); + ET_LOG( + Error, + "output tensor must have the same size as the input tensor in all dimensions except for the specified dimension. (output shape: %s input shape: %s)", + out_shape_str.data(), + in_shape_str.data()); +#endif // ET_LOG_ENABLED + return false; + } } } diff --git a/kernels/portable/cpu/util/targets.bzl b/kernels/portable/cpu/util/targets.bzl index 2c25d171568..26f55a91e8d 100644 --- a/kernels/portable/cpu/util/targets.bzl +++ b/kernels/portable/cpu/util/targets.bzl @@ -44,6 +44,7 @@ def define_common_targets(): ], compiler_flags = ["-Wno-missing-prototypes"], deps = [ + "//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string", "//executorch/runtime/kernel:kernel_includes", ], visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/optimized/cpu/..."],