From 76c7789c4096ddfcc52b8b278e76e2c0e1e0bd18 Mon Sep 17 00:00:00 2001 From: Kalaivani Baskar <156762498+KalaivaniMCW@users.noreply.github.com> Date: Thu, 10 Oct 2024 08:39:08 +0530 Subject: [PATCH] #13408: Pytorch tracing sweeps - eltwise (#13437) #13408: Pytorch sweeps set 1 --- .github/workflows/ttnn-run-sweeps.yaml | 18 + .../eltwise/binary/add/add_all_pytorch2.py | 593 ++++++++++++++++++ .../eltwise/binary/eq/eq_scalar_pytorch2.py | 89 +++ .../floor_divide/floor_divide_pytorch2.py | 97 +++ .../eltwise/binary/gt/gt_scalar_pytorch2.py | 80 +++ .../eltwise/binary/le/le_tensor_pytorch2.py | 88 +++ .../binary/multiply/mul_tensor_pytorch2.py | 472 ++++++++++++++ .../remainder/remainder_scalar_pytorch2.py | 78 +++ .../sweeps/eltwise/unary/abs/abs_pytorch2.py | 76 +++ .../unary/bitwise/bitwise_not_pytorch2.py | 82 +++ .../eltwise/unary/ceil/ceil_pytorch2.py | 81 +++ .../sweeps/eltwise/unary/cos/cos_pytorch2.py | 73 +++ .../sweeps/eltwise/unary/elu/elu_pytorch2.py | 77 +++ .../sweeps/eltwise/unary/exp/exp_pytorch2.py | 87 +++ .../eltwise/unary/floor/floor_pytorch2.py | 82 +++ .../eltwise/unary/gelu/gelu_pytorch2.py | 129 ++++ .../unary/hardsigmoid/hardsigmoid_pytorch2.py | 89 +++ .../unary/leaky_relu/leaky_relu_pytorch2.py | 95 +++ .../sweeps/eltwise/unary/log/log_pytorch2.py | 73 +++ .../unit_testing/misc/test_unary_ops_ttnn.py | 25 +- .../{ => eltwise}/test_activation.py | 38 +- .../operations/eltwise/unary/unary_pybind.hpp | 2 +- ttnn/ttnn/operations/unary.py | 22 +- 23 files changed, 2515 insertions(+), 31 deletions(-) create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/add/add_all_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/eq/eq_scalar_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/floor_divide/floor_divide_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/gt/gt_scalar_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/le/le_tensor_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/multiply/mul_tensor_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/binary/remainder/remainder_scalar_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/abs/abs_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/bitwise/bitwise_not_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/ceil/ceil_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/cos/cos_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/elu/elu_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/exp/exp_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/floor/floor_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/gelu/gelu_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/hardsigmoid/hardsigmoid_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/leaky_relu/leaky_relu_pytorch2.py create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/log/log_pytorch2.py rename tests/ttnn/unit_tests/operations/{ => eltwise}/test_activation.py (88%) diff --git a/.github/workflows/ttnn-run-sweeps.yaml b/.github/workflows/ttnn-run-sweeps.yaml index e15b7880d44..d234535b80f 100644 --- a/.github/workflows/ttnn-run-sweeps.yaml +++ b/.github/workflows/ttnn-run-sweeps.yaml @@ -13,10 +13,15 @@ on: - add - ccl.line_all_gather - ccl.all_gather_n300 + - eltwise.unary.abs.abs_pytorch2 - eltwise.unary.relu.relu - eltwise.unary.relu.relu_pytorch2 - eltwise.unary.gelu.gelu + - eltwise.unary.gelu.gelu_pytorch2 + - eltwise.unary.hardsigmoid.hardsigmoid_pytorch2 + - eltwise.unary.leaky_relu.leaky_relu_pytorch2 - eltwise.unary.cos.cos + - eltwise.unary.cos.cos_pytorch2 - eltwise.unary.sin.sin - eltwise.unary.sin.sin_pytorch2 - eltwise.unary.tril.tril_pytorch2 @@ -29,12 +34,16 @@ on: - eltwise.unary.rdiv.rdiv - eltwise.unary.frac.frac - eltwise.unary.ceil.ceil + - eltwise.unary.ceil.ceil_pytorch2 - eltwise.unary.trunc.trunc - eltwise.unary.floor.floor + - eltwise.unary.floor.floor_pytorch2 - eltwise.unary.clone.clone - eltwise.unary.elu.elu + - eltwise.unary.elu.elu_pytorch2 - eltwise.unary.erfc.erfc - eltwise.unary.exp.exp + - eltwise.unary.exp.exp_pytorch2 - eltwise.unary.exp2.exp2 - eltwise.unary.expm1.expm1 - eltwise.unary.tanh.tanh @@ -44,12 +53,14 @@ on: - eltwise.unary.deg2rad.deg2rad - eltwise.unary.relu6.relu6 - eltwise.unary.log.log + - eltwise.unary.log.log_pytorch2 - eltwise.unary.log1p.log1p - eltwise.unary.log2.log2 - eltwise.unary.log10.log10 - eltwise.unary.bitwise.bitwise_and - eltwise.unary.bitwise.bitwise_left_shift - eltwise.unary.bitwise.bitwise_not + - eltwise.unary.bitwise.bitwise_not_pytorch2 - eltwise.unary.bitwise.bitwise_or - eltwise.unary.bitwise.bitwise_right_shift - eltwise.unary.bitwise.bitwise_xor @@ -99,8 +110,10 @@ on: - eltwise.unary.isnan - eltwise.unary.isneginf - eltwise.unary.isposinf + - eltwise.binary.add.add_all_pytorch2 - eltwise.binary.subtract.subtract - eltwise.binary.multiply.multiply + - eltwise.binary.multiply.mul_tensor_pytorch2 - eltwise.binary.div.div - eltwise.binary.div_no_nan.div_no_nan - eltwise.binary.logical_or.logical_or_ @@ -115,9 +128,14 @@ on: - eltwise.binary.remainder.remainder - eltwise.binary.squared_difference.squared_difference - eltwise.binary.squared_difference_output.squared_difference_output + - eltwise.binary.remainder.remainder_scalar_pytorch2 - eltwise.binary.bcast.bcast_h_sharded - eltwise.binary.bcast.bcast + - eltwise.binary.eq.eq_scalar_pytorch2 + - eltwise.binary.gt.gt_scalar_pytorch2 + - eltwise.binary.le.le_tensor_pytorch2 - eltwise.binary.fmod.fmod + - eltwise.binary.floor_divide.floor_divide_pytorch2 - eltwise.binary.logaddexp.logaddexp - eltwise.binary.ldexp.ldexp - eltwise.binary.hypot.hypot diff --git a/tests/sweep_framework/sweeps/eltwise/binary/add/add_all_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/add/add_all_pytorch2.py new file mode 100644 index 00000000000..408f0c117fa --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/add/add_all_pytorch2.py @@ -0,0 +1,593 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + {"self": [0, 1], "other": [0, 1]}, + {"self": [0], "other": [0]}, + {"self": [1, 1, 1024], "other": [1, 1, 1024]}, + {"self": [1, 1, 16, 32], "other": [1, 1, 16, 32]}, + {"self": [1, 1, 3072], "other": [1, 1, 3072]}, + {"self": [1, 1, 4096], "other": [1, 1, 4096]}, + {"self": [1, 1, 512], "other": [1, 1, 512]}, + {"self": [1, 1, 7, 64], "other": [1, 1, 7, 64]}, + {"self": [1, 1, 768], "other": [1, 1, 768]}, + {"self": [1, 1, 768], "other": [1, 768]}, + {"self": [1, 10, 1024], "other": [1, 10, 1024]}, + {"self": [1, 10, 512], "other": [1, 10, 512]}, + {"self": [1, 10, 768], "other": [1, 10, 768]}, + {"self": [1, 1008, 7, 7], "other": [1, 1008, 7, 7]}, + {"self": [1, 1024, 10, 10], "other": [1, 1024, 10, 10]}, + {"self": [1, 1024, 14, 14], "other": [1, 1024, 14, 14]}, + {"self": [1, 1024, 16, 16], "other": [1, 1024, 16, 16]}, + {"self": [1, 1024, 160], "other": [1, 1024, 160]}, + {"self": [1, 1024, 256], "other": [256]}, + {"self": [1, 1024, 45, 80], "other": [1, 1024, 1, 1]}, + {"self": [1, 1024, 45, 80], "other": [1, 1024, 45, 80]}, + {"self": [1, 1024, 50, 68], "other": [1, 1024, 1, 1]}, + {"self": [1, 1024, 50, 68], "other": [1, 1024, 50, 68]}, + {"self": [1, 1024, 640], "other": [1, 1024, 640]}, + {"self": [1, 1024, 7, 7], "other": [1, 1024, 7, 7]}, + {"self": [1, 1024], "other": [1, 1024]}, + {"self": [1, 104, 28, 28], "other": [1, 104, 28, 28]}, + {"self": [1, 1056, 48, 48], "other": [1, 1056, 48, 48]}, + {"self": [1, 112, 14, 14], "other": [1, 112, 14, 14]}, + {"self": [1, 112, 15, 15], "other": [1, 112, 15, 15]}, + {"self": [1, 112, 20, 20], "other": [1, 112, 20, 20]}, + {"self": [1, 112, 24, 24], "other": [1, 112, 24, 24]}, + {"self": [1, 12, 1, 10], "other": [1, 1, 1, 10]}, + {"self": [1, 12, 1, 10], "other": [1, 12, 1, 10]}, + {"self": [1, 12, 1, 1], "other": [1, 1, 1, 1]}, + {"self": [1, 12, 1, 1], "other": [1, 12, 1, 1]}, + {"self": [1, 12, 1, 24], "other": [1, 1, 1, 24]}, + {"self": [1, 12, 1, 2], "other": [1, 1, 1, 2]}, + {"self": [1, 12, 1, 2], "other": [1, 12, 1, 2]}, + {"self": [1, 12, 1, 46], "other": [1, 1, 1, 46]}, + {"self": [1, 12, 10, 10], "other": [1, 1, 1, 10]}, + {"self": [1, 12, 10, 10], "other": [1, 12, 10, 10]}, + {"self": [1, 12, 12, 12], "other": [1, 1, 1, 12]}, + {"self": [1, 12, 128], "other": [1, 12, 128]}, + {"self": [1, 12, 14, 14], "other": [1, 1, 1, 14]}, + {"self": [1, 12, 197, 197], "other": [1, 12, 197, 197]}, + {"self": [1, 12, 201, 201], "other": [1, 1, 1, 201]}, + {"self": [1, 12, 24, 24], "other": [1, 1, 24, 24]}, + {"self": [1, 12, 25, 25], "other": [1, 1, 1, 25]}, + {"self": [1, 12, 3072], "other": [1, 12, 3072]}, + {"self": [1, 12, 45, 45], "other": [1, 1, 45, 45]}, + {"self": [1, 12, 7, 7], "other": [1, 1, 1, 7]}, + {"self": [1, 12, 768], "other": [1, 12, 768]}, + {"self": [1, 12, 9, 9], "other": [1, 1, 1, 9]}, + {"self": [1, 120, 17, 17], "other": [1, 120, 17, 17]}, + {"self": [1, 120, 28, 28], "other": [1, 120, 28, 28]}, + {"self": [1, 1200, 320], "other": [1, 1200, 320]}, + {"self": [1, 1232, 14, 14], "other": [1, 1232, 14, 14]}, + {"self": [1, 128, 100, 136], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 128, 128], "other": [1, 128, 128, 128]}, + {"self": [1, 128, 1536], "other": [1, 128, 1536]}, + {"self": [1, 128, 180, 320], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 200, 272], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 28, 28], "other": [1, 128, 28, 28]}, + {"self": [1, 128, 56, 56], "other": [1, 128, 56, 56]}, + {"self": [1, 128, 75, 75], "other": [1, 128, 75, 75]}, + {"self": [1, 128, 90, 160], "other": [1, 128, 1, 1]}, + {"self": [1, 1280, 16, 16], "other": [1, 1280, 1, 1]}, + {"self": [1, 1280, 16, 16], "other": [1, 1280, 16, 16]}, + {"self": [1, 1280, 8, 8], "other": [1, 1280, 1, 1]}, + {"self": [1, 1280, 8, 8], "other": [1, 1280, 8, 8]}, + {"self": [1, 1344, 14, 14], "other": [1, 1344, 14, 14]}, + {"self": [1, 136, 19, 19], "other": [1, 136, 19, 19]}, + {"self": [1, 1370, 1280], "other": [1, 1370, 1280]}, + {"self": [1, 1392, 14, 14], "other": [1, 1392, 14, 14]}, + {"self": [1, 14, 128], "other": [1, 14, 128]}, + {"self": [1, 14, 14, 384], "other": [1, 14, 14, 384]}, + {"self": [1, 14, 14, 512], "other": [1, 14, 14, 512]}, + {"self": [1, 14, 3072], "other": [1, 14, 3072]}, + {"self": [1, 14, 768], "other": [1, 14, 768]}, + {"self": [1, 144, 28, 28], "other": [1, 144, 28, 28]}, + {"self": [1, 144, 7, 7], "other": [1, 144, 7, 7]}, + {"self": [1, 1445, 192], "other": [1, 1445, 192]}, + {"self": [1, 15, 1024], "other": [1, 15, 1024]}, + {"self": [1, 15, 512], "other": [1, 15, 512]}, + {"self": [1, 1500, 768], "other": [1, 1500, 768]}, + {"self": [1, 1500, 768], "other": [1500, 768]}, + {"self": [1, 1512, 7, 7], "other": [1, 1512, 7, 7]}, + {"self": [1, 16, 1, 10], "other": [1, 1, 1, 10]}, + {"self": [1, 16, 1, 10], "other": [1, 16, 1, 10]}, + {"self": [1, 16, 1, 1], "other": [1, 1, 1, 1]}, + {"self": [1, 16, 1, 1], "other": [1, 16, 1, 1]}, + {"self": [1, 16, 1, 2], "other": [1, 1, 1, 2]}, + {"self": [1, 16, 1, 2], "other": [1, 16, 1, 2]}, + {"self": [1, 16, 1, 60], "other": [1, 1, 1, 60]}, + {"self": [1, 16, 1, 6], "other": [1, 1, 1, 6]}, + {"self": [1, 16, 10, 10], "other": [1, 1, 1, 10]}, + {"self": [1, 16, 10, 10], "other": [1, 16, 10, 10]}, + {"self": [1, 16, 112, 112], "other": [1, 16, 112, 112]}, + {"self": [1, 16, 16, 384], "other": [1, 16, 16, 384]}, + {"self": [1, 16, 16, 512], "other": [1, 16, 16, 512]}, + {"self": [1, 16, 160, 160], "other": [1, 16, 160, 160]}, + {"self": [1, 16, 19, 19], "other": [1, 1, 19, 19]}, + {"self": [1, 16, 197, 197], "other": [1, 16, 197, 197]}, + {"self": [1, 16, 256, 256], "other": [1, 1, 1, 256]}, + {"self": [1, 16, 5, 5], "other": [1, 1, 1, 5]}, + {"self": [1, 16, 59, 59], "other": [1, 1, 59, 59]}, + {"self": [1, 16, 6, 49, 49], "other": [1, 16, 1, 49, 49]}, + {"self": [1, 16, 6, 64, 64], "other": [1, 16, 1, 64, 64]}, + {"self": [1, 16, 768], "other": [1, 16, 768]}, + {"self": [1, 16, 8, 49, 49], "other": [1, 16, 1, 49, 49]}, + {"self": [1, 16, 8, 64, 64], "other": [1, 16, 1, 64, 64]}, + {"self": [1, 16, 9, 9], "other": [1, 1, 1, 9]}, + {"self": [1, 160, 14, 14], "other": [1, 160, 14, 14]}, + {"self": [1, 160, 24, 24], "other": [1, 160, 24, 24]}, + {"self": [1, 160, 7, 7], "other": [1, 160, 7, 7]}, + {"self": [1, 16384, 256], "other": [256]}, + {"self": [1, 16384, 32], "other": [1, 16384, 32]}, + {"self": [1, 168, 28, 28], "other": [1, 168, 28, 28]}, + {"self": [1, 18, 56, 56], "other": [1, 18, 56, 56]}, + {"self": [1, 19, 1024], "other": [1, 19, 1024]}, + {"self": [1, 192, 28, 28], "other": [1, 192, 28, 28]}, + {"self": [1, 192, 32, 42], "other": [1, 192, 32, 42]}, + {"self": [1, 192, 7, 7], "other": [1, 192, 7, 7]}, + {"self": [1, 192, 8, 8], "other": [1, 192, 8, 8]}, + {"self": [1, 1920, 7, 7], "other": [1, 1920, 7, 7]}, + {"self": [1, 19200, 64], "other": [1, 19200, 64]}, + {"self": [1, 193, 768], "other": [1, 193, 768]}, + {"self": [1, 196, 768], "other": [1, 196, 768]}, + {"self": [1, 197, 1024], "other": [1, 197, 1024]}, + {"self": [1, 197, 768], "other": [1, 197, 768]}, + {"self": [1, 201, 768], "other": [1, 201, 768]}, + {"self": [1, 2016, 7, 7], "other": [1, 2016, 7, 7]}, + {"self": [1, 2048, 23, 40], "other": [1, 2048, 1, 1]}, + {"self": [1, 2048, 23, 40], "other": [1, 2048, 23, 40]}, + {"self": [1, 2048, 25, 34], "other": [1, 2048, 1, 1]}, + {"self": [1, 2048, 25, 34], "other": [1, 2048, 25, 34]}, + {"self": [1, 2048, 7, 7], "other": [1, 2048, 7, 7]}, + {"self": [1, 2048, 768], "other": [1, 2048, 768]}, + {"self": [1, 2048, 768], "other": [2048, 768]}, + {"self": [1, 208, 14, 14], "other": [1, 208, 14, 14]}, + {"self": [1, 208, 9, 9], "other": [1, 208, 9, 9]}, + {"self": [1, 216, 28, 28], "other": [1, 216, 28, 28]}, + {"self": [1, 224, 56, 56], "other": [1, 224, 56, 56]}, + {"self": [1, 232, 10, 10], "other": [1, 232, 10, 10]}, + {"self": [1, 232, 56, 56], "other": [1, 232, 56, 56]}, + {"self": [1, 24, 28, 28], "other": [1, 24, 28, 28]}, + {"self": [1, 24, 49, 49], "other": [1, 24, 49, 49]}, + {"self": [1, 24, 56, 56], "other": [1, 24, 56, 56]}, + {"self": [1, 24, 60, 60], "other": [1, 24, 60, 60]}, + {"self": [1, 24, 64, 64], "other": [1, 24, 64, 64]}, + {"self": [1, 24, 65, 65], "other": [1, 24, 65, 65]}, + {"self": [1, 24, 768], "other": [1, 24, 768]}, + {"self": [1, 24, 80, 80], "other": [1, 24, 80, 80]}, + {"self": [1, 240, 28, 28], "other": [1, 240, 28, 28]}, + {"self": [1, 25, 768], "other": [1, 25, 768]}, + {"self": [1, 2520, 7, 7], "other": [1, 2520, 7, 7]}, + {"self": [1, 256, 100, 136], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 100, 136], "other": [1, 256, 100, 136]}, + {"self": [1, 256, 1024], "other": [1, 256, 1024]}, + {"self": [1, 256, 128, 128], "other": [1, 256, 128, 128]}, + {"self": [1, 256, 1280], "other": [1, 256, 1280]}, + {"self": [1, 256, 14, 14], "other": [1, 256, 14, 14]}, + {"self": [1, 256, 180, 320], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 180, 320], "other": [1, 256, 180, 320]}, + {"self": [1, 256, 200, 272], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 200, 272], "other": [1, 256, 200, 272]}, + {"self": [1, 256, 256], "other": [1, 256, 256]}, + {"self": [1, 256, 256], "other": [256]}, + {"self": [1, 256, 28, 28], "other": [1, 256, 28, 28]}, + {"self": [1, 256, 38, 38], "other": [1, 256, 38, 38]}, + {"self": [1, 256, 384], "other": [1, 256, 384]}, + {"self": [1, 256, 45, 80], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 50, 68], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 50, 68], "other": [1, 256, 50, 68]}, + {"self": [1, 256, 512], "other": [1, 256, 512]}, + {"self": [1, 256, 56, 56], "other": [1, 256, 56, 56]}, + {"self": [1, 256, 64, 64], "other": [1, 256, 64, 64]}, + {"self": [1, 256, 75, 75], "other": [1, 256, 75, 75]}, + {"self": [1, 256, 90, 160], "other": [1, 256, 1, 1]}, + {"self": [1, 272, 12, 12], "other": [1, 272, 12, 12]}, + {"self": [1, 28, 28, 192], "other": [1, 28, 28, 192]}, + {"self": [1, 28, 28, 256], "other": [1, 28, 28, 256]}, + {"self": [1, 288, 14, 14], "other": [1, 288, 14, 14]}, + {"self": [1, 2904, 24, 24], "other": [1, 2904, 24, 24]}, + {"self": [1, 3, 16, 16, 2], "other": [1, 3, 16, 16, 2]}, + {"self": [1, 3, 300, 300], "other": [1, 3, 300, 300]}, + {"self": [1, 3, 32, 32, 2], "other": [1, 3, 32, 32, 2]}, + {"self": [1, 3, 320, 320], "other": [1, 3, 320, 320]}, + {"self": [1, 3, 64, 64, 2], "other": [1, 3, 64, 64, 2]}, + {"self": [1, 3, 800, 1066], "other": [1, 3, 800, 1066]}, + {"self": [1, 300, 512], "other": [1, 300, 512]}, + {"self": [1, 3024, 7, 7], "other": [1, 3024, 7, 7]}, + {"self": [1, 32, 1536], "other": [1, 32, 1536]}, + {"self": [1, 32, 24576], "other": [1, 32, 24576]}, + {"self": [1, 32, 28, 28], "other": [1, 32, 28, 28]}, + {"self": [1, 32, 32, 192], "other": [1, 32, 32, 192]}, + {"self": [1, 32, 32, 256], "other": [1, 32, 32, 256]}, + {"self": [1, 32, 49, 49], "other": [1, 32, 49, 49]}, + {"self": [1, 32, 56, 56], "other": [1, 32, 56, 56]}, + {"self": [1, 32, 64, 64], "other": [1, 32, 64, 64]}, + {"self": [1, 32, 75, 75], "other": [1, 32, 75, 75]}, + {"self": [1, 32, 95, 95], "other": [1, 32, 95, 95]}, + {"self": [1, 320, 14, 14], "other": [1, 320, 14, 14]}, + {"self": [1, 320, 64, 64], "other": [1, 320, 1, 1]}, + {"self": [1, 320, 64, 64], "other": [1, 320, 64, 64]}, + {"self": [1, 336, 14, 14], "other": [1, 336, 14, 14]}, + {"self": [1, 336, 56, 56], "other": [1, 336, 56, 56]}, + {"self": [1, 36, 28, 28], "other": [1, 36, 28, 28]}, + {"self": [1, 3712, 7, 7], "other": [1, 3712, 7, 7]}, + {"self": [1, 4, 12, 49, 49], "other": [1, 4, 1, 49, 49]}, + {"self": [1, 4, 12, 64, 64], "other": [1, 4, 1, 64, 64]}, + {"self": [1, 4, 16, 49, 49], "other": [1, 4, 1, 49, 49]}, + {"self": [1, 4, 16, 64, 64], "other": [1, 4, 1, 64, 64]}, + {"self": [1, 4, 768], "other": [1, 4, 768]}, + {"self": [1, 4, 768], "other": [4, 768]}, + {"self": [1, 40, 14, 14], "other": [1, 40, 14, 14]}, + {"self": [1, 40, 28, 28], "other": [1, 40, 28, 28]}, + {"self": [1, 40, 30, 30], "other": [1, 40, 30, 30]}, + {"self": [1, 40, 40, 40], "other": [1, 40, 40, 40]}, + {"self": [1, 400, 7, 7], "other": [1, 400, 7, 7]}, + {"self": [1, 408, 14, 14], "other": [1, 408, 14, 14]}, + {"self": [1, 4096, 256], "other": [256]}, + {"self": [1, 4096, 320], "other": [1, 4096, 320]}, + {"self": [1, 4096, 64], "other": [1, 4096, 64]}, + {"self": [1, 432, 14, 14], "other": [1, 432, 14, 14]}, + {"self": [1, 440, 7, 7], "other": [1, 440, 7, 7]}, + {"self": [1, 448, 28, 28], "other": [1, 448, 28, 28]}, + {"self": [1, 45, 3072], "other": [1, 45, 3072]}, + {"self": [1, 45, 768], "other": [1, 45, 768]}, + {"self": [1, 48, 14, 14], "other": [1, 48, 14, 14]}, + {"self": [1, 48, 33, 33], "other": [1, 48, 33, 33]}, + {"self": [1, 48, 38, 38], "other": [1, 48, 38, 38]}, + {"self": [1, 48, 56, 56], "other": [1, 48, 56, 56]}, + {"self": [1, 4800, 128], "other": [1, 4800, 128]}, + {"self": [1, 5, 1024], "other": [1, 5, 1024]}, + {"self": [1, 5, 16, 32], "other": [1, 5, 16, 32]}, + {"self": [1, 5, 4096], "other": [1, 5, 4096]}, + {"self": [1, 50, 1024], "other": [1, 50, 1024]}, + {"self": [1, 50, 768], "other": [1, 50, 768]}, + {"self": [1, 512, 100, 136], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 100, 136], "other": [1, 512, 100, 136]}, + {"self": [1, 512, 14, 14], "other": [1, 512, 14, 14]}, + {"self": [1, 512, 23, 40], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 25, 34], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 28, 28], "other": [1, 512, 28, 28]}, + {"self": [1, 512, 32, 32], "other": [1, 512, 32, 32]}, + {"self": [1, 512, 45, 80], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 50, 68], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 7, 7], "other": [1, 512, 7, 7]}, + {"self": [1, 512, 90, 160], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 90, 160], "other": [1, 512, 90, 160]}, + {"self": [1, 528, 96, 96], "other": [1, 528, 96, 96]}, + {"self": [1, 56, 48, 48], "other": [1, 56, 48, 48]}, + {"self": [1, 56, 56, 128], "other": [1, 56, 56, 128]}, + {"self": [1, 56, 56, 96], "other": [1, 56, 56, 96]}, + {"self": [1, 576, 14, 14], "other": [1, 576, 14, 14]}, + {"self": [1, 59, 1024], "other": [1, 59, 1024]}, + {"self": [1, 6, 1, 15], "other": [1, 1, 1, 15]}, + {"self": [1, 6, 1, 15], "other": [1, 6, 1, 15]}, + {"self": [1, 6, 1, 17], "other": [1, 1, 1, 17]}, + {"self": [1, 6, 1, 17], "other": [1, 6, 1, 17]}, + {"self": [1, 6, 1, 1], "other": [1, 1, 1, 1]}, + {"self": [1, 6, 1, 1], "other": [1, 6, 1, 1]}, + {"self": [1, 6, 1, 2], "other": [1, 1, 1, 2]}, + {"self": [1, 6, 1, 2], "other": [1, 6, 1, 2]}, + {"self": [1, 6, 15, 15], "other": [1, 1, 1, 15]}, + {"self": [1, 6, 15, 15], "other": [1, 6, 15, 15]}, + {"self": [1, 64, 120, 160], "other": [1, 64, 120, 160]}, + {"self": [1, 64, 1280], "other": [1, 64, 1280]}, + {"self": [1, 64, 14, 14], "other": [1, 64, 14, 14]}, + {"self": [1, 64, 180, 320], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 200, 272], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 240, 320], "other": [1, 64, 240, 320]}, + {"self": [1, 64, 256, 256], "other": [1, 64, 256, 256]}, + {"self": [1, 64, 28, 28], "other": [1, 64, 28, 28]}, + {"self": [1, 64, 3, 49, 49], "other": [1, 64, 1, 49, 49]}, + {"self": [1, 64, 3, 64, 64], "other": [1, 64, 1, 64, 64]}, + {"self": [1, 64, 30, 40], "other": [1, 64, 30, 40]}, + {"self": [1, 64, 360, 640], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 4, 49, 49], "other": [1, 64, 1, 49, 49]}, + {"self": [1, 64, 4, 64, 64], "other": [1, 64, 1, 64, 64]}, + {"self": [1, 64, 400, 544], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 480, 640], "other": [1, 64, 480, 640]}, + {"self": [1, 64, 56, 56], "other": [1, 64, 56, 56]}, + {"self": [1, 64, 60, 80], "other": [1, 64, 60, 80]}, + {"self": [1, 64, 6144], "other": [1, 64, 6144]}, + {"self": [1, 64, 64, 128], "other": [1, 64, 64, 128]}, + {"self": [1, 64, 64, 96], "other": [1, 64, 64, 96]}, + {"self": [1, 64, 9, 9], "other": [1, 1, 1, 9]}, + {"self": [1, 640, 32, 32], "other": [1, 640, 1, 1]}, + {"self": [1, 640, 32, 32], "other": [1, 640, 32, 32]}, + {"self": [1, 672, 28, 28], "other": [1, 672, 28, 28]}, + {"self": [1, 672, 7, 7], "other": [1, 672, 7, 7]}, + {"self": [1, 696, 28, 28], "other": [1, 696, 28, 28]}, + {"self": [1, 7, 3072], "other": [1, 7, 3072]}, + {"self": [1, 7, 4544], "other": [1, 7, 4544]}, + {"self": [1, 7, 7, 1024], "other": [1, 7, 7, 1024]}, + {"self": [1, 7, 7, 768], "other": [1, 7, 7, 768]}, + {"self": [1, 7, 768], "other": [1, 7, 768]}, + {"self": [1, 71, 7, 64], "other": [1, 71, 7, 64]}, + {"self": [1, 71, 7, 7], "other": [7, 7]}, + {"self": [1, 72, 14, 14], "other": [1, 72, 14, 14]}, + {"self": [1, 72, 56, 56], "other": [1, 72, 56, 56]}, + {"self": [1, 720, 14, 14], "other": [1, 720, 14, 14]}, + {"self": [1, 728, 19, 19], "other": [1, 728, 19, 19]}, + {"self": [1, 728, 38, 38], "other": [1, 728, 38, 38]}, + {"self": [1, 7392, 12, 12], "other": [1, 7392, 12, 12]}, + {"self": [1, 768, 384], "other": [384]}, + {"self": [1, 784, 7, 7], "other": [1, 784, 7, 7]}, + {"self": [1, 8, 1, 10], "other": [1, 1, 1, 10]}, + {"self": [1, 8, 1, 10], "other": [1, 8, 1, 10]}, + {"self": [1, 8, 1, 1], "other": [1, 1, 1, 1]}, + {"self": [1, 8, 1, 1], "other": [1, 8, 1, 1]}, + {"self": [1, 8, 1, 2], "other": [1, 1, 1, 2]}, + {"self": [1, 8, 1, 2], "other": [1, 8, 1, 2]}, + {"self": [1, 8, 10, 10], "other": [1, 1, 1, 10]}, + {"self": [1, 8, 10, 10], "other": [1, 8, 10, 10]}, + {"self": [1, 8, 256, 2048], "other": [1, 1, 1, 2048]}, + {"self": [1, 8, 768], "other": [1, 8, 768]}, + {"self": [1, 8, 8, 1024], "other": [1, 8, 8, 1024]}, + {"self": [1, 8, 8, 768], "other": [1, 8, 8, 768]}, + {"self": [1, 80, 10, 10], "other": [1, 80, 10, 10]}, + {"self": [1, 80, 14, 14], "other": [1, 80, 14, 14]}, + {"self": [1, 80, 15, 15], "other": [1, 80, 15, 15]}, + {"self": [1, 80, 20, 20], "other": [1, 80, 20, 20]}, + {"self": [1, 80, 56, 56], "other": [1, 80, 56, 56]}, + {"self": [1, 88, 17, 17], "other": [1, 88, 17, 17]}, + {"self": [1, 888, 7, 7], "other": [1, 888, 7, 7]}, + {"self": [1, 896, 14, 14], "other": [1, 896, 14, 14]}, + {"self": [1, 9, 1024], "other": [1, 9, 1024]}, + {"self": [1, 9, 128], "other": [1, 9, 128]}, + {"self": [1, 9, 16384], "other": [1, 9, 16384]}, + {"self": [1, 9, 2048], "other": [1, 9, 2048]}, + {"self": [1, 9, 3072], "other": [1, 9, 3072]}, + {"self": [1, 9, 4096], "other": [1, 9, 4096]}, + {"self": [1, 9, 768], "other": [1, 9, 768]}, + {"self": [1, 9, 8192], "other": [1, 9, 8192]}, + {"self": [1, 912, 7, 7], "other": [1, 912, 7, 7]}, + {"self": [1, 96, 14, 14], "other": [1, 96, 14, 14]}, + {"self": [1, 96, 19, 19], "other": [1, 96, 19, 19]}, + {"self": [1, 96, 56, 56], "other": [1, 96, 56, 56]}, + {"self": [1, 96, 7, 7], "other": [1, 96, 7, 7]}, + {"self": [1, 96, 80], "other": [1, 96, 80]}, + {"self": [10, 10], "other": [10, 10]}, + {"self": [100, 1, 256], "other": [100, 1, 256]}, + {"self": [12, 24, 24], "other": [12, 24, 24]}, + {"self": [13600, 1, 4], "other": [1, 9, 4]}, + {"self": [15, 15], "other": [15, 15]}, + {"self": [16, 6, 49, 49], "other": [1, 6, 49, 49]}, + {"self": [16, 6, 64, 64], "other": [1, 6, 64, 64]}, + {"self": [16, 8, 49, 49], "other": [1, 8, 49, 49]}, + {"self": [16, 8, 64, 64], "other": [1, 8, 64, 64]}, + {"self": [2, 7, 512], "other": [1, 7, 512]}, + {"self": [2, 7, 512], "other": [2, 7, 512]}, + {"self": [2, 8, 7, 7], "other": [2, 1, 7, 7]}, + {"self": [2048, 262], "other": [262]}, + {"self": [221, 1, 4], "other": [1, 9, 4]}, + {"self": [25, 4], "other": [25, 1]}, + {"self": [3234, 1], "other": [3234, 1]}, + {"self": [3234, 2], "other": [3234, 2]}, + {"self": [3234], "other": [3234]}, + {"self": [3400, 1, 4], "other": [1, 9, 4]}, + {"self": [4, 12, 49, 49], "other": [1, 12, 49, 49]}, + {"self": [4, 12, 64, 64], "other": [1, 12, 64, 64]}, + {"self": [4, 16, 49, 49], "other": [1, 16, 49, 49]}, + {"self": [4, 16, 64, 64], "other": [1, 16, 64, 64]}, + {"self": [59, 1024], "other": [59, 1024]}, + {"self": [63, 1, 4], "other": [1, 9, 4]}, + {"self": [64, 3, 49, 49], "other": [1, 3, 49, 49]}, + {"self": [64, 3, 64, 64], "other": [1, 3, 64, 64]}, + {"self": [64, 4, 49, 49], "other": [1, 4, 49, 49]}, + {"self": [64, 4, 64, 64], "other": [1, 4, 64, 64]}, + {"self": [850, 1, 4], "other": [1, 9, 4]}, + {"self": [8732, 1], "other": [8732, 1]}, + {"self": [8732, 2], "other": [8732, 2]}, + {"self": [8732], "other": [8732]}, + {"self": [], "other": []}, + {"self": [920, 1, 256], "other": [256]}, + {"self": [920, 1, 256], "other": [920, 1, 256]}, + {"self": [1, 1, 1, 42], "other": -6.0}, + {"self": [1, 1, 1, 42], "other": 0.5}, + {"self": [1, 1, 1, 42], "other": 1.0}, + {"self": [1, 1, 1, 42], "other": 1.0}, + {"self": [1, 1, 1, 42], "other": 2.0}, + {"self": [1, 1, 1024], "other": 1.0}, + {"self": [1, 1, 1], "other": 1e-06}, + {"self": [1, 1, 224, 224], "other": -0.030000000000000027}, + {"self": [1, 1, 224, 224], "other": -0.08799999999999997}, + {"self": [1, 1, 224, 224], "other": -0.18799999999999994}, + {"self": [1, 1, 3072], "other": 1.0}, + {"self": [1, 1, 32, 1], "other": -6.0}, + {"self": [1, 1, 32, 1], "other": 0.5}, + {"self": [1, 1, 32, 1], "other": 1.0}, + {"self": [1, 1, 32, 1], "other": 1.0}, + {"self": [1, 1, 32, 1], "other": 2.0}, + {"self": [1, 1, 4096], "other": 1.0}, + {"self": [1, 1, 40], "other": 1e-06}, + {"self": [1, 10, 1], "other": 1e-06}, + {"self": [1, 1024, 1, 1], "other": 0.0}, + {"self": [1, 1024, 1, 1], "other": 1e-05}, + {"self": [1, 10], "other": 0.0}, + {"self": [1, 10], "other": 1.0}, + {"self": [1, 12, 3072], "other": 1.0}, + {"self": [1, 128, 1, 1], "other": 0.0}, + {"self": [1, 128, 1, 1], "other": 1e-05}, + {"self": [1, 14, 3072], "other": 1.0}, + {"self": [1, 15, 1024], "other": 1.0}, + {"self": [1, 15, 1], "other": 1e-06}, + {"self": [1, 19], "other": 2.0}, + {"self": [1, 1], "other": 0.0}, + {"self": [1, 1], "other": 16.0}, + {"self": [1, 1], "other": 2.0}, + {"self": [1, 2048, 1, 1], "other": 0.0}, + {"self": [1, 2048, 1, 1], "other": 1e-05}, + {"self": [1, 23, 1], "other": 1e-06}, + {"self": [1, 256, 1, 1], "other": 0.0}, + {"self": [1, 256, 1, 1], "other": 1e-05}, + {"self": [1, 32, 6144], "other": 1.0}, + {"self": [1, 32, 6144], "other": 1.0}, + {"self": [1, 45, 3072], "other": 1.0}, + {"self": [1, 5, 4096], "other": 1.0}, + {"self": [1, 512, 1, 1], "other": 0.0}, + {"self": [1, 512, 1, 1], "other": 1e-05}, + {"self": [1, 59], "other": 2.0}, + {"self": [1, 64, 1, 1], "other": 0.0}, + {"self": [1, 64, 1, 1], "other": 1e-05}, + {"self": [1, 7, 3072], "other": 1.0}, + {"self": [1, 9, 128], "other": 1.0}, + {"self": [1, 9, 16384], "other": 1.0}, + {"self": [1, 9, 3072], "other": 1.0}, + {"self": [1, 9, 4096], "other": 1.0}, + {"self": [1, 9, 8192], "other": 1.0}, + {"self": [10, 10], "other": 0.0}, + {"self": [10, 10], "other": 8.0}, + {"self": [100], "other": 0.0}, + {"self": [1066], "other": 0.5}, + {"self": [10], "other": 0.5}, + {"self": [120], "other": 0.5}, + {"self": [128], "other": 0.5}, + {"self": [12], "other": 0.0}, + {"self": [136], "other": 0.0}, + {"self": [14], "other": 0.0}, + {"self": [15, 15], "other": 0.0}, + {"self": [15, 15], "other": 8.0}, + {"self": [160], "other": 0.5}, + {"self": [16], "other": 0.0}, + {"self": [17, 17], "other": 0.0}, + {"self": [17, 17], "other": 16.0}, + {"self": [19], "other": 0.5}, + {"self": [1], "other": 0.5}, + {"self": [2, 2], "other": 0.0}, + {"self": [2, 2], "other": 16.0}, + {"self": [20], "other": 0.5}, + {"self": [23], "other": 0.0}, + {"self": [24, 24], "other": 160.0}, + {"self": [240], "other": 0.5}, + {"self": [28], "other": 0.0}, + {"self": [2], "other": 0.5}, + {"self": [300], "other": 0.5}, + {"self": [30], "other": 0.5}, + {"self": [320], "other": 0.5}, + {"self": [32], "other": 0.0}, + {"self": [38], "other": 0.5}, + {"self": [3], "other": 0.5}, + {"self": [40], "other": 0.0}, + {"self": [40], "other": 0.5}, + {"self": [480], "other": 0.5}, + {"self": [50], "other": 0.0}, + {"self": [56], "other": 0.0}, + {"self": [5], "other": 0.5}, + {"self": [60], "other": 0.5}, + {"self": [640], "other": 0.5}, + {"self": [64], "other": 0.0}, + {"self": [68], "other": 0.0}, + {"self": [7], "other": 0.0}, + {"self": [800], "other": 0.5}, + {"self": [80], "other": 0.5}, + {"self": [], "other": 1}, + ], + # {"self": [s0 + 1, s0 + 1], "other": 16}, + # {"self": [s0 + 1, s0 + 1], "other": 0}, + # {"self": [1, 16, 1, "s0 + 1"], "other": [1, 1, 1, "s0 + 1"]}, + # {"self": [1, 16, 1, "s0 + 1"], "other": [1, 16, 1, "s0 + 1"]}, + # {"self": [1, 8, 1, "s0 + 1"], "other": [1, 1, 1, "s0 + 1"]}, + # {"self": [1, 8, 1, "s0 + 1"], "other": [1, 8, 1, "s0 + 1"]}, + # {"self": [1, 6, 1, "s0 + 1"], "other": [1, 1, 1, "s0 + 1"]}, + # {"self": [1, 6, 1, "s0 + 1"], "other": [1, 6, 1, "s0 + 1"]}, + # {"self": [1, 12, 1, "s0 + 1"], "other": [1, 1, 1, "s0 + 1"]}, + # {"self": [1, 12, 1, "s0 + 1"], "other": [1, 12, 1, "s0 + 1"]}, + # {"self": [1, 32, "s0", "s1"], "other": [1, 32, "s0", "s1"]}, + # {"self": [1, 12, 1, "s10 + 1"], "other": [1, 1, 1, "s10 + 1"]}, + # {"self": [1, 64, "s1", "s2"], "other": [1, 64, "s1", "s2"]}, + # {"self": [1, 128, "s1", "s2"], "other": [1, 128, "s1", "s2"]}, + # {"self": [1, 16, 1, "s10 + 1"], "other": [1, 1, 1, "s10 + 1"]}, + # {"self": [1, 256, "s1", "s2"], "other": [1, 256, "s1", "s2"]}, + # {"self": [1, "s0", 768], "other": [1, "s0", 768]} + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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["self"]) + + if isinstance(input_shape["other"], list): + torch_input_tensor_b = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_b_dtype + )(input_shape["other"]) + else: + torch_input_tensor_b = torch.tensor(input_shape["other"], dtype=torch.float32) + # torch_input_tensor_b = input_shape["other"] + + golden_function = ttnn.get_golden_function(ttnn.add) + 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, + ) + + # if isinstance(input_shape["other"], list): + 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, + ) + # else: + # input_tensor_b = input_shape["other"] + + start_time = start_measuring_time() + result = ttnn.add(input_tensor_a, input_tensor_b) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, pcc=0.9999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/eq/eq_scalar_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/eq/eq_scalar_pytorch2.py new file mode 100644 index 00000000000..6a8a955225f --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/eq/eq_scalar_pytorch2.py @@ -0,0 +1,89 @@ +# 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 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. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [1, 1, 256], + [1, 16], + [1, 7], + [1, 7], + [16, 49, 49], + [16, 64, 64], + [1], + [1], + [4, 49, 49], + [4, 64, 64], + [64, 49, 49], + [64, 64, 64], + ], + "scalar": [1, 0, 1, 50256, 0, 0, 1, 50256, 0, 0, 0, 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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a mesh_device_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + scalar, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.eq) + torch_output_tensor = golden_function(torch_input_tensor_a, scalar) + + 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.eq(input_tensor_a, scalar, 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/floor_divide/floor_divide_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/floor_divide/floor_divide_pytorch2.py new file mode 100644 index 00000000000..efb9b66b64b --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/floor_divide/floor_divide_pytorch2.py @@ -0,0 +1,97 @@ +# 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 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. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [128], + ], + "scalar": [ + 2, + ], + "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 mesh_device_fixture(): + device = ttnn.open_device(device_id=0) + assert ttnn.device.is_wormhole_b0(device), "This op is available for Wormhole_B0 only" + yield (device, "Wormhole_B0") + ttnn.close_device(device) + del device + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a mesh_device_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + scalar, + 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_shape) + + torch_input_tensor_b = torch.tensor(scalar, dtype=torch.float32) + + golden_function = ttnn.get_golden_function(ttnn.floor_div) + 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_a_dtype, + layout=input_a_layout, + device=device, + memory_config=input_a_memory_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.floor_div(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/gt/gt_scalar_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/gt/gt_scalar_pytorch2.py new file mode 100644 index 00000000000..0910775d42a --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/gt/gt_scalar_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 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. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [10, 10], + [15, 15], + [], + ], + "scalar": [0, 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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a mesh_device_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + scalar, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.gt) + torch_output_tensor = golden_function(torch_input_tensor_a, scalar) + + 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.gt(input_tensor_a, scalar, 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/le/le_tensor_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/le/le_tensor_pytorch2.py new file mode 100644 index 00000000000..d119ced4892 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/le/le_tensor_pytorch2.py @@ -0,0 +1,88 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape_a": [[1, 1, 1]], + "input_shape_b": [[1, 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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +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.le) + 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.le(input_tensor_a, input_tensor_b) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/multiply/mul_tensor_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/multiply/mul_tensor_pytorch2.py new file mode 100644 index 00000000000..37c1414c713 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/multiply/mul_tensor_pytorch2.py @@ -0,0 +1,472 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + {"self": [0], "other": 0.5}, + {"self": [1, 1, 1, 10], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 12], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 14], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 15], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 17], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 1], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 201], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 2048], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 256], "other": -3.3895313892515355e38}, + {"self": [1, 1, 1, 25], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 2], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 42], "other": -0.75}, + {"self": [1, 1, 1, 42], "other": 1.25}, + {"self": [1, 1, 1, 42], "other": 1.9761904761904763}, + {"self": [1, 1, 1, 5], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 6], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1, 7], "other": -3.3895313892515355e38}, + {"self": [1, 1, 1, 8], "other": -3.3895313892515355e38}, + {"self": [1, 1, 1, 9], "other": -3.4028234663852886e38}, + {"self": [1, 1, 1024], "other": 0.03125}, + {"self": [1, 1, 1024], "other": 0.044715}, + {"self": [1, 1, 1024], "other": 0.125}, + {"self": [1, 1, 1024], "other": 0.5}, + {"self": [1, 1, 1024], "other": 0.7978845608028654}, + {"self": [1, 1, 224, 224], "other": 0.448}, + {"self": [1, 1, 224, 224], "other": 0.45}, + {"self": [1, 1, 224, 224], "other": 0.458}, + {"self": [1, 1, 256], "other": 1.0}, + {"self": [1, 1, 3072], "other": 0.044715}, + {"self": [1, 1, 3072], "other": 0.5}, + {"self": [1, 1, 3072], "other": 0.7978845608028654}, + {"self": [1, 1, 32, 1], "other": -0.75}, + {"self": [1, 1, 32, 1], "other": 1.25}, + {"self": [1, 1, 32, 1], "other": 1.5625}, + {"self": [1, 1, 4096], "other": 0.044715}, + {"self": [1, 1, 4096], "other": 0.5}, + {"self": [1, 1, 4096], "other": 0.7978845608028654}, + {"self": [1, 1, 480, 640], "other": 10.0}, + {"self": [1, 1, 512], "other": 0.04419417382415922}, + {"self": [1, 1, 768], "other": 0.03608439182435161}, + {"self": [1, 1, 768], "other": 0.125}, + {"self": [1, 12, 3072], "other": 0.044715}, + {"self": [1, 12, 3072], "other": 0.5}, + {"self": [1, 12, 3072], "other": 0.7978845608028654}, + {"self": [1, 12, 64, 64], "other": 16.0}, + {"self": [1, 14, 3072], "other": 0.044715}, + {"self": [1, 14, 3072], "other": 0.5}, + {"self": [1, 14, 3072], "other": 0.7978845608028654}, + {"self": [1, 15, 1024], "other": 0.044715}, + {"self": [1, 15, 1024], "other": 0.5}, + {"self": [1, 15, 1024], "other": 0.7978845608028654}, + {"self": [1, 16, 64, 64], "other": 16.0}, + {"self": [1, 160], "other": 1.0}, + {"self": [1, 19, 1024], "other": 0.125}, + {"self": [1, 19, 1024], "other": 32.0}, + {"self": [1, 1], "other": 0.0}, + {"self": [1, 1], "other": 16.0}, + {"self": [1, 1], "other": 50258.0}, + {"self": [1, 1], "other": 50259.0}, + {"self": [1, 1], "other": 50359.0}, + {"self": [1, 1], "other": 50363.0}, + {"self": [1, 23, 40], "other": 6.283185307179586}, + {"self": [1, 24, 49, 32], "other": 0.1767766952966369}, + {"self": [1, 24, 64, 64], "other": 16.0}, + {"self": [1, 24, 768], "other": 0.125}, + {"self": [1, 3, 16, 16, 2], "other": 2.0}, + {"self": [1, 3, 32, 32, 2], "other": 2.0}, + {"self": [1, 3, 64, 64, 2], "other": 2.0}, + {"self": [1, 3, 64, 64], "other": 16.0}, + {"self": [1, 32, 49, 32], "other": 0.1767766952966369}, + {"self": [1, 32, 6144], "other": 0.044715}, + {"self": [1, 32, 6144], "other": 0.5}, + {"self": [1, 32, 6144], "other": 0.79788456}, + {"self": [1, 32, 64, 64], "other": 16.0}, + {"self": [1, 4, 64, 64], "other": 16.0}, + {"self": [1, 45, 3072], "other": 0.044715}, + {"self": [1, 45, 3072], "other": 0.5}, + {"self": [1, 45, 3072], "other": 0.7978845608028654}, + {"self": [1, 5, 4096], "other": 0.044715}, + {"self": [1, 5, 4096], "other": 0.5}, + {"self": [1, 5, 4096], "other": 0.7978845608028654}, + {"self": [1, 50, 3072], "other": 1.702}, + {"self": [1, 50, 768], "other": 0.125}, + {"self": [1, 59, 1024], "other": 0.125}, + {"self": [1, 6, 64, 64], "other": 16.0}, + {"self": [1, 7, 3072], "other": 0.044715}, + {"self": [1, 7, 3072], "other": 0.5}, + {"self": [1, 7, 3072], "other": 0.7978845608028654}, + {"self": [1, 8, 64, 64], "other": 16.0}, + {"self": [1, 9, 128], "other": 0.044715}, + {"self": [1, 9, 128], "other": 0.5}, + {"self": [1, 9, 128], "other": 0.7978845608028654}, + {"self": [1, 9, 16384], "other": 0.044715}, + {"self": [1, 9, 16384], "other": 0.5}, + {"self": [1, 9, 16384], "other": 0.7978845608028654}, + {"self": [1, 9, 3072], "other": 0.044715}, + {"self": [1, 9, 3072], "other": 0.5}, + {"self": [1, 9, 3072], "other": 0.7978845608028654}, + {"self": [1, 9, 4096], "other": 0.044715}, + {"self": [1, 9, 4096], "other": 0.5}, + {"self": [1, 9, 4096], "other": 0.7978845608028654}, + {"self": [1, 9, 8192], "other": 0.044715}, + {"self": [1, 9, 8192], "other": 0.5}, + {"self": [1, 9, 8192], "other": 0.7978845608028654}, + {"self": [10, 10], "other": 16.0}, + {"self": [10, 10], "other": 8.0}, + {"self": [100], "other": 0.5}, + {"self": [1066], "other": 0.600375234521576}, + {"self": [120], "other": 0.5}, + {"self": [128], "other": 0.125}, + {"self": [128], "other": 0.25}, + {"self": [128], "other": 0.5}, + {"self": [128], "other": 1.0}, + {"self": [128], "other": 2.0}, + {"self": [12], "other": 32.0}, + {"self": [136], "other": 0.5}, + {"self": [14], "other": 0.5}, + {"self": [15, 15], "other": 16.0}, + {"self": [15, 15], "other": 8.0}, + {"self": [16, 6, 49, 32], "other": 0.1767766952966369}, + {"self": [16, 8, 49, 32], "other": 0.1767766952966369}, + {"self": [160], "other": -9.210340371976184}, + {"self": [160], "other": 0.5}, + {"self": [16], "other": 0.5}, + {"self": [16], "other": 32.0}, + {"self": [17, 17], "other": 16.0}, + {"self": [2, 2], "other": 16.0}, + {"self": [2, 7, 2048], "other": 1.702}, + {"self": [2, 7, 512], "other": 0.125}, + {"self": [23], "other": 31.304347826086957}, + {"self": [240], "other": 0.5}, + {"self": [28], "other": 0.25}, + {"self": [28], "other": 0.5}, + {"self": [300], "other": 1.6}, + {"self": [300], "other": 2.1333333333333333}, + {"self": [30], "other": 0.5}, + {"self": [320], "other": 0.5}, + {"self": [320], "other": 1.0}, + {"self": [320], "other": 1.5}, + {"self": [320], "other": 2.0}, + {"self": [3234, 2], "other": 0.5}, + {"self": [3234], "other": 0.5}, + {"self": [32], "other": 0.5}, + {"self": [4, 12, 49, 32], "other": 0.1767766952966369}, + {"self": [4, 16, 49, 32], "other": 0.1767766952966369}, + {"self": [40], "other": 0.5}, + {"self": [40], "other": 32.0}, + {"self": [480], "other": 0.5}, + {"self": [50], "other": 0.5}, + {"self": [56], "other": 0.125}, + {"self": [56], "other": 0.25}, + {"self": [56], "other": 0.5}, + {"self": [60], "other": 0.5}, + {"self": [64, 3, 49, 32], "other": 0.1767766952966369}, + {"self": [64, 4, 49, 32], "other": 0.1767766952966369}, + {"self": [640], "other": 0.5}, + {"self": [64], "other": 0.5}, + {"self": [68], "other": 0.5}, + {"self": [7], "other": 0.42857142857142855}, + {"self": [800], "other": 0.6}, + {"self": [80], "other": 0.5}, + {"self": [8732, 2], "other": 0.5}, + {"self": [8732], "other": 0.5}, + # vec other + {"self": [0, 1], "other": [0, 1]}, + {"self": [0], "other": []}, + {"self": [1, 1, 1, 17], "other": [1, 1, 1, 17]}, + {"self": [1, 1, 1, 1], "other": [1, 1, 1, 1]}, + {"self": [1, 1, 1, 2], "other": [1, 1, 1, 2]}, + {"self": [1, 1, 1, 42], "other": [1, 1, 1, 42]}, + {"self": [1, 1, 1024], "other": [1, 1, 1024]}, + {"self": [1, 1, 1024], "other": [1, 1, 1]}, + {"self": [1, 1, 16, 32], "other": [1, 1, 1, 32]}, + {"self": [1, 1, 3072], "other": [1, 1, 3072]}, + {"self": [1, 1, 32, 1], "other": [1, 1, 32, 1]}, + {"self": [1, 1, 4096], "other": [1, 1, 4096]}, + {"self": [1, 1, 512], "other": [1, 1, 1]}, + {"self": [1, 1, 7, 64], "other": [1, 1, 7, 64]}, + {"self": [1, 1, 768], "other": [1, 1, 1]}, + {"self": [1, 10, 1024], "other": [1, 10, 1]}, + {"self": [1, 10, 512], "other": [1, 10, 1]}, + {"self": [1, 10, 768], "other": [1, 10, 1]}, + {"self": [1, 1024, 1, 1], "other": [1, 1024, 1, 1]}, + {"self": [1, 1024, 2560], "other": [1, 1024, 2560]}, + {"self": [1, 1024, 45, 80], "other": [1, 1024, 1, 1]}, + {"self": [1, 1024, 50, 68], "other": [1, 1024, 1, 1]}, + {"self": [1, 1024, 7, 7], "other": [1, 1024, 1, 1]}, + {"self": [1, 104, 1, 1], "other": [1, 104, 28, 28]}, + {"self": [1, 1056, 1, 1], "other": [1, 1056, 48, 48]}, + {"self": [1, 10], "other": [1, 10]}, + {"self": [1, 12, 3072], "other": [1, 12, 3072]}, + {"self": [1, 120, 1, 1], "other": [1, 120, 14, 14]}, + {"self": [1, 120, 1, 1], "other": [1, 120, 28, 28]}, + {"self": [1, 120, 1, 1], "other": [1, 120, 40, 40]}, + {"self": [1, 120, 28, 28], "other": [1, 120, 1, 1]}, + {"self": [1, 120, 28, 28], "other": [1, 120, 28, 28]}, + {"self": [1, 1232, 1, 1], "other": [1, 1232, 14, 14]}, + {"self": [1, 128, 1, 1], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 100, 136], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 180, 320], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 200, 272], "other": [1, 128, 1, 1]}, + {"self": [1, 128, 90, 160], "other": [1, 128, 1, 1]}, + {"self": [1, 1392, 1, 1], "other": [1, 1392, 14, 14]}, + {"self": [1, 14, 3072], "other": [1, 14, 3072]}, + {"self": [1, 144, 1, 1], "other": [1, 144, 14, 14]}, + {"self": [1, 144, 1, 1], "other": [1, 144, 28, 28]}, + {"self": [1, 15, 1024], "other": [1, 15, 1024]}, + {"self": [1, 15, 512], "other": [1, 15, 1]}, + {"self": [1, 1512, 1, 1], "other": [1, 1512, 7, 7]}, + {"self": [1, 16, 1, 1], "other": [1, 16, 56, 56]}, + {"self": [1, 184, 14, 14], "other": [1, 184, 14, 14]}, + {"self": [1, 192, 32, 42], "other": [1, 1, 1, 42]}, + {"self": [1, 192, 32, 42], "other": [1, 1, 32, 1]}, + {"self": [1, 1], "other": [1, 160]}, + {"self": [1, 200, 14, 14], "other": [1, 200, 14, 14]}, + {"self": [1, 2016, 1, 1], "other": [1, 2016, 7, 7]}, + {"self": [1, 2048, 1, 1], "other": [1, 2048, 1, 1]}, + {"self": [1, 2048, 23, 40], "other": [1, 2048, 1, 1]}, + {"self": [1, 2048, 25, 34], "other": [1, 2048, 1, 1]}, + {"self": [1, 208, 1, 1], "other": [1, 208, 14, 14]}, + {"self": [1, 216, 1, 1], "other": [1, 216, 28, 28]}, + {"self": [1, 224, 1, 1], "other": [1, 224, 56, 56]}, + {"self": [1, 232, 1, 1], "other": [1, 232, 56, 56]}, + {"self": [1, 24, 64, 64], "other": [24, 1, 1]}, + {"self": [1, 240, 1, 1], "other": [1, 240, 14, 14]}, + {"self": [1, 240, 28, 28], "other": [1, 240, 28, 28]}, + {"self": [1, 256, 1, 1], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 100, 136], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 128, 128], "other": [128, 1]}, + {"self": [1, 256, 128, 128], "other": [128]}, + {"self": [1, 256, 180, 320], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 200, 272], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 45, 80], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 50, 68], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 5120], "other": [1, 256, 5120]}, + {"self": [1, 256, 56, 56], "other": [1, 256, 1, 1]}, + {"self": [1, 256, 90, 160], "other": [1, 256, 1, 1]}, + {"self": [1, 288, 1, 1], "other": [1, 288, 7, 7]}, + {"self": [1, 2904, 1, 1], "other": [1, 2904, 24, 24]}, + {"self": [1, 3, 16, 16, 2], "other": [1, 3, 16, 16, 2]}, + {"self": [1, 3, 16, 16, 2], "other": []}, + {"self": [1, 3, 300, 300], "other": [300, 1]}, + {"self": [1, 3, 300, 300], "other": [300]}, + {"self": [1, 3, 32, 32, 2], "other": [1, 3, 32, 32, 2]}, + {"self": [1, 3, 32, 32, 2], "other": []}, + {"self": [1, 3, 320, 320], "other": [320, 1]}, + {"self": [1, 3, 320, 320], "other": [320]}, + {"self": [1, 3, 64, 64, 2], "other": [1, 3, 64, 64, 2]}, + {"self": [1, 3, 64, 64, 2], "other": []}, + {"self": [1, 3, 800, 1066], "other": [1066]}, + {"self": [1, 3, 800, 1066], "other": [800, 1]}, + {"self": [1, 3024, 1, 1], "other": [1, 3024, 7, 7]}, + {"self": [1, 32, 6144], "other": [1, 32, 6144]}, + {"self": [1, 32, 64, 64], "other": [32, 1, 1]}, + {"self": [1, 320, 1, 1], "other": [1, 320, 14, 14]}, + {"self": [1, 32], "other": [1, 32]}, + {"self": [1, 336, 1, 1], "other": [1, 336, 14, 14]}, + {"self": [1, 3712, 1, 1], "other": [1, 3712, 7, 7]}, + {"self": [1, 4096, 1280], "other": [1, 4096, 1280]}, + {"self": [1, 440, 1, 1], "other": [1, 440, 7, 7]}, + {"self": [1, 448, 1, 1], "other": [1, 448, 28, 28]}, + {"self": [1, 45, 3072], "other": [1, 45, 3072]}, + {"self": [1, 48, 1, 1], "other": [1, 48, 56, 56]}, + {"self": [1, 480, 1, 1], "other": [1, 480, 10, 10]}, + {"self": [1, 480, 1, 1], "other": [1, 480, 14, 14]}, + {"self": [1, 480, 1, 1], "other": [1, 480, 20, 20]}, + {"self": [1, 480, 14, 14], "other": [1, 480, 1, 1]}, + {"self": [1, 480, 14, 14], "other": [1, 480, 14, 14]}, + {"self": [1, 5, 16, 32], "other": [1, 5, 1, 32]}, + {"self": [1, 5, 4096], "other": [1, 5, 4096]}, + {"self": [1, 50, 3072], "other": [1, 50, 3072]}, + {"self": [1, 512, 1, 1], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 1, 1], "other": [1, 512, 38, 38]}, + {"self": [1, 512, 100, 136], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 23, 40], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 25, 34], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 28, 28], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 45, 80], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 50, 68], "other": [1, 512, 1, 1]}, + {"self": [1, 512, 90, 160], "other": [1, 512, 1, 1]}, + {"self": [1, 528, 1, 1], "other": [1, 528, 96, 96]}, + {"self": [1, 576, 1, 1], "other": [1, 576, 14, 14]}, + {"self": [1, 576, 1, 1], "other": [1, 576, 7, 7]}, + {"self": [1, 59], "other": [1, 59]}, + {"self": [1, 60], "other": [1, 60]}, + {"self": [1, 64, 1, 1], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 1, 1], "other": [1, 64, 56, 56]}, + {"self": [1, 64, 120, 160], "other": [1, 1, 120, 160]}, + {"self": [1, 64, 120, 160], "other": [120, 1]}, + {"self": [1, 64, 120, 160], "other": [160]}, + {"self": [1, 64, 180, 320], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 200, 272], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 240, 320], "other": [240, 1]}, + {"self": [1, 64, 240, 320], "other": [320]}, + {"self": [1, 64, 30, 40], "other": [1, 1, 30, 40]}, + {"self": [1, 64, 30, 40], "other": [30, 1]}, + {"self": [1, 64, 30, 40], "other": [40]}, + {"self": [1, 64, 360, 640], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 400, 544], "other": [1, 64, 1, 1]}, + {"self": [1, 64, 480, 640], "other": [480, 1]}, + {"self": [1, 64, 480, 640], "other": [640]}, + {"self": [1, 64, 5120], "other": [1, 64, 5120]}, + {"self": [1, 64, 60, 80], "other": [1, 1, 60, 80]}, + {"self": [1, 64, 60, 80], "other": [60, 1]}, + {"self": [1, 64, 60, 80], "other": [80]}, + {"self": [1, 672, 1, 1], "other": [1, 672, 10, 10]}, + {"self": [1, 672, 1, 1], "other": [1, 672, 14, 14]}, + {"self": [1, 672, 1, 1], "other": [1, 672, 20, 20]}, + {"self": [1, 672, 1, 1], "other": [1, 672, 7, 7]}, + {"self": [1, 672, 14, 14], "other": [1, 672, 1, 1]}, + {"self": [1, 672, 14, 14], "other": [1, 672, 14, 14]}, + {"self": [1, 672, 7, 7], "other": [1, 672, 1, 1]}, + {"self": [1, 696, 1, 1], "other": [1, 696, 28, 28]}, + {"self": [1, 7, 3072], "other": [1, 7, 3072]}, + {"self": [1, 71, 7, 64], "other": [1, 1, 7, 64]}, + {"self": [1, 72, 1, 1], "other": [1, 72, 28, 28]}, + {"self": [1, 72, 1, 1], "other": [1, 72, 40, 40]}, + {"self": [1, 72, 1, 1], "other": [1, 72, 56, 56]}, + {"self": [1, 72, 28, 28], "other": [1, 72, 1, 1]}, + {"self": [1, 72, 56, 56], "other": [1, 72, 56, 56]}, + {"self": [1, 7392, 1, 1], "other": [1, 7392, 12, 12]}, + {"self": [1, 768, 14, 14], "other": [1, 768, 1, 1]}, + {"self": [1, 784, 1, 1], "other": [1, 784, 7, 7]}, + {"self": [1, 888, 1, 1], "other": [1, 888, 7, 7]}, + {"self": [1, 896, 1, 1], "other": [1, 896, 14, 14]}, + {"self": [1, 9, 128], "other": [1, 9, 128]}, + {"self": [1, 9, 16384], "other": [1, 9, 16384]}, + {"self": [1, 9, 3072], "other": [1, 9, 3072]}, + {"self": [1, 9, 4096], "other": [1, 9, 4096]}, + {"self": [1, 9, 8192], "other": [1, 9, 8192]}, + {"self": [1, 96, 1, 1], "other": [1, 96, 14, 14]}, + {"self": [1, 960, 1, 1], "other": [1, 960, 7, 7]}, + {"self": [1, 960, 7, 7], "other": [1, 960, 1, 1]}, + {"self": [1, 960, 7, 7], "other": [1, 960, 7, 7]}, + {"self": [100], "other": []}, + {"self": [1024], "other": [1, 1, 1024]}, + {"self": [1024], "other": [1, 10, 1024]}, + {"self": [1024], "other": [1, 197, 1024]}, + {"self": [12], "other": []}, + {"self": [136], "other": []}, + {"self": [13], "other": []}, + {"self": [16, 1], "other": [1, 1, 32]}, + {"self": [16, 6, 64, 64], "other": [6, 1, 1]}, + {"self": [16, 8, 64, 64], "other": [8, 1, 1]}, + {"self": [17], "other": []}, + {"self": [1], "other": [1]}, + {"self": [2, 1], "other": []}, + {"self": [2, 7, 2048], "other": [2, 7, 2048]}, + {"self": [25], "other": []}, + {"self": [300], "other": []}, + {"self": [3234, 1], "other": [3234, 1]}, + {"self": [3234, 2], "other": [2]}, + {"self": [34], "other": []}, + {"self": [4, 12, 64, 64], "other": [12, 1, 1]}, + {"self": [4, 16, 64, 64], "other": [16, 1, 1]}, + {"self": [50], "other": []}, + {"self": [512], "other": [1, 1, 512]}, + {"self": [512], "other": [1, 10, 512]}, + {"self": [512], "other": [1, 15, 512]}, + {"self": [64, 3, 64, 64], "other": [3, 1, 1]}, + {"self": [64, 4, 64, 64], "other": [4, 1, 1]}, + {"self": [68], "other": []}, + {"self": [768], "other": [1, 1, 768]}, + {"self": [768], "other": [1, 10, 768]}, + {"self": [768], "other": [1, 197, 768]}, + {"self": [7], "other": []}, + {"self": [8732, 1], "other": [8732, 1]}, + {"self": [8732, 2], "other": [2]}, + {"self": [9], "other": []}, + {"self": [], "other": [0, 1]}, + {"self": [], "other": [1, 1, 768]}, + {"self": [], "other": [1, 24, 768]}, + {"self": [], "other": [3234, 1]}, + {"self": [], "other": [8732, 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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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["self"]) + + if isinstance(input_shape["other"], list): + torch_input_tensor_b = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_b_dtype + )(input_shape["other"]) + else: + torch_input_tensor_b = torch.tensor(input_shape["other"], dtype=torch.float32) + # torch_input_tensor_b = input_shape["other"] + + golden_function = ttnn.get_golden_function(ttnn.mul) + 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, + ) + + # if isinstance(input_shape["other"], list): + 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, + ) + # else: + # input_tensor_b = input_shape["other"] + + start_time = start_measuring_time() + result = ttnn.mul(input_tensor_a, input_tensor_b) + output_tensor = ttnn.to_torch(result) + e2e_perf = stop_measuring_time(start_time) + + return [check_with_pcc(torch_output_tensor, output_tensor, pcc=0.99), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/binary/remainder/remainder_scalar_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/binary/remainder/remainder_scalar_pytorch2.py new file mode 100644 index 00000000000..5ac35667ba3 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/binary/remainder/remainder_scalar_pytorch2.py @@ -0,0 +1,78 @@ +# 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 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. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [1], + ], + "scalar": [7], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a mesh_device_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + scalar, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.remainder) + torch_output_tensor = golden_function(torch_input_tensor_a, scalar) + + 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.remainder(input_tensor_a, scalar, 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/unary/abs/abs_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/abs/abs_pytorch2.py new file mode 100644 index 00000000000..0e262cc9980 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/abs/abs_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 +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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [10, 10], + [15, 15], + ], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.abs) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.abs(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/bitwise/bitwise_not_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/bitwise/bitwise_not_pytorch2.py new file mode 100644 index 00000000000..91f5e28af58 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/bitwise/bitwise_not_pytorch2.py @@ -0,0 +1,82 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [[1, 23, 40]], + "input_a_dtype": [ttnn.int32], + "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 mesh_device_fixture(): + device = ttnn.open_device(device_id=0) + assert ttnn.device.is_wormhole_b0(device), "This op is available for Wormhole_B0 only" + yield (device, "Wormhole_B0") + ttnn.close_device(device) + del device + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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=-2147483647, high=2147483648, dtype=torch.int64), input_a_dtype + )(input_shape) + + torch_input_tensor_a = torch.full(size=input_shape, fill_value=-2147483647).to(torch.int32) + + torch_output_tensor = torch.bitwise_not(torch_input_tensor_a) + + 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.bitwise_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/ceil/ceil_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/ceil/ceil_pytorch2.py new file mode 100644 index 00000000000..03fa811c4a1 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/ceil/ceil_pytorch2.py @@ -0,0 +1,81 @@ +# 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, is_wormhole_b0 + +# 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [[1066], [120], [128], [160], [240], [300], [30], [320], [40], [480], [60], [640], [800], [80]], + "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 mesh_device_fixture(): + device = ttnn.open_device(device_id=0) + assert ttnn.device.is_wormhole_b0(device), "This op is available for Wormhole_B0 only" + yield (device, "Wormhole_B0") + ttnn.close_device(device) + del device + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.ceil) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.ceil(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/cos/cos_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/cos/cos_pytorch2.py new file mode 100644 index 00000000000..9cb49e3f023 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/cos/cos_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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [[1, 160], [1, 23, 40, 64]], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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=0, high=6.283185307179586, dtype=torch.float16), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.cos) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.cos(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/elu/elu_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/elu/elu_pytorch2.py new file mode 100644 index 00000000000..b69687ef84a --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/elu/elu_pytorch2.py @@ -0,0 +1,77 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [1, 128, 28, 28], + ], + "alpha": [1.0], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + alpha, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.elu) + torch_output_tensor = golden_function(torch_input_tensor_a, alpha=alpha) + + 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.elu(input_tensor_a, alpha=alpha, 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/exp/exp_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/exp/exp_pytorch2.py new file mode 100644 index 00000000000..90f50db4656 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/exp/exp_pytorch2.py @@ -0,0 +1,87 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [0, 1], + [12, 1, 1], + [16, 1, 1], + [160], + [24, 1, 1], + [3, 1, 1], + [32, 1, 1], + [3234, 1], + [4, 1, 1], + [6, 1, 1], + [8, 1, 1], + [8732, 1], + [], + ], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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=-10, high=10, dtype=torch.float32), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.exp) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.exp(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/floor/floor_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/floor/floor_pytorch2.py new file mode 100644 index 00000000000..e3328020f49 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/floor/floor_pytorch2.py @@ -0,0 +1,82 @@ +# 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, is_wormhole_b0 + +# 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. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [[1, 1, 1, 42], [1, 1, 32, 1]], + "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 mesh_device_fixture(): + device = ttnn.open_device(device_id=0) + assert ttnn.device.is_wormhole_b0(device), "This op is available for Wormhole_B0 only" + yield (device, "Wormhole_B0") + ttnn.close_device(device) + del device + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a mesh_device_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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_shape) + + golden_function = ttnn.get_golden_function(ttnn.floor) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.floor(input_tensor_a, 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/unary/gelu/gelu_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/gelu/gelu_pytorch2.py new file mode 100644 index 00000000000..595c6613e0d --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/gelu/gelu_pytorch2.py @@ -0,0 +1,129 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [1, 1, 3072], + [1, 10, 3072], + [1, 10, 768], + [1, 1024, 2560], + [1, 1024, 512], + [1, 1024, 640], + [1, 1200, 1280], + [1, 1370, 5120], + [1, 14, 14, 1536], + [1, 14, 14, 2048], + [1, 1445, 768], + [1, 1500, 3072], + [1, 1536], + [1, 16, 16, 1536], + [1, 16, 16, 2048], + [1, 16, 3072], + [1, 16384, 128], + [1, 19, 4096], + [1, 19200, 256], + [1, 196, 3072], + [1, 197, 3072], + [1, 197, 4096], + [1, 201, 3072], + [1, 2048, 768], + [1, 24, 3072], + [1, 25, 3072], + [1, 256, 1024], + [1, 256, 1280], + [1, 256, 256], + [1, 256, 4096], + [1, 256, 5120], + [1, 28, 28, 1024], + [1, 28, 28, 768], + [1, 300, 2048], + [1, 32, 32, 1024], + [1, 32, 32, 768], + [1, 4, 3072], + [1, 4096, 1280], + [1, 4096, 256], + [1, 4800, 512], + [1, 50, 3072], + [1, 50, 4096], + [1, 56, 56, 384], + [1, 56, 56, 512], + [1, 64, 5120], + [1, 64, 64, 384], + [1, 64, 64, 512], + [1, 7, 18176], + [1, 7, 7, 3072], + [1, 7, 7, 4096], + [1, 768, 1500], + [1, 768, 3000], + [1, 768, 384], + [1, 8, 8, 3072], + [1, 8, 8, 4096], + ], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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.float16), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.gelu) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.gelu(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/hardsigmoid/hardsigmoid_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/hardsigmoid/hardsigmoid_pytorch2.py new file mode 100644 index 00000000000..cd9266e2bc7 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/hardsigmoid/hardsigmoid_pytorch2.py @@ -0,0 +1,89 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [1, 1024, 1, 1], + [1, 120, 1, 1], + [1, 144, 1, 1], + [1, 16, 1, 1], + [1, 240, 1, 1], + [1, 256, 1, 1], + [1, 288, 1, 1], + [1, 480, 1, 1], + [1, 512, 1, 1], + [1, 576, 1, 1], + [1, 672, 1, 1], + [1, 72, 1, 1], + [1, 768, 1, 1], + [1, 96, 1, 1], + [1, 960, 1, 1], + ], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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.float16), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.hardsigmoid) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.hardsigmoid(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/leaky_relu/leaky_relu_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/leaky_relu/leaky_relu_pytorch2.py new file mode 100644 index 00000000000..5f0078fb17b --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/leaky_relu/leaky_relu_pytorch2.py @@ -0,0 +1,95 @@ +# 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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [ + [1, 1024, 16, 16], + [1, 128, 128, 128], + [1, 128, 1536], + [1, 128, 32, 32], + [1, 128, 64, 64], + [1, 256, 16, 16], + [1, 256, 32, 32], + [1, 256, 384], + [1, 256, 64, 64], + [1, 32, 24576], + [1, 32, 24576], + [1, 32, 256, 256], + [1, 32, 512, 512], + [1, 512, 16, 16], + [1, 512, 32, 32], + [1, 512, 96], + [1, 64, 128, 128], + [1, 64, 256, 256], + [1, 64, 6144], + ], + "negative_slope": [0.1], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + negative_slope, + 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.float16), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.leaky_relu) + torch_output_tensor = golden_function(torch_input_tensor_a, negative_slope=negative_slope) + + 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.leaky_relu(input_tensor_a, negative_slope=negative_slope, 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/log/log_pytorch2.py b/tests/sweep_framework/sweeps/eltwise/unary/log/log_pytorch2.py new file mode 100644 index 00000000000..e53c4b11c7f --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/log/log_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 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") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_shape": [[1, 1], [10, 10], [15, 15], [17, 17], [2, 2]], + "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], + }, +} + + +# This is the run instructions for the test, defined by the developer. +# The run function must take the above-defined parameters as inputs. +# The runner will call this run function with each test vector, and the returned results from this function will be stored. +# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. +def run( + input_shape, + 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=1, high=100, dtype=torch.float32), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.log) + torch_output_tensor = golden_function(torch_input_tensor_a) + + 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.log(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/tt_eager/python_api_testing/unit_testing/misc/test_unary_ops_ttnn.py b/tests/tt_eager/python_api_testing/unit_testing/misc/test_unary_ops_ttnn.py index bda1f32c355..7cf8ea27cfd 100644 --- a/tests/tt_eager/python_api_testing/unit_testing/misc/test_unary_ops_ttnn.py +++ b/tests/tt_eager/python_api_testing/unit_testing/misc/test_unary_ops_ttnn.py @@ -463,34 +463,13 @@ def test_unary_gelu_ttnn(input_shapes, fast_and_approx, device): (torch.Size([1, 3, 320, 384])), ), ) -@pytest.mark.parametrize("negative_slope", [1.0, 5.0, 10.0]) +@pytest.mark.parametrize("negative_slope", [1.0, 5.0, 10.0, 0.1]) def test_unary_leaky_relu_ttnn(input_shapes, negative_slope, device): in_data, input_tensor = data_gen_with_range(input_shapes, -10, 10, device) _, output_tensor = data_gen_with_range(input_shapes, -1, 1, device) cq_id = 0 - ttnn.leaky_relu(input_tensor, slope=negative_slope, output_tensor=output_tensor, queue_id=cq_id) - golden_tensor = torch.nn.functional.leaky_relu(in_data, negative_slope) - - comp_pass = compare_pcc([output_tensor], [golden_tensor]) - assert comp_pass - - -@pytest.mark.parametrize( - "input_shapes", - ( - (torch.Size([1, 1, 32, 32])), - (torch.Size([1, 1, 320, 384])), - (torch.Size([1, 3, 320, 384])), - ), -) -@pytest.mark.parametrize("negative_slope", [1.0, 5.0, 10.0]) -def test_unary_leaky_relu_ttnn(input_shapes, negative_slope, device): - in_data, input_tensor = data_gen_with_range(input_shapes, -10, 10, device) - _, output_tensor = data_gen_with_range(input_shapes, -1, 1, device) - - cq_id = 0 - ttnn.leaky_relu(input_tensor, slope=negative_slope, output_tensor=output_tensor, queue_id=cq_id) + ttnn.leaky_relu(input_tensor, negative_slope=negative_slope, output_tensor=output_tensor, queue_id=cq_id) golden_tensor = torch.nn.functional.leaky_relu(in_data, negative_slope) comp_pass = compare_pcc([output_tensor], [golden_tensor]) diff --git a/tests/ttnn/unit_tests/operations/test_activation.py b/tests/ttnn/unit_tests/operations/eltwise/test_activation.py similarity index 88% rename from tests/ttnn/unit_tests/operations/test_activation.py rename to tests/ttnn/unit_tests/operations/eltwise/test_activation.py index 56eb3293c33..2f3f4b41865 100644 --- a/tests/ttnn/unit_tests/operations/test_activation.py +++ b/tests/ttnn/unit_tests/operations/eltwise/test_activation.py @@ -186,6 +186,38 @@ def torch_prelu(x, *args, weight, **kwargs): return result +def run_activation_test_elu(device, h, w, scalar, ttnn_function, pcc=0.99): + torch.manual_seed(0) + + torch_input_tensor_a = torch.rand((h, w), dtype=torch.bfloat16) + golden_function = ttnn.get_golden_function(ttnn_function) + torch_output_tensor = golden_function(torch_input_tensor_a, alpha=scalar) + + input_tensor_a = ttnn.from_torch(torch_input_tensor_a, layout=ttnn.TILE_LAYOUT, device=device) + + output_tensor = ttnn_function(input_tensor_a, alpha=scalar) + output_tensor = ttnn.to_layout(output_tensor, ttnn.ROW_MAJOR_LAYOUT) + output_tensor = ttnn.from_device(output_tensor) + output_tensor = ttnn.to_torch(output_tensor) + assert_with_pcc(torch_output_tensor, output_tensor, pcc) + + +def run_activation_test_leaky_relu(device, h, w, scalar, ttnn_function, pcc=0.99): + torch.manual_seed(0) + + torch_input_tensor_a = torch.rand((h, w), dtype=torch.bfloat16) + golden_function = ttnn.get_golden_function(ttnn_function) + torch_output_tensor = golden_function(torch_input_tensor_a, negative_slope=scalar) + + input_tensor_a = ttnn.from_torch(torch_input_tensor_a, layout=ttnn.TILE_LAYOUT, device=device) + + output_tensor = ttnn_function(input_tensor_a, negative_slope=scalar) + output_tensor = ttnn.to_layout(output_tensor, ttnn.ROW_MAJOR_LAYOUT) + output_tensor = ttnn.from_device(output_tensor) + output_tensor = ttnn.to_torch(output_tensor) + assert_with_pcc(torch_output_tensor, output_tensor, pcc) + + def run_activation_test_scalarB(device, h, w, scalar, ttnn_function, pcc=0.99): torch.manual_seed(0) @@ -222,7 +254,7 @@ def run_activation_test_scalarB_key(device, h, w, value, ttnn_function, pcc=0.99 @pytest.mark.parametrize("h", [64]) @pytest.mark.parametrize("w", [128]) def test_scalarB_elu(device, h, w, scalar): - run_activation_test_scalarB(device, h, w, scalar, ttnn.elu) + run_activation_test_elu(device, h, w, scalar, ttnn.elu) @pytest.mark.parametrize("alpha", [1, 2.5, 5.0]) @@ -268,11 +300,11 @@ def test_scalarB_heaviside(device, h, w, value): run_activation_test_scalarB_key(device, h, w, value, ttnn.heaviside) -@pytest.mark.parametrize("scalar", [-0.5, 0, 0.5]) +@pytest.mark.parametrize("scalar", [-0.5, 0, 0.1, 0.01, 0.5]) @pytest.mark.parametrize("h", [64]) @pytest.mark.parametrize("w", [128]) def test_scalarB_leaky_relu(device, h, w, scalar): - run_activation_test_scalarB(device, h, w, scalar, ttnn.leaky_relu) + run_activation_test_leaky_relu(device, h, w, scalar, ttnn.leaky_relu) @pytest.mark.parametrize("weight", [-0.5, 1.0, 0.5]) diff --git a/ttnn/cpp/ttnn/operations/eltwise/unary/unary_pybind.hpp b/ttnn/cpp/ttnn/operations/eltwise/unary/unary_pybind.hpp index 763767c0bb7..4a46a796570 100644 --- a/ttnn/cpp/ttnn/operations/eltwise/unary/unary_pybind.hpp +++ b/ttnn/cpp/ttnn/operations/eltwise/unary/unary_pybind.hpp @@ -1449,7 +1449,7 @@ void py_module(py::module& module) { )doc"); detail::bind_unary_operation_with_float_parameter(module, ttnn::heaviside, "value", "The value parameter for the Heaviside function", ""); - detail::bind_unary_operation_with_float_parameter(module, ttnn::leaky_relu, "slope", "The slope parameter for the Leaky ReLU function", ""); + detail::bind_unary_operation_with_float_parameter(module, ttnn::leaky_relu, "negative_slope", "The slope parameter for the Leaky ReLU function", ""); detail::bind_unary_operation_with_float_parameter(module, ttnn::relu_max, "upper_limit", "The max value for ReLU function", "This function caps off the input to a max value and a min value of 0"); detail::bind_unary_operation_with_float_parameter(module, ttnn::relu_min, "lower_limit", "The min value for ReLU function", "This will carry out ReLU operation at min value instead of the standard 0"); diff --git a/ttnn/ttnn/operations/unary.py b/ttnn/ttnn/operations/unary.py index 48d0d9eca5f..c282c2b21b2 100644 --- a/ttnn/ttnn/operations/unary.py +++ b/ttnn/ttnn/operations/unary.py @@ -66,8 +66,6 @@ def _golden_function(input_tensor: ttnn.Tensor, **_): "gelu": torch.nn.functional.gelu, "rsqrt": torch.rsqrt, # Unaries with float parameter - "elu": torch.nn.functional.elu, - "leaky_relu": torch.nn.functional.leaky_relu, # "prelu": torch_prelu, # Alias for leaky_relu. TODO(#8544): implement PReLU properly # Other unaries (composite operations) "softplus": torch.nn.functional.softplus, @@ -151,8 +149,6 @@ def _golden_function(input_tensor: ttnn.Tensor, **_): ttnn.gelu, ttnn.rsqrt, # Unaries with float parameter - ttnn.elu, - ttnn.leaky_relu, # ttnn.prelu, # Alias for leaky_relu. TODO(#8544): implement PReLU properly # Unaries using op_chain ttnn.log_sigmoid, @@ -236,6 +232,24 @@ def _golden_function_pow(input_tensor_a, exponent, *args, **kwargs): ttnn.attach_golden_function(ttnn.pow, golden_function=_golden_function_pow) +def _golden_function_elu(input_tensor_a, *args, alpha=1.0, **kwargs): + import torch + + return torch.nn.functional.elu(input_tensor_a, alpha=alpha) + + +ttnn.attach_golden_function(ttnn.elu, golden_function=_golden_function_elu) + + +def _golden_function_leaky_relu(input_tensor_a, *args, negative_slope=0.01, **kwargs): + import torch + + return torch.nn.functional.leaky_relu(input_tensor_a, negative_slope=negative_slope) + + +ttnn.attach_golden_function(ttnn.leaky_relu, golden_function=_golden_function_leaky_relu) + + def _golden_function_relu_min(input_tensor_a, *args, lower_limit, **kwargs): import torch