-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
002ca3a
commit ca724af
Showing
5 changed files
with
232 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ttnn | ||
from tests.sweep_framework.sweep_utils.utils import gen_shapes | ||
from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt | ||
|
||
from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time | ||
from models.utility_functions import torch_random | ||
|
||
|
||
# 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": gen_shapes([1, 1, 32, 64], [6, 12, 256, 256], [1, 1, 32, 64], 16), | ||
"input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], | ||
"input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], | ||
"input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], | ||
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], | ||
}, | ||
} | ||
|
||
|
||
# Invalidate vector is called during the generation phase where each vector will be passed in. | ||
# If invalidated, the vector will still be stored but will be skipped. | ||
# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid. | ||
def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: | ||
if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: | ||
return True, "Row Major layout is not supported" | ||
return False, None | ||
|
||
|
||
# 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_dtype, | ||
input_layout, | ||
input_memory_config, | ||
output_memory_config, | ||
*, | ||
device, | ||
) -> list: | ||
torch.manual_seed(0) | ||
|
||
torch_input_tensor = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.float16), input_dtype | ||
)(input_shape) | ||
|
||
golden_function = ttnn.get_golden_function(ttnn.geglu) | ||
torch_output_tensor = golden_function(torch_input_tensor, dim=-1) | ||
|
||
input_tensor = ttnn.from_torch( | ||
torch_input_tensor, | ||
dtype=input_dtype, | ||
layout=input_layout, | ||
device=device, | ||
memory_config=input_memory_config, | ||
) | ||
|
||
start_time = start_measuring_time() | ||
result = ttnn.geglu(input_tensor, dim=-1, 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] |
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
76 changes: 76 additions & 0 deletions
76
tests/sweep_framework/sweeps/eltwise/unary/swiglu/swiglu.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,76 @@ | ||
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import Optional, Tuple | ||
from functools import partial | ||
|
||
import torch | ||
import ttnn | ||
from tests.sweep_framework.sweep_utils.utils import gen_shapes | ||
from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt | ||
|
||
from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time | ||
from models.utility_functions import torch_random | ||
|
||
|
||
# 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": gen_shapes([1, 1, 32, 64], [6, 12, 256, 256], [1, 1, 32, 64], 16), | ||
"input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], | ||
"input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], | ||
"input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], | ||
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], | ||
}, | ||
} | ||
|
||
|
||
# Invalidate vector is called during the generation phase where each vector will be passed in. | ||
# If invalidated, the vector will still be stored but will be skipped. | ||
# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid. | ||
def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: | ||
if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: | ||
return True, "Row Major layout is not supported" | ||
return False, None | ||
|
||
|
||
# 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_dtype, | ||
input_layout, | ||
input_memory_config, | ||
output_memory_config, | ||
*, | ||
device, | ||
) -> list: | ||
torch.manual_seed(0) | ||
|
||
torch_input_tensor = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.float16), input_dtype | ||
)(input_shape) | ||
|
||
golden_function = ttnn.get_golden_function(ttnn.swiglu) | ||
torch_output_tensor = golden_function(torch_input_tensor, dim=-1) | ||
|
||
input_tensor = ttnn.from_torch( | ||
torch_input_tensor, | ||
dtype=input_dtype, | ||
layout=input_layout, | ||
device=device, | ||
memory_config=input_memory_config, | ||
) | ||
|
||
start_time = start_measuring_time() | ||
result = ttnn.swiglu(input_tensor, dim=-1, 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] |
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