diff --git a/docs/source/ttnn/ttnn/api.rst b/docs/source/ttnn/ttnn/api.rst index edbb7ad103b4..c39c01067083 100644 --- a/docs/source/ttnn/ttnn/api.rst +++ b/docs/source/ttnn/ttnn/api.rst @@ -173,6 +173,7 @@ Pointwise Unary ttnn/multigammaln_bw ttnn/add_bw ttnn/eq_bw + ttnn/floor_bw Pointwise Binary ================ diff --git a/docs/source/ttnn/ttnn/dependencies/tt_lib.rst b/docs/source/ttnn/ttnn/dependencies/tt_lib.rst index c9bc0a4a5912..e5860286833f 100644 --- a/docs/source/ttnn/ttnn/dependencies/tt_lib.rst +++ b/docs/source/ttnn/ttnn/dependencies/tt_lib.rst @@ -966,8 +966,6 @@ Backward Operations .. autofunction:: tt_lib.tensor.repeat_bw -.. autofunction:: tt_lib.tensor.floor_bw - .. autofunction:: tt_lib.tensor.round_bw .. autofunction:: tt_lib.tensor.unary_div_no_nan_bw diff --git a/tests/tt_eager/python_api_testing/unit_testing/backward_ops/test_backward_floor.py b/tests/tt_eager/python_api_testing/unit_testing/backward_ops/test_backward_floor.py index b9fd8c121356..8d71f8228653 100644 --- a/tests/tt_eager/python_api_testing/unit_testing/backward_ops/test_backward_floor.py +++ b/tests/tt_eager/python_api_testing/unit_testing/backward_ops/test_backward_floor.py @@ -5,6 +5,7 @@ import torch import pytest import tt_lib +import ttnn from tests.tt_eager.python_api_testing.unit_testing.backward_ops.utility_funcs import compare_pcc, data_gen_with_range @@ -22,7 +23,7 @@ def test_bw_floor(input_shapes, device): pyt_y = torch.floor(in_data) - tt_output_tensor_on_device = tt_lib.tensor.floor_bw(grad_tensor) + tt_output_tensor_on_device = ttnn.floor_bw(grad_tensor, input_tensor) in_data.retain_grad() diff --git a/tt_eager/tt_dnn/op_library/backward/backward_ops.cpp b/tt_eager/tt_dnn/op_library/backward/backward_ops.cpp index 6b0cd6860b80..b0f7c06e90d6 100644 --- a/tt_eager/tt_dnn/op_library/backward/backward_ops.cpp +++ b/tt_eager/tt_dnn/op_library/backward/backward_ops.cpp @@ -2053,16 +2053,6 @@ std::vector repeat_bw( return operation::decorate_as_composite(__func__, _repeat_bw)(grad, input, shape, output_mem_config); } -std::vector _floor_bw(const Tensor& grad, const MemoryConfig& output_mem_config) { - std::vector grad_tensor; - Tensor t_zero = zeros_like(grad, output_mem_config); - grad_tensor.emplace_back(t_zero); - return grad_tensor; -} -std::vector floor_bw(const Tensor& grad, const MemoryConfig& output_mem_config) { - return operation::decorate_as_composite(__func__, _floor_bw)(grad, output_mem_config); -} - std::vector _round_bw(const Tensor& grad, const MemoryConfig& output_mem_config) { std::vector grad_tensor; Tensor t_zero = zeros_like(grad, output_mem_config); diff --git a/tt_eager/tt_dnn/op_library/backward/backward_ops.hpp b/tt_eager/tt_dnn/op_library/backward/backward_ops.hpp index 7b11d7b1a69d..700e9e7127c2 100644 --- a/tt_eager/tt_dnn/op_library/backward/backward_ops.hpp +++ b/tt_eager/tt_dnn/op_library/backward/backward_ops.hpp @@ -528,9 +528,6 @@ std::vector complex_sub_bw( std::vector repeat_bw( const Tensor& grad, const Tensor& input, const Shape& shape, const MemoryConfig& output_mem_config); -std::vector floor_bw( - const Tensor& grad, const MemoryConfig& output_mem_config = operation::DEFAULT_OUTPUT_MEMORY_CONFIG); - std::vector round_bw( const Tensor& grad, const MemoryConfig& output_mem_config = operation::DEFAULT_OUTPUT_MEMORY_CONFIG); diff --git a/tt_eager/tt_lib/csrc/tt_lib_bindings_tensor_backward_ops.cpp b/tt_eager/tt_lib/csrc/tt_lib_bindings_tensor_backward_ops.cpp index d6a30e7243a1..3d49bbc47155 100644 --- a/tt_eager/tt_lib/csrc/tt_lib_bindings_tensor_backward_ops.cpp +++ b/tt_eager/tt_lib/csrc/tt_lib_bindings_tensor_backward_ops.cpp @@ -1477,23 +1477,6 @@ namespace tt::tt_metal::detail{ "output_mem_config", "Layout of tensor in TT Accelerator device memory banks", "MemoryConfig", "Default is interleaved in DRAM", "No" )doc"); - - m_tensor.def("floor_bw", &tt::tt_metal::floor_bw, - py::arg("grad").noconvert(), py::arg("output_mem_config").noconvert() = operation::DEFAULT_OUTPUT_MEMORY_CONFIG, R"doc( - Returns an tensor of zeros like ``grad`` tensor - - Input tensor must have BFLOAT16 data type. - - Output tensor will have BFLOAT16 data type. - - .. csv-table:: - :header: "Argument", "Description", "Data type", "Valid range", "Required" - - "grad", "Gradient tensor", "Tensor", "Tensor of shape [W, Z, Y, X]", "Yes" - "output_mem_config", "Layout of tensor in TT Accelerator device memory banks", "MemoryConfig", "Default is interleaved in DRAM", "No" - )doc"); - - m_tensor.def("round_bw", &tt::tt_metal::round_bw, py::arg("grad").noconvert(), py::arg("output_mem_config").noconvert() = operation::DEFAULT_OUTPUT_MEMORY_CONFIG, R"doc( Returns an tensor of zeros like ``grad`` tensor 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 f1185034701b..9fb4be488aa5 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 @@ -96,6 +96,8 @@ std::function(const Tensor&, const Tensor&, const Memo return _assign_bw; case UnaryBackwardOpType::MULTIGAMMALN_BW: return _multigammaln_bw; + case UnaryBackwardOpType::FLOOR_BW: + return _floor_bw; default: TT_ASSERT(false && "Undefined op type"); return 0; 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 b06e55143a6b..98058f9b5321 100644 --- a/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward.hpp +++ b/ttnn/cpp/ttnn/operations/eltwise/unary_backward/unary_backward.hpp @@ -72,5 +72,7 @@ constexpr auto assign_bw = ttnn::register_operation>("ttnn::multigammaln_bw"); constexpr auto add_bw = ttnn::register_operation>("ttnn::add_bw"); constexpr auto eq_bw = ttnn::register_operation>("ttnn::eq_bw"); +constexpr auto floor_bw = ttnn::register_operation>("ttnn::floor_bw"); + } // namespace ttnn 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 b463ec45c1bf..a3b65618ce0e 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 @@ -195,6 +195,11 @@ void py_module(py::module& module) { R"doc(Performs backward operations for equal to comparison on :attr:`input_tensor`, :attr:`alpha` or attr:`input_tensor_a`, attr:`input_tensor_b` with given :attr:`grad_tensor`. Returns an tensor of zeros like input tensors.)doc"); + detail::bind_unary_backward( + module, + ttnn::floor_bw, + R"doc(Performs backward operations for floor on :attr:`input_tensor` or attr:`input_tensor_a`, attr:`input_tensor_b` with given :attr:`grad_tensor`.)doc"); + } } // namespace binary_backward