From 031ac0945d2d7c7da1391c3660038337e2fbb224 Mon Sep 17 00:00:00 2001 From: VirdhatchaniKN Date: Wed, 17 Jul 2024 12:58:00 +0000 Subject: [PATCH] #9874: Remove clamp_min_bw --- docs/source/ttnn/ttnn/api.rst | 1 - docs/source/ttnn/ttnn/ttnn/clamp_min_bw.rst | 6 ---- .../backward/test_backward_clamp_min.py | 35 ------------------- .../device/unary_backward_op.cpp | 18 +++------- .../device/unary_backward_op.hpp | 1 - .../eltwise/unary_backward/unary_backward.hpp | 1 - .../unary_backward/unary_backward_pybind.hpp | 5 --- ttnn/ttnn/.rpath_checked__ttnn | 0 ttnn/ttnn/operations/unary_backward.py | 2 -- 9 files changed, 4 insertions(+), 65 deletions(-) delete mode 100644 docs/source/ttnn/ttnn/ttnn/clamp_min_bw.rst delete mode 100644 tests/ttnn/unit_tests/operations/backward/test_backward_clamp_min.py delete mode 100644 ttnn/ttnn/.rpath_checked__ttnn diff --git a/docs/source/ttnn/ttnn/api.rst b/docs/source/ttnn/ttnn/api.rst index a822394d7d6..c92850331b6 100644 --- a/docs/source/ttnn/ttnn/api.rst +++ b/docs/source/ttnn/ttnn/api.rst @@ -168,7 +168,6 @@ Pointwise Unary ttnn/tanhshrink ttnn/threshold ttnn/mul_bw - ttnn/clamp_min_bw ttnn/clamp_bw ttnn/hardtanh_bw ttnn/threshold_bw diff --git a/docs/source/ttnn/ttnn/ttnn/clamp_min_bw.rst b/docs/source/ttnn/ttnn/ttnn/clamp_min_bw.rst deleted file mode 100644 index 34d578c8495..00000000000 --- a/docs/source/ttnn/ttnn/ttnn/clamp_min_bw.rst +++ /dev/null @@ -1,6 +0,0 @@ -.. _ttnn.clamp_min_bw: - -ttnn.clamp_min_bw -################# - -.. autofunction:: ttnn.clamp_min_bw diff --git a/tests/ttnn/unit_tests/operations/backward/test_backward_clamp_min.py b/tests/ttnn/unit_tests/operations/backward/test_backward_clamp_min.py deleted file mode 100644 index b7249b9d0d6..00000000000 --- a/tests/ttnn/unit_tests/operations/backward/test_backward_clamp_min.py +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. - -# SPDX-License-Identifier: Apache-2.0 - -import torch -import pytest -import ttnn -from tests.ttnn.unit_tests.operations.backward.utility_funcs import data_gen_with_range, compare_pcc - - -@pytest.mark.parametrize( - "input_shapes", - ( - (torch.Size([1, 1, 32, 32])), - (torch.Size([1, 1, 320, 384])), - (torch.Size([1, 3, 320, 384])), - ), -) -@pytest.mark.parametrize("min", (-1.0, 1.0, 0.0, -0.5, -10.0, 10.0)) -def test_bw_clamp_min(input_shapes, min, device): - in_data, input_tensor = data_gen_with_range(input_shapes, -100, -1, device, True) - grad_data, grad_tensor = data_gen_with_range(input_shapes, -10, -1, device, True) - - pyt_y = torch.clamp(in_data, min=min) - - tt_output_tensor_on_device = ttnn.clamp_min_bw(grad_tensor, input_tensor, min) - - in_data.retain_grad() - - pyt_y.backward(gradient=grad_data) - - golden_tensor = [in_data.grad] - - comp_pass = compare_pcc(tt_output_tensor_on_device, golden_tensor) - assert comp_pass diff --git a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.cpp b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.cpp index c4925b8429b..e67cbcebc7b 100644 --- a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.cpp +++ b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.cpp @@ -29,24 +29,16 @@ std::vector _mul_bw( return grad_tensor; } -std::vector _clamp_min_bw( - const Tensor& grad, const Tensor& input, float min, const MemoryConfig& output_mem_config) { - std::vector grad_tensor; - Tensor minT = ttnn::ge(input, min, std::nullopt, output_mem_config); - Tensor result = ttnn::multiply(grad, minT, std::nullopt, output_mem_config); - grad_tensor.emplace_back(result); - return grad_tensor; -} - - - std::vector _clamp_bw( const Tensor& grad, const Tensor& input, std::optional min, std::optional max, const std::optional& output_mem_config) { std::vector grad_tensor; auto output_memory_config = output_mem_config.value_or(input.memory_config()); //TODO: Remove after ternary forward ops migration is completed TT_FATAL((max.has_value() || min.has_value()) && "Only one of 'min' or 'max' can be None. Please provide atleast one value"); if (!max.has_value()) { - return _clamp_min_bw( grad, input, min.value(), output_memory_config); + Tensor minT = ttnn::ge(input, min.value(), std::nullopt, output_mem_config); + Tensor result = ttnn::multiply(grad, minT, std::nullopt, output_mem_config); + grad_tensor.emplace_back(result); + return grad_tensor; }else if(!min.has_value()) { Tensor maxT = ttnn::le(input, max.value(), std::nullopt, output_mem_config); Tensor result = ttnn::multiply(grad, maxT, std::nullopt, output_mem_config); @@ -1726,8 +1718,6 @@ std::function(const Tensor&, const Tensor&, float, con switch (OpType) { case UnaryBackwardOpType::MUL_BW: return _mul_bw; - case UnaryBackwardOpType::CLAMP_MIN_BW: - return _clamp_min_bw; case UnaryBackwardOpType::ADD_BW: return _add_bw; case UnaryBackwardOpType::EQ_BW: diff --git a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.hpp b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.hpp index 33920f312f2..be685ae40a8 100644 --- a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.hpp +++ b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/device/unary_backward_op.hpp @@ -14,7 +14,6 @@ namespace ttnn::operations::unary_backward { constexpr uint8_t DefaultQueueId = 0; enum class UnaryBackwardOpType { MUL_BW, - CLAMP_MIN_BW, CLAMP_BW, HARDTANH_BW, THRESHOLD_BW, diff --git a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward.hpp b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward.hpp index 6370d3d65d2..d7347b88332 100644 --- a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward.hpp +++ b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward.hpp @@ -329,7 +329,6 @@ constexpr auto sqrt_bw = ttnn::register_operation>("ttnn::prod_bw"); constexpr auto mul_bw = ttnn::register_operation>("ttnn::mul_bw"); -constexpr auto clamp_min_bw = ttnn::register_operation>("ttnn::clamp_min_bw"); constexpr auto assign_bw = ttnn::register_operation>("ttnn::assign_bw"); constexpr auto multigammaln_bw = ttnn::register_operation>("ttnn::multigammaln_bw"); constexpr auto add_bw = ttnn::register_operation>("ttnn::add_bw"); diff --git a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward_pybind.hpp b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward_pybind.hpp index ec6a894333e..b8e33b82d84 100644 --- a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward_pybind.hpp +++ b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward_pybind.hpp @@ -729,11 +729,6 @@ void py_module(py::module& module) { ttnn::mul_bw, R"doc(Performs backward operations for multiply on :attr:`input_tensor`, :attr:`alpha` or attr:`input_tensor_a`, attr:`input_tensor_b`, with given :attr:`grad_tensor`.)doc"); - detail::bind_unary_backward( - module, - ttnn::clamp_min_bw, - R"doc(Performs backward operations for clamp min value on :attr:`input_tensor`, :attr:`alpha` with given :attr:`grad_tensor`.)doc"); - detail::bind_unary_backward_optional_float_params_with_default( module, ttnn::clamp_bw, diff --git a/ttnn/ttnn/.rpath_checked__ttnn b/ttnn/ttnn/.rpath_checked__ttnn deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ttnn/ttnn/operations/unary_backward.py b/ttnn/ttnn/operations/unary_backward.py index a826a5d7458..a6580f62df3 100644 --- a/ttnn/ttnn/operations/unary_backward.py +++ b/ttnn/ttnn/operations/unary_backward.py @@ -48,7 +48,6 @@ def unary_bw_prod(torch_op, x, grad_data, *args, **kwargs): name_to_golden_function = { "mul_bw": lambda x, grad_data: unary_bw_with_float(torch.mul, x, grad_data), - "clamp_min_bw": lambda x, grad_data: unary_bw_with_float(torch.clamp_min, x, grad_data), "add_bw": lambda x, grad_data: unary_bw_with_float(torch.add, x, grad_data), "eq_bw": lambda x, grad_data: unary_bw_with_float(torch.eq, x, grad_data), "gt_bw": lambda x, grad_data: unary_bw_with_float(torch.gt, x, grad_data), @@ -136,7 +135,6 @@ def _golden_function(input_tensor: ttnn.Tensor, **_): TTNN_ELTWISE_UNARY_BACKWARD_CPP_FUNCTIONS = [ ttnn.mul_bw, - ttnn.clamp_min_bw, ttnn.add_bw, ttnn.eq_bw, ttnn.gt_bw,