-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #11512: Add nonzero sweep and add it to ttnn-run-sweeps.yaml * #11512: Add licence header to nonzero sweep * #11512: Update gen_with_zeroes function
- Loading branch information
1 parent
6624bd3
commit 2c84ace
Showing
3 changed files
with
100 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
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
97 changes: 97 additions & 0 deletions
97
tests/sweep_framework/sweeps/data_movement/nonzero/nonzero.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,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.sweep_utils.utils import gen_shapes, sanitize_shape_rm, gen_with_zeroes | ||
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": gen_shapes([1, 1, 1, 1], [1, 1, 1, 256], [1, 1, 1, 1], 16), | ||
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], | ||
"input_layout": [ttnn.ROW_MAJOR_LAYOUT, ttnn.TILE_LAYOUT], | ||
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], | ||
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
}, | ||
"xfail": { | ||
"input_shape": gen_shapes([1, 1, 1, 1], [1, 1, 1, 256], [1, 1, 1, 1], 16), | ||
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], | ||
"input_layout": [ttnn.ROW_MAJOR_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 invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: | ||
if test_vector["input_layout"] == ttnn.TILE_LAYOUT: | ||
return True, "Input tensor must be in row major layout" | ||
if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT and test_vector["input_a_dtype"] == ttnn.bfloat8_b: | ||
return True, "bfloat8_b is only supported on tiled layout" | ||
return False, None | ||
|
||
|
||
def run( | ||
input_shape, | ||
input_a_dtype, | ||
input_layout, | ||
input_a_memory_config, | ||
output_memory_config, | ||
*, | ||
device, | ||
) -> list: | ||
data_seed = random.randint(0, 20000000) | ||
torch.manual_seed(data_seed) | ||
|
||
if input_layout == ttnn.ROW_MAJOR_LAYOUT: | ||
input_shape = sanitize_shape_rm(input_shape) | ||
|
||
torch_input_tensor_a = gen_func_with_cast_tt( | ||
partial(gen_with_zeroes, probabilityzeroes="random", low=-100, high=100, dtype=torch.float32), input_a_dtype | ||
)(input_shape) | ||
|
||
torch_output_tensor = torch.nonzero(torch_input_tensor_a, as_tuple=False) | ||
torch_num_nonzero = torch_output_tensor.shape[0] | ||
torch_output_tensor = torch_output_tensor[:, 3].reshape(-1, 1) | ||
|
||
input_tensor_a = ttnn.from_torch( | ||
torch_input_tensor_a, | ||
dtype=input_a_dtype, | ||
layout=input_layout, | ||
device=device, | ||
memory_config=input_a_memory_config, | ||
) | ||
|
||
start_time = start_measuring_time() | ||
output_indices, output_tensor = ttnn.nonzero(input_tensor_a, memory_config=output_memory_config) | ||
e2e_perf = stop_measuring_time(start_time) | ||
|
||
num_nonzero = ttnn.to_torch(output_indices)[0, 0, 0, 0].item() | ||
output_tensor = ttnn.to_torch(output_tensor)[0, 0, 0, :num_nonzero].reshape(-1, 1) | ||
|
||
if num_nonzero != torch_num_nonzero: | ||
return [ | ||
(False, f"Expected num of non-zero: {torch_num_nonzero}, actual num of non_zero: {num_nonzero}"), | ||
e2e_perf, | ||
] | ||
|
||
return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] |