match torch clamp backward (#13533)

* match torch clamp backward

* fix PYTHON
This commit is contained in:
chenyu
2025-12-02 17:58:32 -05:00
committed by GitHub
parent 7622be761f
commit e8879f7e31
2 changed files with 5 additions and 2 deletions

View File

@@ -2729,6 +2729,9 @@ class TestOps(unittest.TestCase):
def test_clip(self):
helper_test_op([(45,65)], lambda x: x.clip(-2.3, 1.2))
# NOTE: torch set backward to 1 at the boundaries
# https://github.com/pytorch/pytorch/blob/7a41b66367c38d0af3e8a90f7be48d6b281e7bca/tools/autograd/derivatives.yaml#L421
helper_test_op(None, lambda x: x.clip(-2.5, 1.5), vals=[[-3.0, -2.5, 0, 1.5, 2]])
helper_test_op([(45,65)], lambda x: x.clip(0, 0))
helper_test_op([(45,65)], lambda x: x.clip(10, 100))
helper_test_op([(45,65)], lambda x: x.clip(0, 0.1))