Skip to content

Commit 99afd2c

Browse files
malfetclaude
andauthored
Skip ATen-mode out-of-range integer clamp/hardtanh death tests (pytorch#21933)
pytorch/pytorch#193169 changes how ATen's scalar `clamp` handles an out-of-range integer bound. Instead of converting the bound straight to the input dtype (which raised for signed dtypes and silently wrapped for unsigned ones), ATen now reconciles the bound by direction: a `min` below the dtype's range (or a `max` above it) is a no-op and is dropped, while the opposite direction is rejected. `hardtanh` shares this behavior. The portable kernels keep their own strict bounds check and are unaffected, but the ATen-mode death tests (built with -DUSE_ATEN_LIB) assume every out-of-range integer bound raises, which no longer holds. Skip those integer cases in ATen mode, matching the existing skips for negative uint8 and out-of-range int32 bounds: - op_clamp_test: ByteTensorTooLargeClampDies - op_hardtanh_test: ByteTensorTooLargeScalarDies, CharTensorTooSmallScalarDies, ShortTensorTooLargeScalarDies (gated in the fixture helper, not the shared ScalarOverflowTestMacros.h, which eight suites depend on) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> ### Summary [PLEASE REMOVE] See [CONTRIBUTING.md's Pull Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#pull-requests) for ExecuTorch PR guidelines. [PLEASE REMOVE] If this PR closes an issue, please add a `Fixes #<issue-id>` line. [PLEASE REMOVE] If this PR introduces a fix or feature that should be the upcoming release notes, please add a "Release notes: <area>" label. For a list of available release notes labels, check out [CONTRIBUTING.md's Pull Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#pull-requests). ### Test plan [PLEASE REMOVE] How did you test this PR? Please write down any manual commands you used and note down tests that you have written if applicable. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1c64a66 commit 99afd2c

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎kernels/test/op_clamp_test.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ TEST_F(OpClampOutTest, ByteTensorNegativeClampDies) {
368368
}
369369

370370
TEST_F(OpClampOutTest, ByteTensorTooLargeClampDies) {
371+
ET_SKIP_IF(
372+
torch::executor::testing::SupportedFeatures::get()->is_aten,
373+
"ATen kernel treats an out-of-range integer clamp bound as a no-op or an "
374+
"error depending on direction");
371375
// Cannot be represented by a uint8_t.
372376
expect_bad_clamp_value_dies<ScalarType::Byte>(256);
373377
}

‎kernels/test/op_hardtanh_test.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
#include <executorch/kernels/test/FunctionHeaderWrapper.h> // Declares the operator
1010
#include <executorch/kernels/test/ScalarOverflowTestMacros.h>
1111
#include <executorch/kernels/test/TestUtil.h>
12+
#include <executorch/kernels/test/supported_features.h>
13+
#include <executorch/kernels/test/supported_features_skip.h>
1214
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1315
#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h>
1416
#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h>
17+
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
1518

1619
#include <gtest/gtest.h>
1720

@@ -55,6 +58,16 @@ class OpHardTanhTest : public OperatorTest {
5558

5659
template <ScalarType DTYPE>
5760
void expect_bad_scalar_value_dies(const Scalar& bad_value) {
61+
if constexpr (executorch::runtime::isIntegralType(
62+
DTYPE, /*includeBool=*/false)) {
63+
// ATen treats an out-of-range integer hardtanh bound as a no-op or an
64+
// error depending on direction, so the death test no longer holds.
65+
ET_SKIP_IF(
66+
torch::executor::testing::SupportedFeatures::get()->is_aten,
67+
"ATen kernel treats out-of-range integer hardtanh bounds by "
68+
"direction (no-op or error)");
69+
}
70+
5871
TensorFactory<DTYPE> tf;
5972
Tensor in = tf.ones({2, 2});
6073
Tensor out = tf.zeros({2, 2});

0 commit comments

Comments
 (0)