From 3972d7bb767f5979db46614c6581cad15f4fe36b Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 21 Nov 2024 13:19:19 -0800 Subject: [PATCH 1/2] Revert "[Executorch][Portable] Dont upcast to double for sigmoid" This reverts commit c242a59e5860fd1761fef7c379c69a06b6bfa910. Attempting to debug/fix #7019. --- kernels/portable/cpu/op_sigmoid.cpp | 36 ++++++++----------- .../kernels/portable/op_registration_util.bzl | 3 -- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/kernels/portable/cpu/op_sigmoid.cpp b/kernels/portable/cpu/op_sigmoid.cpp index 34b2ec60dec..84c4ea2f542 100644 --- a/kernels/portable/cpu/op_sigmoid.cpp +++ b/kernels/portable/cpu/op_sigmoid.cpp @@ -8,7 +8,6 @@ #include -#include #include #include @@ -36,26 +35,21 @@ Tensor& sigmoid_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) { out, "Failed to resize output tensor."); - ScalarType compute_type = - executorch::runtime::isFloatingType(in.scalar_type()) ? in.scalar_type() - : ScalarType::Float; - compute_type = utils::get_compute_type(compute_type); - - // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "sigmoid.out"; - - ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { - utils::apply_unitensor_elementwise_fn( - [](const CTYPE_COMPUTE val_in) { - CTYPE_COMPUTE out_val = static_cast(1.0) / - (static_cast(1.0) + exp(-val_in)); - return out_val; - }, - ctx, - in, - utils::SupportedTensorDtypes::REALHBBF16, - out, - utils::SupportedTensorDtypes::FLOATHBF16); + ScalarType in_type = in.scalar_type(); + ScalarType out_type = out.scalar_type(); + ET_SWITCH_REALHB_TYPES(in_type, ctx, "sigmoid.out", CTYPE_IN, [&]() { + ET_SWITCH_FLOATH_TYPES(out_type, ctx, "sigmoid.out", CTYPE_OUT, [&]() { + apply_unary_map_fn( + [](const CTYPE_IN val_in) { + // perform math in double to preserve precision + double in_casted = static_cast(val_in); + double out_val = 1.0 / (1.0 + exp(-in_casted)); + return static_cast(out_val); + }, + in.const_data_ptr(), + out.mutable_data_ptr(), + in.numel()); + }); }); return out; diff --git a/shim/xplat/executorch/kernels/portable/op_registration_util.bzl b/shim/xplat/executorch/kernels/portable/op_registration_util.bzl index 140a71cbfe8..ab8fc63a2af 100644 --- a/shim/xplat/executorch/kernels/portable/op_registration_util.bzl +++ b/shim/xplat/executorch/kernels/portable/op_registration_util.bzl @@ -1080,9 +1080,6 @@ ATEN_OPS = ( name = "op_sigmoid", deps = [ "//executorch/kernels/portable/cpu/util:functional_util", - "//executorch/kernels/portable/cpu/util:elementwise_util", - "//executorch/kernels/portable/cpu/util:broadcast_util", - "//executorch/kernels/portable/cpu/util:dtype_util", ], ), op_target( From fa6246b72f884a136d89a6180826524eff089557 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 21 Nov 2024 13:20:19 -0800 Subject: [PATCH 2/2] kick workflow --- .github/workflows/build-wheels-m1.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-wheels-m1.yml b/.github/workflows/build-wheels-m1.yml index 1dad6ad5ea1..32819058c90 100644 --- a/.github/workflows/build-wheels-m1.yml +++ b/.github/workflows/build-wheels-m1.yml @@ -1,4 +1,5 @@ # From https://github.com/pytorch/test-infra/wiki/Using-Nova-Reusable-Build-Workflows +# kick build name: Build M1 Wheels on: