-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#13373: Add sweep test for tanh_pytorch2
- Loading branch information
1 parent
45ead5e
commit 4f7f1a6
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/sweep_framework/sweeps/eltwise/unary/tanh/tanh_pytorch2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# 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 = { | ||
"tanh_1": { | ||
"input_shape": [ | ||
[1, 1, 1024], | ||
[1, 1, 24576], | ||
[1, 1, 3072], | ||
[1, 1, 4096], | ||
[1, 12, 3072], | ||
[1, 14, 3072], | ||
[1, 15, 1024], | ||
[1, 256, 96], | ||
[1, 32, 6144], | ||
[1, 45, 3072], | ||
[1, 5, 4096], | ||
[1, 7, 3072], | ||
[1, 768], | ||
[1, 9, 128], | ||
[1, 9, 16384], | ||
[1, 9, 3072], | ||
[1, 9, 4096], | ||
[1, 9, 8192], | ||
], | ||
"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, | ||
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_output_tensor = torch.tanh(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.tanh(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] |