Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3f125b6
Update `sorted_vector_map`
JakobDegen May 8, 2024
25214d4
Use compile-time promotion to reduce max/min size & build time (#3459)
swolchok May 8, 2024
a2e1310
Use compile-time promotion to reduce floor_divide size & build time (…
swolchok May 8, 2024
ad33982
Use compile-time promotion to reduce remainder size & build time (#3458)
swolchok May 8, 2024
5c05def
Use compile-time promotion to reduce fmod size & build time (#3456)
swolchok May 8, 2024
7841e96
support Half in minimum and clamp (#3457)
swolchok May 8, 2024
c8f306d
Stylize struct members with snake_case (#3545)
May 8, 2024
2d68bd3
Rename `Allocator.*` as `vma_api.*` (#3552)
May 8, 2024
f8403ed
Error out when token is outside of vocab size (#3535)
cccclai May 9, 2024
dd81fc7
Fix backend/arm tests failing when there is no tosa installed (#3560)
zingo May 9, 2024
fff20a7
Update pytorch pin (#3562)
mergennachin May 9, 2024
21f5fbf
Catch check on symbolic shapes (#3537)
angelayi May 9, 2024
38c30d6
use utils:{min,max}_override in {min,max}imum ops (#3453)
swolchok May 9, 2024
8ebe1c9
Use compile-time promotion to reduce bitwise op size & build time (#3…
swolchok May 9, 2024
5adc8bf
Use compile-time promotion to reduce optimized mul op size & build ti…
swolchok May 9, 2024
a4110e0
Use compile-time promotion to reduce optimized add/sub op size & buil…
swolchok May 9, 2024
b3c3e65
Use compile-time promotion to reduce optimized le op size & build tim…
swolchok May 9, 2024
cc11541
make extract_delegate_segments=True by default (#3405)
May 9, 2024
edaae14
Split `Resource.h` into multiple files within `memory/` (#3553)
May 9, 2024
f6f881a
Remove unneeded `api::` prefix within `namespace api` (#3554)
May 9, 2024
ebdb152
Save and load VkPipelineCache data if path is specified (#3546)
May 9, 2024
cc2d3b5
Revise memory monitor to align with Xcode metrics (#3131)
May 9, 2024
2ac7f2a
Add support for method level executorch backend config (#3266)
tarun292 May 9, 2024
6c56122
Break flag bc (#3128)
mcr229 May 9, 2024
8a63430
add per-channel tests for linear (#3551)
mcr229 May 9, 2024
0563aa7
Disable view_copy elimination for graph outputs (#3565)
mcremon-meta May 9, 2024
749f6ab
Rust: Update sysinfo crate (#3520)
May 9, 2024
c83af25
Add target_link_options_shared_lib to coremldelegate build (#3556)
swolchok May 10, 2024
8e2e2e2
explicitly import _export.exported_program. (#3574)
zhxchen17 May 10, 2024
1871ec1
min pip version (#3526)
lucylq May 10, 2024
b93b7ae
Change custom_skip_targets meaning for constant_prop_pass (#3491)
dulinriley May 10, 2024
60fa0d3
build and upload aar (#3381)
kirklandsign May 10, 2024
43bfcd2
Batch norm (#3569)
yipjustin May 10, 2024
60c94e8
gelu (#3573)
copyrightly May 11, 2024
629b112
Cadence - refactor quantizer and passes (#3539)
mcremon-meta May 13, 2024
9db0a69
Simplify gen_oplist_copy_from_core file (#3549)
mergennachin May 13, 2024
c229e7b
Update README.md with correct link (#3591)
mergennachin May 13, 2024
a88a78d
Separate mm and addmm into separate implementation files + cleanup (#…
SS-JIA May 13, 2024
e288039
Comment out memory planning log (#3581)
lucylq May 13, 2024
87d828a
don't partition max pool with ceil mode (#3578)
mcr229 May 13, 2024
4b5e434
Reuse the existing clone of the ios toolchain for Core ML. (#3575)
shoumikhin May 13, 2024
ea9647f
Add support for slice_scatter; enable index_put (#3399)
DenisVieriu97 May 13, 2024
ebe701e
Install mpmath in pip installation (#3593)
mergennachin May 13, 2024
c853b3c
Add base for sgd optimizer (#3496)
May 13, 2024
c69861d
Ease Core ML partitioner and quantizer imports. (#3564)
shoumikhin May 13, 2024
01ce72c
Fix includes in Core ML backend. (#3603)
shoumikhin May 14, 2024
b64182d
Fix memory.view insertion except for output nodes (#3602)
dulinriley May 14, 2024
e8a520c
Fix headers search paths for nlohmann json in Core ML. (#3607)
shoumikhin May 14, 2024
0e7955d
Implement `aten.linear.default` (#3594)
SS-JIA May 14, 2024
39f9c0f
temporary disable dim order ops in executorch/examples to mitigate os…
Gasoonjia May 14, 2024
aaa2f2e
Add a way to run c++ unittest on OSS (#3606)
kirklandsign May 15, 2024
fb24c9d
Fix headers search paths for nlohmann json in Core ML. (#3614)
shoumikhin May 15, 2024
99ec946
Add typed-arena to oss shim (#3576)
cjhopman May 15, 2024
c2bc810
Update .gitmodules
dijopaul May 15, 2024
82e159e
adding nnlib repo
dijopaul May 15, 2024
6dfda8d
Update .gitmodules
dijopaul May 16, 2024
8cc2bd8
Adding build support for nnlib
dijopaul May 16, 2024
2ec6046
Adding cmakelist changes to link nnlib
dijopaul May 17, 2024
2da285e
Adding CFLAG updates
dijopaul May 22, 2024
5ad8ab0
Adding quantizer and dequantizer from nnlib
dijopaul May 28, 2024
6b6b80b
Moving nnlib obj and lib files to cmake build dir
dijopaul May 29, 2024
460e821
Merge branch 'dijopaul_add-nnlib' of https://github.com/dijopaul/exec…
dijopaul May 29, 2024
3328646
Clean up quantize and dequantize
dijopaul May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support Half in minimum and clamp (pytorch#3457)
Summary:
Pull Request resolved: pytorch#3457

IIUC, these ops need to support Half but don't. Noticed it as a difference from maximum.

Reviewed By: manuelcandales

Differential Revision: D56846242

fbshipit-source-id: 6b5f85ee77ac6078ae2e82ad1f1944c5d5104340
  • Loading branch information
swolchok authored and facebook-github-bot committed May 8, 2024
commit 7841e96c7a37e82fd2d8aad037093f9d4d1068ee
18 changes: 9 additions & 9 deletions kernels/portable/cpu/op_clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ __ET_NODISCARD bool check_bounds(
}
});
} else if (isFloatingType(out_type)) {
ET_SWITCH_FLOAT_TYPES(out_type, ctx, "clamp", CTYPE_OUT, [&]() {
ET_SWITCH_FLOATH_TYPES(out_type, ctx, "clamp", CTYPE_OUT, [&]() {
if (std::isfinite(val) &&
is_out_of_bounds<CTYPE_VAL, CTYPE_OUT, double>(val)) {
ET_LOG(Error, "%s value out of bounds", val_name);
Expand Down Expand Up @@ -119,7 +119,7 @@ Tensor& clamp_out(

ET_KERNEL_CHECK(ctx, common_type == out_type, InvalidArgument, out);

ET_SWITCH_REAL_TYPES(out_type, ctx, "clamp", CTYPE_OUT, [&]() {
ET_SWITCH_REALH_TYPES(out_type, ctx, "clamp", CTYPE_OUT, [&]() {
// Extract optional min value
CTYPE_OUT min = 0;
if (has_min) {
Expand All @@ -140,7 +140,7 @@ Tensor& clamp_out(
});
}

ET_SWITCH_REAL_TYPES_AND(Bool, in_type, ctx, "clamp", CTYPE_IN, [&]() {
ET_SWITCH_REALHB_TYPES(in_type, ctx, "clamp", CTYPE_IN, [&]() {
apply_unary_map_fn(
[has_min, min, has_max, max](const CTYPE_IN val_in) {
CTYPE_OUT val_out = static_cast<CTYPE_OUT>(val_in);
Expand Down Expand Up @@ -195,20 +195,20 @@ Tensor& clamp_tensor_out(
ScalarType out_type = out.scalar_type();

if (has_min) {
common_type = promoteTypes(common_type, min_type);
common_type = promoteTypes(common_type, min_type, /*half_to_float*/ true);
}
if (has_max) {
common_type = promoteTypes(common_type, max_type);
common_type = promoteTypes(common_type, max_type, /*half_to_float*/ true);
}

ET_KERNEL_CHECK(ctx, canCast(common_type, out_type), InvalidArgument, out);

constexpr auto name = "clamp.Tensor_out";

ET_SWITCH_REALB_TYPES(in_type, ctx, name, CTYPE_IN, [&]() {
ET_SWITCH_REALB_TYPES(min_type, ctx, name, CTYPE_MIN, [&]() {
ET_SWITCH_REALB_TYPES(max_type, ctx, name, CTYPE_MAX, [&]() {
ET_SWITCH_REALB_TYPES(out_type, ctx, name, CTYPE_OUT, [&]() {
ET_SWITCH_REALHB_TYPES(in_type, ctx, name, CTYPE_IN, [&]() {
ET_SWITCH_REALHB_TYPES(min_type, ctx, name, CTYPE_MIN, [&]() {
ET_SWITCH_REALHB_TYPES(max_type, ctx, name, CTYPE_MAX, [&]() {
ET_SWITCH_REALHB_TYPES(out_type, ctx, name, CTYPE_OUT, [&]() {
apply_ternary_elementwise_fn<
CTYPE_IN,
CTYPE_MIN,
Expand Down
27 changes: 13 additions & 14 deletions kernels/portable/cpu/op_minimum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,24 @@ Tensor& minimum_out(

ScalarType a_type = a.scalar_type();
ScalarType b_type = b.scalar_type();
ScalarType common_type = promoteTypes(a_type, b_type);
ScalarType common_type = promoteTypes(a_type, b_type, /*half_to_float*/ true);
ScalarType out_type = out.scalar_type();

ET_KERNEL_CHECK(ctx, canCast(common_type, out_type), InvalidArgument, out);

ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, "minimum.out", CTYPE_A, [&]() {
ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, "minimum.out", CTYPE_B, [&]() {
using CTYPE_IN =
typename torch::executor::promote_types<CTYPE_A, CTYPE_B>::type;
ET_SWITCH_REALHB_TYPES(a_type, ctx, "minimum.out", CTYPE_A, [&]() {
ET_SWITCH_REALHB_TYPES(b_type, ctx, "minimum.out", CTYPE_B, [&]() {
using CTYPE_IN = typename torch::executor::
promote_types<CTYPE_A, CTYPE_B, /*half_to_float*/ true>::type;
ET_DCHECK(CppTypeToScalarType<CTYPE_IN>::value == common_type);
ET_SWITCH_REAL_TYPES_AND(
Bool, out_type, ctx, "minimum.out", CTYPE_OUT, [&]() {
MinimumInner<
can_cast<CTYPE_IN, CTYPE_OUT>::value,
CTYPE_A,
CTYPE_B,
CTYPE_IN,
CTYPE_OUT>::run(a, b, out);
});
ET_SWITCH_REALHB_TYPES(out_type, ctx, "minimum.out", CTYPE_OUT, [&]() {
MinimumInner<
can_cast<CTYPE_IN, CTYPE_OUT>::value,
CTYPE_A,
CTYPE_B,
CTYPE_IN,
CTYPE_OUT>::run(a, b, out);
});
});
});

Expand Down
42 changes: 42 additions & 0 deletions kernels/portable/cpu/util/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,48 @@ INT_T max_override(INT_T a, INT_T b) {
return std::max(a, b);
}

template <
typename T,
typename std::enable_if<
std::is_same<T, torch::executor::Half>::value,
bool>::type = true>
T min_override(T a, T b) {
const auto float_a = static_cast<float>(a);
if (std::isnan(float_a)) {
return a;
}
const auto float_b = static_cast<float>(b);
if (std::isnan(float_b)) {
return b;
}

if (float_a < float_b) {
return a;
}
return b;
}

template <
typename T,
typename std::enable_if<
std::is_same<T, torch::executor::Half>::value,
bool>::type = true>
T max_override(T a, T b) {
const auto float_a = static_cast<float>(a);
if (std::isnan(float_a)) {
return a;
}
const auto float_b = static_cast<float>(b);
if (std::isnan(float_b)) {
return b;
}

if (float_a > float_b) {
return a;
}
return b;
}

/**
* There is a slight difference in how std::fmod works compared to how ATen
* determines remainders:
Expand Down
25 changes: 21 additions & 4 deletions kernels/test/op_clamp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ class OpClampOutTest : public OperatorTest {
// Test cases that are compatible with float and double.
template <ScalarType DTYPE>
void run_floating_point_test_cases() {
constexpr auto kInfinity =
std::numeric_limits<typename TensorFactory<DTYPE>::ctype>::infinity();
using ctype = typename TensorFactory<DTYPE>::ctype;
using opt_infinity_type = std::conditional_t<
std::is_same<ctype, exec_aten::Half>::value,
float,
ctype>;
constexpr auto kInfinity = std::numeric_limits<ctype>::infinity();
const auto kOptInfinity =
OptScalar(static_cast<opt_infinity_type>(kInfinity));
const auto kOptMinusInfinity =
OptScalar(static_cast<opt_infinity_type>(-kInfinity));
std::vector<ClampTestCase<DTYPE>> test_cases = {
{
std::string(__func__) + ": Simple negative/positive clamp",
Expand Down Expand Up @@ -178,7 +186,7 @@ class OpClampOutTest : public OperatorTest {
std::string(__func__) + ": Infinite min",
{2, 2}, // sizes
{-10.1, -1.1, 1.1, 10.1}, // input_data
OptScalar(-kInfinity), // min
kOptMinusInfinity, // min
OptScalar(5.5), // max
{-10.1, -1.1, 1.1, 5.5}, // expected_data
},
Expand All @@ -187,7 +195,7 @@ class OpClampOutTest : public OperatorTest {
{2, 2}, // sizes
{-10.1, -1.1, 1.1, 10.1}, // input_data
OptScalar(-5.5), // min
OptScalar(kInfinity), // max
kOptInfinity, // max
{-5.5, -1.1, 1.1, 10.1}, // expected_data
},
{
Expand Down Expand Up @@ -285,6 +293,15 @@ TEST_F(OpClampOutTest, LongTensors) {
run_signed_integer_test_cases<ScalarType::Long>();
}

TEST_F(OpClampOutTest, HalfTensors) {
// Note that the integer test cases test the situation where the min/max value
// Scalars are integer types, demonstrating that floating point types can be
// clamped to integer values.
run_unsigned_integer_test_cases<ScalarType::Half>();
run_signed_integer_test_cases<ScalarType::Half>();
run_floating_point_test_cases<ScalarType::Half>();
}

TEST_F(OpClampOutTest, FloatTensors) {
// Note that the integer test cases test the situation where the min/max value
// Scalars are integer types, demonstrating that floating point types can be
Expand Down
4 changes: 4 additions & 0 deletions kernels/test/op_minimum_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ TEST_F(OpMinimumOutTest, LongTensors) {
test_minimum_out_same_size<ScalarType::Long>();
}

TEST_F(OpMinimumOutTest, HalfTensors) {
test_minimum_out_same_size<ScalarType::Half>();
}

TEST_F(OpMinimumOutTest, FloatTensors) {
test_minimum_out_same_size<ScalarType::Float>();
}
Expand Down