From e71b3e85890f90ec73faae4a2928c60e7233eadc Mon Sep 17 00:00:00 2001 From: Virdhatchani Narayanamoorthy <138196495+VirdhatchaniKN@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:15:53 +0530 Subject: [PATCH] #13373: PyTorch Tracing Sweeps - Eltwise set 2 (#13421) * #13373: PyTorch Tracing Sweeps for set 2 * #13373: Update golden function * #13421: Update * #13421: Update where sweep --- .github/workflows/ttnn-run-sweeps.yaml | 12 ++ .../eltwise/binary/div/div_tensor_pytorch2.py | 193 ++++++++++++++++++ .../eltwise/binary/lt/lt_scalar_pytorch2.py | 73 +++++++ .../eltwise/binary/lt/lt_tensor_pytorch2.py | 80 ++++++++ .../multiply/multiply_scalar_pytorch2.py | 69 +++++++ .../eltwise/binary/ne/ne_scalar_pytorch2.py | 74 +++++++ .../subtract/subtract_tensor_pytorch2.py | 172 ++++++++++++++++ .../eltwise/ternary/where/where_pytorch2.py | 6 +- .../eltwise/unary/clamp/clamp_min_pytorch2.py | 76 +++++++ .../eltwise/unary/clamp/clamp_pytorch2.py | 123 +++++++++++ .../unary/hardswish/hardswish_pytorch2.py | 93 +++++++++ .../unary/hardtanh/hardtanh_pytorch2.py | 181 ++++++++++++++++ .../unary/logical_not/logical_not_pytorch2.py | 67 ++++++ .../sweeps/eltwise/unary/neg/neg_pytorch2.py | 74 +++++++ 14 files changed, 1290 insertions(+), 3 deletions(-) create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/div/div_tensor_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/lt/lt_scalar_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/lt/lt_tensor_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/multiply/multiply_scalar_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/ne/ne_scalar_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/subtract/subtract_tensor_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_min_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/hardswish/hardswish_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/hardtanh/hardtanh_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/logical_not/logical_not_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/neg/neg_pytorch2.py diff --git a/.github/workflows/ttnn-run-sweeps.yaml b/.github/workflows/ttnn-run-sweeps.yaml index 905ac2c879d..3b537e205e4 100644 --- a/.github/workflows/ttnn-run-sweeps.yaml +++ b/.github/workflows/ttnn-run-sweeps.yaml @@ -28,6 +28,8 @@ on: - eltwise.unary.sin.sin_pytorch2 - eltwise.unary.tril.tril_pytorch2 - eltwise.unary.clamp.clamp + - eltwise.unary.clamp.clamp_pytorch2 + - eltwise.unary.clamp.clamp_min_pytorch2 - eltwise.unary.clip.clip - eltwise.unary.cbrt.cbrt - eltwise.unary.rsub.rsub @@ -70,6 +72,8 @@ on: - eltwise.unary.logical_not.logical_not_ - eltwise.unary.logical_not.logical_not - eltwise.unary.logical_not.logical_not_output + - eltwise.unary.logical_not.logical_not_pytorch2 + - eltwise.unary.neg.neg_pytorch2 - eltwise.unary.erf.erf - eltwise.unary.erfinv.erfinv - eltwise.unary.i0.i0 @@ -148,10 +152,15 @@ on: - eltwise.unary.lez.lez - eltwise.unary.nez.nez - eltwise.unary.prelu.prelu + - eltwise.unary.hardswish.hardswish_pytorch2 + - eltwise.unary.hardtanh.hardtanh_pytorch2 - eltwise.binary.subtract.subtract + - eltwise.binary.subtract.subtract_tensor_pytorch2 - eltwise.binary.multiply.multiply - eltwise.binary.multiply.mul_tensor_pytorch2 + - eltwise.binary.multiply.multiply_scalar_pytorch2 - eltwise.binary.div.div + - eltwise.binary.div.div_tensor_pytorch2 - eltwise.binary.div_no_nan.div_no_nan - eltwise.binary.logical_or.logical_or_ - eltwise.binary.logical_or.logical_or @@ -175,6 +184,9 @@ on: - eltwise.binary.floor_divide.floor_divide_pytorch2 - eltwise.binary.logaddexp.logaddexp - eltwise.binary.ldexp.ldexp + - eltwise.binary.lt.lt_tensor_pytorch2 + - eltwise.binary.lt.lt_scalar_pytorch2 + - eltwise.binary.ne.ne_scalar_pytorch2 - eltwise.binary.hypot.hypot - eltwise.binary.xlogy.xlogy - eltwise.binary_backward.embedding_bw.embedding_bw diff --git a/tests/sweep_framework/sweeps/eltwise/binary/div/div_tensor_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/div/div_tensor_pytorch2.py new file mode 100644 index 00000000000..f0f59a5ee0c --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/div/div_tensor_pytorch2.py @@ -0,0 +1,193 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [0, 1], "other": 1.0}, + {"shape": [1, 1, 16384, 256], "other": 5.656854249492381}, + {"shape": [1, 1, 19200, 300], "other": 8.0}, + {"shape": [1, 1, 256], "other": 0.5}, + {"shape": [1, 1024, 640], "other": 1.0}, + {"shape": [1, 12, 10, 10], "other": 8.0}, + {"shape": [1, 12, 12, 12], "other": 8.0}, + {"shape": [1, 12, 14, 14], "other": 8.0}, + {"shape": [1, 12, 16, 64], "other": 8.0}, + {"shape": [1, 12, 197, 197], "other": 8.0}, + {"shape": [1, 12, 201, 201], "other": 8.0}, + {"shape": [1, 12, 25, 25], "other": 8.0}, + {"shape": [1, 12, 7, 7], "other": []}, + {"shape": [1, 12, 9, 9], "other": 8.0}, + {"shape": [1, 128, 1536], "other": 3}, + {"shape": [1, 1280, 16, 16], "other": 1.0}, + {"shape": [1, 1280, 8, 8], "other": 1}, + {"shape": [1, 1280, 8, 8], "other": 1.0}, + {"shape": [1, 16, 1, 6], "other": []}, + # {"shape": [1, 16, 1, s10 + 1], "other": []}, + {"shape": [1, 16, 197, 197], "other": 8.0}, + {"shape": [1, 16, 256, 256], "other": 8.0}, + {"shape": [1, 16, 5, 5], "other": []}, + {"shape": [1, 16, 9, 9], "other": 11.313708498984761}, + {"shape": [1, 16, 9, 9], "other": 8.0}, + {"shape": [1, 1], "other": 16}, + {"shape": [1, 1], "other": 2.0794415416798357}, + {"shape": [1, 2, 4096, 256], "other": 5.656854249492381}, + {"shape": [1, 2, 4800, 300], "other": 8.0}, + {"shape": [1, 23, 40, 1], "other": [128]}, + {"shape": [1, 23, 40], "other": [1, 1, 40]}, + {"shape": [1, 23, 40], "other": [1, 23, 1]}, + {"shape": [1, 24, 64, 32], "other": [1, 24, 64, 32]}, + {"shape": [1, 256, 1280], "other": 1.0}, + {"shape": [1, 256, 384], "other": 3}, + {"shape": [1, 3, 1445, 1445], "other": 8.0}, + {"shape": [1, 32, 24576], "other": 3}, + {"shape": [1, 32, 64, 32], "other": [1, 32, 64, 32]}, + {"shape": [1, 320, 64, 64], "other": 1.0}, + {"shape": [1, 4096, 320], "other": 1.0}, + {"shape": [1, 5, 1024, 256], "other": 5.656854249492381}, + {"shape": [1, 5, 1200, 300], "other": 8.0}, + {"shape": [1, 50257], "other": 0.9}, + {"shape": [1, 512, 38, 38], "other": [1, 512, 38, 38]}, + {"shape": [1, 512], "other": [1, 1]}, + {"shape": [1, 512], "other": [1, 512]}, + {"shape": [1, 64, 1280], "other": 1.0}, + {"shape": [1, 64, 6144], "other": 3}, + {"shape": [1, 64, 9, 9], "other": 8.0}, + {"shape": [1, 640, 32, 32], "other": 1.0}, + {"shape": [1, 8, 2048, 256], "other": 5.656854249492381}, + {"shape": [1, 8, 256, 2048], "other": 5.656854249492381}, + {"shape": [1, 8, 256, 256], "other": 5.656854249492381}, + {"shape": [1, 8, 300, 300], "other": 8.0}, + # {"shape": [1, s0, 256], "other": 0.5 }, + {"shape": [10, 10], "other": 2.772588722239781}, + {"shape": [10, 10], "other": 8}, + {"shape": [10], "other": 10}, + {"shape": [10], "other": 9.375}, + {"shape": [128], "other": 128}, + {"shape": [15, 15], "other": 2.772588722239781}, + {"shape": [15, 15], "other": 8}, + {"shape": [16, 6, 64, 32], "other": [16, 6, 64, 32]}, + {"shape": [16, 8, 64, 32], "other": [16, 8, 64, 32]}, + {"shape": [160], "other": 160}, + {"shape": [17, 17], "other": 16}, + {"shape": [17, 17], "other": 2.0794415416798357}, + {"shape": [19], "other": 18.75}, + {"shape": [1], "other": 1}, + {"shape": [1], "other": 1.0}, + {"shape": [2, 2], "other": 16}, + {"shape": [2, 2], "other": 2.0794415416798357}, + {"shape": [2, 512], "other": [2, 1]}, + {"shape": [20], "other": 20}, + {"shape": [2], "other": 2}, + {"shape": [3, 320, 320], "other": [3, 1, 1]}, + {"shape": [3, 480, 640], "other": [3, 1, 1]}, + {"shape": [3234, 1], "other": 10.0}, + {"shape": [3234, 1], "other": 5.0}, + {"shape": [38], "other": 37.5}, + {"shape": [3], "other": 3}, + {"shape": [3], "other": 3.0}, + {"shape": [4, 12, 64, 32], "other": [4, 12, 64, 32]}, + {"shape": [4, 16, 64, 32], "other": [4, 16, 64, 32]}, + {"shape": [5], "other": 4.6875}, + {"shape": [5], "other": 5}, + {"shape": [64, 3, 64, 32], "other": [64, 3, 64, 32]}, + {"shape": [64, 4, 64, 32], "other": [64, 4, 64, 32]}, + {"shape": [8, 100, 32], "other": 5.656854249492381}, + {"shape": [8, 920, 32], "other": 5.656854249492381}, + {"shape": [8732, 1], "other": 10.0}, + {"shape": [8732, 1], "other": 5.0}, + {"shape": [96, 80], "other": [80]}, + {"shape": [], "other": []}, + # {"shape": [s0 + 1, s0 + 1], "other": 16 }, + # {"shape": [s0 + 1, s0 + 1], "other": 2.0794415416798357 }, + ], + "input_a_dtype": [ttnn.bfloat16], + "input_b_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_b_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_b_dtype, + input_a_layout, + input_b_layout, + input_a_memory_config, + input_b_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape = input_specs["shape"] + if len(input_shape) == 0: + torch_input_tensor_a = torch.empty([]) + else: + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_shape) + + other = input_specs["other"] + if isinstance(other, (int, float)): + torch_other_tensor = torch.tensor(other, dtype=torch.float32) + elif len(other) == 0: + torch_other_tensor = torch.empty([]) + else: + torch_other_tensor = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_b_dtype + )(other) + + golden_function = ttnn.get_golden_function(ttnn.divide) + torch_output_tensor = golden_function(torch_input_tensor_a, torch_other_tensor) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + input_tensor_b = ttnn.from_torch( + torch_other_tensor, + dtype=input_b_dtype, + layout=input_b_layout, + device=device, + memory_config=input_b_memory_config, + ) + + start_time = start_measuring_time() + + output_tensor = ttnn.divide(input_tensor_a, input_tensor_b, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(output_tensor) + + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/lt/lt_scalar_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/lt/lt_scalar_pytorch2.py new file mode 100644 index 00000000000..72b7a49436a --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/lt/lt_scalar_pytorch2.py @@ -0,0 +1,73 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [1, 1], "other": 16}, + {"shape": [10, 10], "other": 8}, + {"shape": [15, 15], "other": 8}, + {"shape": [17, 17], "other": 16}, + {"shape": [2, 2], "other": 16}, + # {"shape": [s0 + 1, s0 + 1], "other": 16}, + ], + "input_a_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_a_layout, + input_a_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_specs["shape"]) + + golden_function = ttnn.get_golden_function(ttnn.lt) + torch_output_tensor = golden_function(torch_input_tensor_a, input_specs["other"]) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.lt(input_tensor_a, input_specs["other"], memory_config=output_memory_config) + output_tensor = ttnn.to_torch(output_tensor) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/lt/lt_tensor_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/lt/lt_tensor_pytorch2.py new file mode 100644 index 00000000000..9c828faa5cf --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/lt/lt_tensor_pytorch2.py @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +from tests.ttnn.utils_for_testing import assert_equal, 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 = { + "nightly": { + "input_shape_a": [[1, 50257]], + "input_shape_b": [[1, 1]], + "input_a_dtype": [ttnn.bfloat16], + "input_b_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_b_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_shape_a, + input_shape_b, + input_a_dtype, + input_b_dtype, + input_a_layout, + input_b_layout, + input_a_memory_config, + input_b_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_shape_a) + torch_input_tensor_b = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_b_dtype + )(input_shape_b) + + golden_function = ttnn.get_golden_function(ttnn.lt) + torch_output_tensor = golden_function(torch_input_tensor_a, torch_input_tensor_b) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + input_tensor_b = ttnn.from_torch( + torch_input_tensor_b, + dtype=input_b_dtype, + layout=input_b_layout, + device=device, + memory_config=input_b_memory_config, + ) + start_time = start_measuring_time() + result = ttnn.lt(input_tensor_a, input_tensor_b) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [assert_equal(torch_output_tensor, output_tensor), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/multiply/multiply_scalar_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/multiply/multiply_scalar_pytorch2.py new file mode 100644 index 00000000000..519f55afd09 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/multiply/multiply_scalar_pytorch2.py @@ -0,0 +1,69 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [1, 1, 64, 7], "other": 0.3535533905932738}, + {"shape": [1, 71, 7, 649], "other": 0.3535533905932738}, + ], + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_a_layout, + input_a_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_specs["shape"]) + + golden_function = ttnn.get_golden_function(ttnn.mul) + torch_output_tensor = golden_function(torch_input_tensor_a, input_specs["other"]) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.multiply(input_tensor_a, input_specs["other"], memory_config=output_memory_config) + output_tensor = ttnn.to_torch(output_tensor) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/ne/ne_scalar_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/ne/ne_scalar_pytorch2.py new file mode 100644 index 00000000000..b8bb0cec0d3 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/ne/ne_scalar_pytorch2.py @@ -0,0 +1,74 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [1, 10], "other": 1}, + {"shape": [16, 49, 49], "other": 0}, + {"shape": [16, 64, 64], "other": 0}, + {"shape": [4, 49, 49], "other": 0}, + {"shape": [4, 64, 64], "other": 0}, + {"shape": [64, 49, 49], "other": 0}, + {"shape": [64, 64, 64], "other": 0}, + ], + "input_a_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_a_layout, + input_a_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_specs["shape"]) + + golden_function = ttnn.get_golden_function(ttnn.ne) + torch_output_tensor = golden_function(torch_input_tensor_a, input_specs["other"]) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.ne(input_tensor_a, input_specs["other"], memory_config=output_memory_config) + output_tensor = ttnn.to_torch(output_tensor) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/subtract/subtract_tensor_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/subtract/subtract_tensor_pytorch2.py new file mode 100644 index 00000000000..5e42dc03a1b --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/subtract/subtract_tensor_pytorch2.py @@ -0,0 +1,172 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +TIMEOUT = 30 + +random.seed(0) + + +parameters = { + "nightly": { + "input_specs": [ + {"shape": [0, 1], "other": [0, 1]}, + {"shape": [0], "other": [0]}, + {"shape": [1, 1, 1, 42], "other": -3.0}, + {"shape": [1, 1, 1, 42], "other": -3.75}, + {"shape": [1, 1, 1, 42], "other": 0.5}, + {"shape": [1, 1, 1, 42], "other": 1}, + {"shape": [1, 1, 1, 42], "other": 2.25}, + {"shape": [1, 1, 1, 42], "other": [1, 1, 1, 42]}, + {"shape": [1, 1, 32, 1], "other": -3.0}, + {"shape": [1, 1, 32, 1], "other": -3.75}, + {"shape": [1, 1, 32, 1], "other": 0.5}, + {"shape": [1, 1, 32, 1], "other": 1}, + {"shape": [1, 1, 32, 1], "other": 2.25}, + {"shape": [1, 1, 32, 1], "other": [1, 1, 32, 1]}, + {"shape": [1, 1024, 1, 1], "other": [1, 1024, 1, 1]}, + {"shape": [1, 10], "other": [10, 1]}, + {"shape": [1, 128, 1, 1], "other": [1, 128, 1, 1]}, + {"shape": [1, 15], "other": [15, 1]}, + {"shape": [1, 17], "other": [17, 1]}, + {"shape": [1, 1], "other": [1, 1]}, + {"shape": [1, 2048, 1, 1], "other": [1, 2048, 1, 1]}, + {"shape": [1, 256, 1, 1], "other": [1, 256, 1, 1]}, + {"shape": [1, 2], "other": [2, 1]}, + {"shape": [1, 32], "other": 1}, + {"shape": [1, 45], "other": 1}, + {"shape": [1, 512, 1, 1], "other": [1, 512, 1, 1]}, + {"shape": [1, 59], "other": 1}, + {"shape": [1, 5], "other": 1}, + {"shape": [1, 60], "other": 1}, + {"shape": [1, 64, 1, 1], "other": [1, 64, 1, 1]}, + # {"shape": [1, s0 + 1], "other": [s0 + 1, 1]}, + # {"shape": [1, s0], "other": 1 }, + # {"shape": [1, s10 + 1], "other": 1 }, + {"shape": [1066], "other": 0.5}, + {"shape": [1066], "other": [1066]}, + {"shape": [120, 1], "other": [120, 1]}, + {"shape": [120], "other": 0.5}, + {"shape": [128, 1], "other": [128, 1]}, + {"shape": [128], "other": 0.5}, + {"shape": [128], "other": [128]}, + {"shape": [16, 1, 49], "other": [16, 49, 1]}, + {"shape": [16, 1, 64], "other": [16, 64, 1]}, + {"shape": [160], "other": 0.5}, + {"shape": [160], "other": [160]}, + {"shape": [1], "other": 1}, + {"shape": [24, 1], "other": [1, 24]}, + {"shape": [240, 1], "other": [240, 1]}, + {"shape": [240], "other": 0.5}, + {"shape": [3, 320, 320], "other": [3, 1, 1]}, + {"shape": [3, 480, 640], "other": [3, 1, 1]}, + {"shape": [30, 1], "other": [30, 1]}, + {"shape": [300, 1], "other": [300, 1]}, + {"shape": [300], "other": 0.5}, + {"shape": [300], "other": [300]}, + {"shape": [30], "other": 0.5}, + {"shape": [320, 1], "other": [320, 1]}, + {"shape": [320], "other": 0.5}, + {"shape": [320], "other": [320]}, + {"shape": [3234, 1], "other": [3234, 1]}, + {"shape": [3234, 2], "other": [3234, 2]}, + {"shape": [3234], "other": [3234]}, + {"shape": [4, 1, 49], "other": [4, 49, 1]}, + {"shape": [4, 1, 64], "other": [4, 64, 1]}, + {"shape": [40], "other": 0.5}, + {"shape": [40], "other": [40]}, + {"shape": [480, 1], "other": [480, 1]}, + {"shape": [480], "other": 0.5}, + {"shape": [60, 1], "other": [60, 1]}, + {"shape": [60], "other": 0.5}, + {"shape": [64, 1, 49], "other": [64, 49, 1]}, + {"shape": [64, 1, 64], "other": [64, 64, 1]}, + {"shape": [640], "other": 0.5}, + {"shape": [640], "other": [640]}, + {"shape": [800, 1], "other": [800, 1]}, + {"shape": [800], "other": 0.5}, + {"shape": [80], "other": 0.5}, + {"shape": [80], "other": [80]}, + {"shape": [8732, 1], "other": [8732, 1]}, + {"shape": [8732, 2], "other": [8732, 2]}, + {"shape": [8732], "other": [8732]}, + {"shape": [96, 80], "other": [80]}, + ], + "input_a_dtype": [ttnn.bfloat16], + "input_b_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_b_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_b_dtype, + input_a_layout, + input_b_layout, + input_a_memory_config, + input_b_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape = input_specs["shape"] + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_shape) + + other = input_specs["other"] + if isinstance(other, (int, float)): + torch_other_tensor = torch.tensor(other, dtype=torch.float32) + else: + torch_other_tensor = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_b_dtype + )(other) + + golden_function = ttnn.get_golden_function(ttnn.sub) + torch_output_tensor = golden_function(torch_input_tensor_a, torch_other_tensor) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + input_tensor_b = ttnn.from_torch( + torch_other_tensor, + dtype=input_b_dtype, + layout=input_b_layout, + device=device, + memory_config=input_b_memory_config, + ) + + start_time = start_measuring_time() + + output_tensor = ttnn.subtract(input_tensor_a, input_tensor_b, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(output_tensor) + + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/ternary/where/where_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/ternary/where/where_pytorch2.py index 720b4e1d33d..50a1485782f 100644 --- a/tests/sweep_framework/sweeps/eltwise/ternary/where/where_pytorch2.py +++ b/tests/sweep_framework/sweeps/eltwise/ternary/where/where_pytorch2.py @@ -43,9 +43,9 @@ {"shape1": [2, 2], "shape2": [2, 2], "shape3": [2, 2]}, # {"shape1": ["s0 + 1", "s0 + 1"], "shape2": ["s0 + 1", "s0 + 1"], "shape3": []}, ], - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_b_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_c_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_a_dtype": [ttnn.bfloat16], + "input_b_dtype": [ttnn.bfloat16], + "input_c_dtype": [ttnn.bfloat16], "input_a_layout": [ttnn.TILE_LAYOUT], "input_b_layout": [ttnn.TILE_LAYOUT], "input_c_layout": [ttnn.TILE_LAYOUT], diff --git a/tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_min_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_min_pytorch2.py new file mode 100644 index 00000000000..3ccd70d7411 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_min_pytorch2.py @@ -0,0 +1,76 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes, gen_low_high_scalars +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [1, 1, 38, 38], "min": 1e-12}, + {"shape": [1, 1], "min": 1e-12}, + {"shape": [1, 24, 64, 1], "min": 1e-12}, + {"shape": [1, 32, 64, 1], "min": 1e-12}, + {"shape": [16, 6, 64, 1], "min": 1e-12}, + {"shape": [16, 8, 64, 1], "min": 1e-12}, + {"shape": [4, 12, 64, 1], "min": 1e-12}, + {"shape": [4, 16, 64, 1], "min": 1e-12}, + {"shape": [64, 3, 64, 1], "min": 1e-12}, + {"shape": [64, 4, 64, 1], "min": 1e-12}, + ], + "input_a_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_a_layout, + input_a_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_specs["shape"]) + + golden_function = ttnn.get_golden_function(ttnn.clamp) + torch_output_tensor = golden_function(torch_input_tensor_a, input_specs["min"]) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + start_time = start_measuring_time() + result = ttnn.clamp(input_tensor_a, min=input_specs["min"], memory_config=output_memory_config) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_pytorch2.py new file mode 100644 index 00000000000..7c55b5430f6 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_pytorch2.py @@ -0,0 +1,123 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes, gen_low_high_scalars +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [0, 1], "max": 4.135166556742356}, + {"shape": [0, 2], "min": 0, "max": 1066}, + {"shape": [0, 2], "min": 0, "max": 800}, + {"shape": [1, 1, 1, 42], "min": 0, "max": 82}, + {"shape": [1, 1, 32, 1], "min": 0, "max": 49}, + {"shape": [1066], "min": 0.0}, + {"shape": [1066], "max": 639}, + {"shape": [12, 1, 1], "max": 4.605170185988092}, + {"shape": [120], "min": 0.0}, + {"shape": [120], "max": 59}, + {"shape": [128], "min": 0.0}, + {"shape": [128], "max": 127}, + {"shape": [128], "max": 15}, + {"shape": [128], "max": 31}, + {"shape": [128], "max": 63}, + {"shape": [16, 1, 1], "max": 4.605170185988092}, + {"shape": [160], "min": 0.0}, + {"shape": [160], "max": 79}, + {"shape": [24, 1, 1], "max": 4.605170185988092}, + {"shape": [240], "min": 0.0}, + {"shape": [240], "max": 119}, + {"shape": [3, 1, 1], "max": 4.605170185988092}, + {"shape": [300], "min": 0.0}, + {"shape": [300], "max": 479}, + {"shape": [300], "max": 639}, + {"shape": [30], "min": 0.0}, + {"shape": [30], "max": 14}, + {"shape": [32, 1, 1], "max": 4.605170185988092}, + {"shape": [320], "min": 0.0}, + {"shape": [320], "max": 159}, + {"shape": [320], "max": 319}, + {"shape": [320], "max": 479}, + {"shape": [320], "max": 639}, + {"shape": [3234, 1], "max": 4.135166556742356}, + {"shape": [3234, 2], "min": 0, "max": 320}, + {"shape": [4, 1, 1], "max": 4.605170185988092}, + {"shape": [4, 2], "min": 0, "max": 1}, + {"shape": [40], "min": 0.0}, + {"shape": [40], "max": 19}, + {"shape": [480], "min": 0.0}, + {"shape": [480], "max": 239}, + {"shape": [6, 1, 1], "max": 4.605170185988092}, + {"shape": [6, 2], "min": 0, "max": 1}, + {"shape": [60], "min": 0.0}, + {"shape": [60], "max": 29}, + {"shape": [640], "min": 0.0}, + {"shape": [640], "max": 319}, + {"shape": [8, 1, 1], "max": 4.605170185988092}, + {"shape": [800], "min": 0.0}, + {"shape": [800], "max": 479}, + {"shape": [80], "min": 0.0}, + {"shape": [80], "max": 39}, + {"shape": [8732, 1], "max": 4.135166556742356}, + {"shape": [8732, 2], "min": 0, "max": 300}, + ], + "input_a_dtype": [ttnn.bfloat16], + "input_a_layout": [ttnn.TILE_LAYOUT], + "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_a_dtype, + input_a_layout, + input_a_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_specs["shape"]) + + min_val = input_specs.get("min", None) + max_val = input_specs.get("max", None) + + golden_function = ttnn.get_golden_function(ttnn.clamp) + torch_output_tensor = golden_function(torch_input_tensor_a, min_val, max_val) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + start_time = start_measuring_time() + result = ttnn.clamp(input_tensor_a, min=min_val, max=max_val, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/hardswish/hardswish_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/hardswish/hardswish_pytorch2.py new file mode 100644 index 00000000000..6231caf6860 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/hardswish/hardswish_pytorch2.py @@ -0,0 +1,93 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes, gen_low_high_scalars +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_shape": [ + [1, 1024], + [1, 120, 14, 14], + [1, 1280], + [1, 144, 14, 14], + [1, 16, 112, 112], + [1, 16, 160, 160], + [1, 184, 14, 14], + [1, 184, 20, 20], + [1, 200, 14, 14], + [1, 200, 20, 20], + [1, 240, 14, 14], + [1, 240, 20, 20], + [1, 240, 28, 28], + [1, 240, 40, 40], + [1, 288, 14, 14], + [1, 288, 7, 7], + [1, 480, 10, 10], + [1, 480, 14, 14], + [1, 480, 20, 20], + [1, 576, 7, 7], + [1, 672, 10, 10], + [1, 672, 14, 14], + [1, 672, 20, 20], + [1, 672, 7, 7], + [1, 96, 14, 14], + [1, 96, 28, 28], + [1, 960, 7, 7], + ], + "input_dtype": [ttnn.bfloat16], + "input_layout": [ttnn.TILE_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_shape, + input_dtype, + input_layout, + input_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.hardswish) + torch_output_tensor = golden_function(torch_input_tensor_a) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_dtype, + layout=input_layout, + device=device, + memory_config=input_memory_config, + ) + + start_time = start_measuring_time() + result = ttnn.hardswish(input_tensor_a, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/hardtanh/hardtanh_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/hardtanh/hardtanh_pytorch2.py new file mode 100644 index 00000000000..18df2b70287 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/hardtanh/hardtanh_pytorch2.py @@ -0,0 +1,181 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes, gen_low_high_scalars +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_specs": [ + {"shape": [1, 1024, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1152, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1152, 8, 8], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 116, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1248, 9, 9], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 128, 1, 1], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 128, 2, 2], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 128, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 128, 3, 3], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 128, 5, 5], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 128, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1280, 10, 10], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1280, 12, 12], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1280, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1280, 8, 8], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1280, 9, 9], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 134, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1392, 10, 10], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 14, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 150, 150], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 190, 190], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 30, 30], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 33, 33], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 60, 60], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 65, 65], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 75, 75], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 144, 95, 95], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 16, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 160, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 1632, 12, 12], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 168, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 192, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 192, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 192, 38, 38], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 192, 48, 48], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 192, 75, 75], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 192, 95, 95], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 196, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 20, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 24, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 240, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 240, 15, 15], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 240, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 240, 30, 30], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 256, 10, 10], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 256, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 256, 2, 2], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 256, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 256, 3, 3], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 256, 5, 5], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 272, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 28, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 288, 17, 17], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 288, 19, 19], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 288, 33, 33], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 288, 38, 38], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 32, 112, 112], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 32, 120, 120], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 32, 130, 130], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 32, 150, 150], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 32, 190, 190], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 320, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 334, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 336, 24, 24], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 336, 48, 48], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 34, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 384, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 40, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 40, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 46, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 462, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 480, 10, 10], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 480, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 480, 15, 15], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 512, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 512, 5, 5], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 512, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 528, 17, 17], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 576, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 576, 19, 19], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 576, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 58, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 64, 1, 1], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 64, 112, 112], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 64, 2, 2], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 64, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 640, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 672, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 672, 15, 15], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 672, 20, 20], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 672, 24, 24], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 672, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 672, 8, 8], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 68, 14, 14], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 68, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 720, 17, 17], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 720, 9, 9], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 78, 28, 28], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 816, 10, 10], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 816, 19, 19], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 96, 112, 112], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 96, 120, 120], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 96, 130, 130], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 96, 56, 56], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 96, 60, 60], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 96, 65, 65], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 960, 12, 12], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 960, 24, 24], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 960, 7, 7], "min_val": 0.0, "max_val": 6.0}, + {"shape": [1, 98, 28, 28], "min_val": 0.0, "max_val": 6.0}, + ], + "input_dtype": [ttnn.bfloat16], + "input_layout": [ttnn.TILE_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_specs, + input_dtype, + input_layout, + input_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype + )((input_specs["shape"])) + + min_val = input_specs.get("min_val") + max_val = input_specs.get("max_val") + + golden_function = ttnn.get_golden_function(ttnn.hardtanh) + torch_output_tensor = golden_function(torch_input_tensor_a, min=min_val, max=max_val) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_dtype, + layout=input_layout, + device=device, + memory_config=input_memory_config, + ) + + start_time = start_measuring_time() + result = ttnn.hardtanh(input_tensor_a, min=min_val, max=max_val, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/logical_not/logical_not_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/logical_not/logical_not_pytorch2.py new file mode 100644 index 00000000000..2f3f95d8038 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/logical_not/logical_not_pytorch2.py @@ -0,0 +1,67 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_shape": [ + [7, 7], + ], + "input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_shape, + input_dtype, + input_layout, + input_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.logical_not) + torch_output_tensor = golden_function(torch_input_tensor_a) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_dtype, + layout=input_layout, + device=device, + memory_config=input_memory_config, + ) + + start_time = start_measuring_time() + result = ttnn.logical_not(input_tensor_a, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/neg/neg_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/neg/neg_pytorch2.py new file mode 100644 index 00000000000..fd6d1126902 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/neg/neg_pytorch2.py @@ -0,0 +1,74 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import torch +import random +import ttnn +from tests.sweep_framework.utils import gen_shapes +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt + +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 = { + "nightly": { + "input_shape": [ + [1, 1, 16, 16], + [1, 1, 7, 32], + [1, 1], + [1, 5, 16, 16], + [1, 71, 7, 32], + [17, 17], + [2, 2], + # [s0 + 1, s0 + 1] + ], + "input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + }, +} + + +def run( + input_shape, + input_dtype, + input_layout, + input_memory_config, + output_memory_config, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.neg) + torch_output_tensor = golden_function(torch_input_tensor_a) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_dtype, + layout=input_layout, + device=device, + memory_config=input_memory_config, + ) + + start_time = start_measuring_time() + result = ttnn.neg(input_tensor_a, memory_config=output_memory_config) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf]