[ROCm] fix hardsigmoid op (#162758)

Currently std::min -> ::min did not work as expected on ROCm when input values >= 2147483648
It can be fixed by explicit typing std::min<opmath_t>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/162758
Approved by: https://github.com/jeffdaily, https://github.com/pruthvistony

Co-authored-by: Jeff Daily <jeff.daily@amd.com>
This commit is contained in:
Jeff Daily
2025-09-12 15:07:13 +00:00
committed by PyTorch MergeBot
parent 7357eb66c5
commit 1e9ddf510f
2 changed files with 2 additions and 7 deletions

View File

@ -36,7 +36,7 @@ void hardsigmoid_kernel(TensorIteratorBase& iter) {
[zero, one_sixth, three, six] GPU_LAMBDA(
scalar_t self_val) -> scalar_t {
opmath_t x = static_cast<opmath_t>(self_val);
return std::min(std::max(x + three, zero), six) * one_sixth;
return std::min<opmath_t>(std::max<opmath_t>(x + three, zero), six) * one_sixth;
});
});
}

View File

@ -16593,12 +16593,7 @@ op_db: list[OpInfo] = [
toleranceOverride({torch.float16: tol(atol=1e-04, rtol=0.001)}), 'TestUnaryUfuncs', device_type='cuda',), ],
skips=[
# still want to test that first derivative works though second derivative isn't supported
DecorateInfo(unittest.expectedFailure, 'TestBwdGradients', "test_inplace_gradgrad"),
# produces 0 instead of nan on ROCM
DecorateInfo(unittest.expectedFailure,
'TestUnaryUfuncs', "test_reference_numerics_extremal",
device_type='cuda',
active_if=(TEST_WITH_ROCM)), ]
DecorateInfo(unittest.expectedFailure, 'TestBwdGradients', "test_inplace_gradgrad")]
),
UnaryUfuncInfo(
'nn.functional.logsigmoid',