From 32e26c52eea5ad208fbdd1da48cb5f0fb441d456 Mon Sep 17 00:00:00 2001 From: Mouliraj Elamurugan Date: Fri, 22 Nov 2024 13:04:45 +0530 Subject: [PATCH] #14983: Update unary backward docs (#15292) ### Ticket Link to Github Issue #14983 Problem description Update docs for unary backward ops ### What's changed Updated docs for the unary backward ops ### Checklist - [x] All Post commit CI --- .../eltwise/unary_backward/acos_bw/acos_bw.py | 9 +- .../unary_backward/acosh_bw/acosh_bw.py | 9 +- .../eltwise/unary_backward/cos_bw/cos_bw.py | 9 +- .../eltwise/unary_backward/fill_zero_bw.py | 9 +- .../unary_backward/floor_bw/floor_bw.py | 10 +- .../eltwise/unary_backward/frac_bw/frac_bw.py | 9 +- .../hardsigmoid_bw/hardsigmoid_bw.py | 9 +- .../hardswish_bw/hardswish_bw.py | 9 +- .../eltwise/unary_backward/i0_bw/i0_bw.py | 9 +- .../unary_backward/lgamma_bw/lgamma_bw.py | 9 +- .../unary_backward/log10_bw/log10_bw.py | 9 +- .../eltwise/unary_backward/log_bw/log_bw.py | 9 +- .../eltwise/unary_backward/log_sigmoid_bw.py | 9 +- .../sweeps/eltwise/unary_backward/logit_bw.py | 9 +- .../multigammaln_bw/multigammaln_bw.py | 9 +- .../unary_backward/rad2deg_bw/rad2deg_bw.py | 9 +- .../unary_backward/relu6_bw/relu6_bw.py | 9 +- .../eltwise/unary_backward/relu_bw/relu_bw.py | 9 +- .../unary_backward/round_bw/round_bw.py | 9 +- .../eltwise/unary_backward/selu_bw/selu_bw.py | 9 +- .../eltwise/unary_backward/sin_bw/sin_bw.py | 9 +- .../unary_backward/square_bw/square_bw.py | 9 +- .../eltwise/unary_backward/tanh_bw/tanh_bw.py | 9 +- .../tanhshrink_bw/tanhshrink_bw.py | 9 +- .../unary_backward/trunc_bw/trunc_bw.py | 9 +- .../unary_backward/unary_backward_pybind.hpp | 93 +++---------------- 26 files changed, 37 insertions(+), 282 deletions(-) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/acos_bw/acos_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/acos_bw/acos_bw.py index 933bdf5b348..c5a981d013e 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/acos_bw/acos_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/acos_bw/acos_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -80,8 +74,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/acosh_bw/acosh_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/acosh_bw/acosh_bw.py index 8cd93a41ef6..1fadad9575e 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/acosh_bw/acosh_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/acosh_bw/acosh_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, sanitize_shape_rm 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. @@ -79,8 +73,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/cos_bw/cos_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/cos_bw/cos_bw.py index 4ee114daee4..4162480d75a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/cos_bw/cos_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/cos_bw/cos_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -67,8 +61,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/fill_zero_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/fill_zero_bw.py index 0db0e19f89f..a80295e8921 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/fill_zero_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/fill_zero_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. @@ -56,8 +50,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt(partial(torch_random, low=-10, high=10, dtype=torch.float32), grad_dtype)( input_shape diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/floor_bw/floor_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/floor_bw/floor_bw.py index 2d3aa811334..c254031ffb6 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/floor_bw/floor_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/floor_bw/floor_bw.py @@ -5,7 +5,6 @@ from functools import partial import torch -import random import ttnn from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt @@ -13,12 +12,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. # Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. @@ -55,8 +48,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt( partial(torch_random, low=-100, high=100, dtype=torch.float32), grad_dtype diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/frac_bw/frac_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/frac_bw/frac_bw.py index c27ddd17856..49c6c0e3b23 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/frac_bw/frac_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/frac_bw/frac_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -67,8 +61,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/hardsigmoid_bw/hardsigmoid_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/hardsigmoid_bw/hardsigmoid_bw.py index b4bd8ba9e14..15826977743 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/hardsigmoid_bw/hardsigmoid_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/hardsigmoid_bw/hardsigmoid_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -70,8 +64,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/hardswish_bw/hardswish_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/hardswish_bw/hardswish_bw.py index 1c9cbf0e84a..23e9ceaac5f 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/hardswish_bw/hardswish_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/hardswish_bw/hardswish_bw.py @@ -5,7 +5,6 @@ from functools import partial import torch -import random import ttnn from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt @@ -13,11 +12,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. @@ -55,8 +49,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt( partial(torch_random, low=-100, high=100, dtype=torch.float32), grad_dtype diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/i0_bw/i0_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/i0_bw/i0_bw.py index 8c59c741e33..95773e86898 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/i0_bw/i0_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/i0_bw/i0_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -69,8 +63,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/lgamma_bw/lgamma_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/lgamma_bw/lgamma_bw.py index 7680d638517..252e14800c8 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/lgamma_bw/lgamma_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/lgamma_bw/lgamma_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -82,8 +76,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/log10_bw/log10_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/log10_bw/log10_bw.py index 8bc746be8ab..6bf76fff47a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/log10_bw/log10_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/log10_bw/log10_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -79,8 +73,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/log_bw/log_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/log_bw/log_bw.py index 963da118f61..4a73b42dee9 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/log_bw/log_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/log_bw/log_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -70,8 +64,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/log_sigmoid_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/log_sigmoid_bw.py index c43909bc1e9..0023c89842a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/log_sigmoid_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/log_sigmoid_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. @@ -56,8 +50,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt(partial(torch_random, low=-10, high=10, dtype=torch.float32), grad_dtype)( input_shape diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/logit_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/logit_bw.py index 5e7e430fea0..3d406c87e81 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/logit_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/logit_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. @@ -56,8 +50,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt(partial(torch_random, low=-10, high=10, dtype=torch.float32), grad_dtype)( input_shape diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/multigammaln_bw/multigammaln_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/multigammaln_bw/multigammaln_bw.py index e65b324e38a..c8255708deb 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/multigammaln_bw/multigammaln_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/multigammaln_bw/multigammaln_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -66,8 +60,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/rad2deg_bw/rad2deg_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/rad2deg_bw/rad2deg_bw.py index ac9e7b7e209..e6e30db1dbf 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/rad2deg_bw/rad2deg_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/rad2deg_bw/rad2deg_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -67,8 +61,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/relu6_bw/relu6_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/relu6_bw/relu6_bw.py index b03ce34ab79..fdb235e49dc 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/relu6_bw/relu6_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/relu6_bw/relu6_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -68,8 +62,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/relu_bw/relu_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/relu_bw/relu_bw.py index 9173c3519dd..9ed884ef923 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/relu_bw/relu_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/relu_bw/relu_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -67,8 +61,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/round_bw/round_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/round_bw/round_bw.py index 853781be81b..db037b5995c 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/round_bw/round_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/round_bw/round_bw.py @@ -5,7 +5,6 @@ from functools import partial import torch -import random import ttnn from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt @@ -13,11 +12,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. @@ -67,8 +61,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt( partial(torch_random, low=-100, high=100, dtype=torch.float32), grad_dtype diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/selu_bw/selu_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/selu_bw/selu_bw.py index d4eeac59b7e..902c08d8e0a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/selu_bw/selu_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/selu_bw/selu_bw.py @@ -5,7 +5,6 @@ from functools import partial import torch -import random import ttnn from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt @@ -13,11 +12,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. @@ -55,8 +49,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt( partial(torch_random, low=-100, high=100, dtype=torch.float32), grad_dtype diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/sin_bw/sin_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/sin_bw/sin_bw.py index 472c88a51d2..879b27f51a5 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/sin_bw/sin_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/sin_bw/sin_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -68,8 +62,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/square_bw/square_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/square_bw/square_bw.py index 48164a5efb2..1ae1e02b10c 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/square_bw/square_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/square_bw/square_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -67,8 +61,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/tanh_bw/tanh_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/tanh_bw/tanh_bw.py index 52306744d6c..bfadc5cf45b 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/tanh_bw/tanh_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/tanh_bw/tanh_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, sanitize_shape_rm 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. @@ -66,8 +60,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/tanhshrink_bw/tanhshrink_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/tanhshrink_bw/tanhshrink_bw.py index a2afd5c6e4a..640a8cb3e39 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/tanhshrink_bw/tanhshrink_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/tanhshrink_bw/tanhshrink_bw.py @@ -5,7 +5,6 @@ from functools import partial import torch -import random import ttnn from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt @@ -13,11 +12,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. @@ -55,8 +49,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) torch_grad_tensor = gen_func_with_cast_tt( partial(torch_random, low=-100, high=100, dtype=torch.float32), grad_dtype diff --git a/tests/sweep_framework/sweeps/eltwise/unary_backward/trunc_bw/trunc_bw.py b/tests/sweep_framework/sweeps/eltwise/unary_backward/trunc_bw/trunc_bw.py index c6d85efafd6..0cd269a8fe7 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary_backward/trunc_bw/trunc_bw.py +++ b/tests/sweep_framework/sweeps/eltwise/unary_backward/trunc_bw/trunc_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, sanitize_shape_rm @@ -15,11 +14,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. @@ -69,8 +63,7 @@ def run( *, device, ) -> list: - data_seed = random.randint(0, 20000000) - torch.manual_seed(data_seed) + torch.manual_seed(0) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) 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 18a20dbad59..cbd2d9e2f8c 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 @@ -133,8 +133,8 @@ void bind_unary_backward_op( Example: - >>> grad_tensor = ttnn.to_device(ttnn.from_torch(torch.tensor((1, 2), dtype=torch.bfloat16)), device=device) - >>> input = ttnn.to_device(ttnn.from_torch(torch.tensor((1, 2), dtype=torch.bfloat16)), device=device) + >>> grad_tensor = ttnn.from_torch(torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device) + >>> input = ttnn.from_torch(torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device) >>> output = {1}(grad_tensor, input) )doc", operation.base_name(), @@ -1164,75 +1164,6 @@ void bind_unary_backward_prod_bw(py::module& module, const unary_backward_operat } -template -void bind_unary_backward( - py::module& module, - const unary_backward_operation_t& operation, - const std::string& description, - const std::string& supported_dtype = "BFLOAT16", - const std::string& layout = "TILE", - const std::string& note = "") { - auto doc = fmt::format( - R"doc( - {2} - - Args: - grad_tensor (ttnn.Tensor): the input gradient tensor. - input_tensor (ttnn.Tensor): the input tensor. - - Keyword args: - memory_config (ttnn.MemoryConfig, optional): memory configuration for the operation. Defaults to `None`. - - Returns: - List of ttnn.Tensor: the output tensor. - - Note: - Supported dtypes, layouts, and ranks: - - .. list-table:: - :header-rows: 1 - - * - Dtypes - - Layouts - - Ranks - * - {3} - - {4} - - 2, 3, 4 - - {5} - - Example: - - >>> grad_tensor = ttnn.to_device(ttnn.from_torch(torch.tensor((1, 2), dtype=torch.bfloat16)), device=device) - >>> input = ttnn.to_device(ttnn.from_torch(torch.tensor((1, 2), dtype=torch.bfloat16)), device=device) - >>> output = {1}(grad_tensor, input) - )doc", - operation.base_name(), - operation.python_fully_qualified_name(), - description, - supported_dtype, - layout, - note); - - bind_registered_operation( - module, - operation, - doc, - - ttnn::pybind_overload_t{ - [](const unary_backward_operation_t& self, - const ttnn::Tensor& grad_tensor, - const ttnn::Tensor& input_tensor, - const std::optional& memory_config) -> std::vector { - auto output_memory_config = memory_config.value_or(input_tensor.memory_config()); - return self(grad_tensor, input_tensor, output_memory_config); - }, - py::arg("grad_tensor"), - py::arg("input_tensor"), - py::kw_only(), - py::arg("memory_config") = std::nullopt}); -} - template void bind_unary_backward_gelu( py::module& module, @@ -1473,7 +1404,7 @@ void py_module(py::module& module) { ttnn::sqrt_bw, R"doc(Performs backward operations for square-root on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::multigammaln_bw, R"doc(Performs backward operations for multivariate logarithmic gamma function (also referred to as mvlgamma) on :attr:`input_tensor` with given :attr:`grad_tensor`. @@ -1483,7 +1414,7 @@ void py_module(py::module& module) { detail::bind_unary_backward_prod_bw(module, ttnn::prod_bw); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::lgamma_bw, R"doc(Performs backward operations for lgamma on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc"); @@ -1494,18 +1425,18 @@ void py_module(py::module& module) { R"doc(Performs backward operations for fill on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc", R"doc(BFLOAT16)doc", R"doc(TILE, ROW MAJOR)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::hardsigmoid_bw, R"doc(Performs backward operations for hardsigmoid on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::cos_bw, R"doc(Performs backward operations for cosine on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc", R"doc(BFLOAT16, BFLOAT8_B)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::acosh_bw, R"doc(Performs backward operations for inverse hyperbolic cosine (acosh) on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc"); @@ -1582,18 +1513,18 @@ void py_module(py::module& module) { R"doc(Performs backward operations for neg on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc", R"doc(BFLOAT16, BFLOAT8_B)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::relu_bw, R"doc(Performs backward operations for relu on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc", R"doc(BFLOAT16, BFLOAT8_B)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::logit_bw, R"doc(Performs backward operations for logit on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::floor_bw, R"doc(Performs backward operations for floor on :attr:`input_tensor` with given :attr:`grad_tensor`)doc", @@ -1606,13 +1537,13 @@ void py_module(py::module& module) { "exponent","Exponent value", R"doc(BFLOAT16, BFLOAT8_B)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::round_bw, R"doc(Performs backward operations for round on :attr:`input_tensor` with given :attr:`grad_tensor`.)doc", R"doc(BFLOAT16)doc", R"doc(TILE, ROW MAJOR)doc"); - detail::bind_unary_backward( + detail::bind_unary_backward_op( module, ttnn::log_bw, R"doc(Performs backward operations for logarithm on :attr:`input_tensor` with given :attr:`grad_tensor`)doc");