From fec3ebc0ea6abc10c09d8ae5f79c854202eec692 Mon Sep 17 00:00:00 2001 From: Anasuya G Nair Date: Mon, 11 Nov 2024 13:52:56 +0530 Subject: [PATCH] #13685: Update backward embedding document (#14666) ### Ticket #13685 ### Problem description - ttnn.embedding_bw doesn't support output and input gradient tensors having different dtypes. - ttnn.embedding_bw is not an eltwise op. So, moving corresponding tests outside eltwise folder. ### What's changed - Updated document to add a note mentioning input and output gradients must have the same datatype. - Moved sweep test from `tests/sweep_framework/sweeps/eltwise/binary_backward/embedding_bw/embedding_bw.py` to `tests/sweep_framework/sweeps/embedding_bw/embedding_bw.py` - Move unit test from from `tests/ttnn/unit_tests/operations/eltwise/backward/test_backward_embedding.py` to `tests/ttnn/unit_tests/operations/test_backward_embedding.py` ### Updated doc Screenshot 2024-11-04 at 17 49 31 ### Checklist - [x] [Post commit CI passes](https://github.com/tenstorrent/tt-metal/actions/runs/11680989159) - PASSED - [x] [Run Sweeps](https://github.com/tenstorrent/tt-metal/actions/runs/11678538301) - PASSED - [x] [Night fast dispatch tests](https://github.com/tenstorrent/tt-metal/actions/runs/11678522765) (same as main) --- .github/workflows/ttnn-run-sweeps.yaml | 2 +- .../binary_backward => }/embedding_bw/embedding_bw.py | 9 +-------- .../{eltwise/backward => }/test_backward_embedding.py | 0 .../embedding_backward/embedding_backward_pybind.cpp | 2 ++ 4 files changed, 4 insertions(+), 9 deletions(-) rename tests/sweep_framework/sweeps/{eltwise/binary_backward => }/embedding_bw/embedding_bw.py (96%) rename tests/ttnn/unit_tests/operations/{eltwise/backward => }/test_backward_embedding.py (100%) diff --git a/.github/workflows/ttnn-run-sweeps.yaml b/.github/workflows/ttnn-run-sweeps.yaml index 4e0ddec26a8..1bd08c3025a 100644 --- a/.github/workflows/ttnn-run-sweeps.yaml +++ b/.github/workflows/ttnn-run-sweeps.yaml @@ -235,7 +235,6 @@ on: - eltwise.binary_backward.ldexp_bw - eltwise.binary_backward.logaddexp_bw - eltwise.binary_backward.logaddexp2_bw - - eltwise.binary_backward.embedding_bw.embedding_bw - eltwise.binary_backward.addalpha_bw.addalpha_bw - eltwise.binary_backward.subalpha_bw.subalpha_bw - eltwise.binary_backward.xlogy_bw.xlogy_bw @@ -266,6 +265,7 @@ on: - eltwise.ternary_backward.addcmul_bw - eltwise.ternary_backward.addcdiv_bw - embedding.embedding + - embedding_bw.embedding_bw - reduction.backward.prod_bw.prod_bw - reduction.topk.topk - reduction.argmax.argmax diff --git a/tests/sweep_framework/sweeps/eltwise/binary_backward/embedding_bw/embedding_bw.py b/tests/sweep_framework/sweeps/embedding_bw/embedding_bw.py similarity index 96% rename from tests/sweep_framework/sweeps/eltwise/binary_backward/embedding_bw/embedding_bw.py rename to tests/sweep_framework/sweeps/embedding_bw/embedding_bw.py index a19fd9f1751..b7e748f9510 100644 --- a/tests/sweep_framework/sweeps/eltwise/binary_backward/embedding_bw/embedding_bw.py +++ b/tests/sweep_framework/sweeps/embedding_bw/embedding_bw.py @@ -6,7 +6,6 @@ from functools import partial import torch -import random import ttnn from tests.sweep_framework.sweep_utils.utils import gen_shapes from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt @@ -14,11 +13,6 @@ from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time from models.utility_functions import torch_random -# Override the default timeout in seconds for hang detection. -TIMEOUT = 30 - -random.seed(0) - # Parameters provided to the test vector generator are defined here. # They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. @@ -91,8 +85,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) batch_size, seq_length, embeddings_dim, num_embeddings = embedding_args diff --git a/tests/ttnn/unit_tests/operations/eltwise/backward/test_backward_embedding.py b/tests/ttnn/unit_tests/operations/test_backward_embedding.py similarity index 100% rename from tests/ttnn/unit_tests/operations/eltwise/backward/test_backward_embedding.py rename to tests/ttnn/unit_tests/operations/test_backward_embedding.py diff --git a/ttnn/cpp/ttnn/operations/embedding_backward/embedding_backward_pybind.cpp b/ttnn/cpp/ttnn/operations/embedding_backward/embedding_backward_pybind.cpp index f9e93cd87b4..d3daeb0d8f1 100644 --- a/ttnn/cpp/ttnn/operations/embedding_backward/embedding_backward_pybind.cpp +++ b/ttnn/cpp/ttnn/operations/embedding_backward/embedding_backward_pybind.cpp @@ -35,6 +35,8 @@ void py_bind_embedding_backward(py::module& module) { Returns: ttnn.Tensor: the output tensor. + Note: + The input and the output gradient tensors must have the same datatype. Example: >>> device_id = 0