-
Notifications
You must be signed in to change notification settings - Fork 88
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
### Ticket #15857 ### Problem description Add forge sweep tests for binary ops ### What's changed Added automation script to generate forge sweep tests for the following ops: - eq - ge - gt - lt - ne - logical_and - logical_or - div - remainder - where ### Checklist - [ ] Post commit CI passes
- Loading branch information
1 parent
aa4ca74
commit 31dca41
Showing
11 changed files
with
1,420 additions
and
1 deletion.
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
265 changes: 265 additions & 0 deletions
265
tests/sweep_framework/sweeps/eltwise/binary/div/div_forge.py
Large diffs are not rendered by default.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
tests/sweep_framework/sweeps/eltwise/binary/eq/eq_forge.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,104 @@ | ||
# 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.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" 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 = { | ||
"xfail": { | ||
"input_shape": [ | ||
{"self": [1, 1, 5, 5], "other": [1], "input_dtype": "ttnn.bfloat16"}, | ||
{"self": [1, 1, 7, 7], "other": [1], "input_dtype": "ttnn.bfloat16"}, | ||
{"self": [1, 45], "other": [1, 45], "input_dtype": "ttnn.int32"}, | ||
{"self": [1, 5], "other": [1, 5], "input_dtype": "ttnn.int32"}, | ||
{"self": [1, 6], "other": [1, 6], "input_dtype": "ttnn.int32"}, | ||
{"self": [1, 7], "other": [1, 7], "input_dtype": "ttnn.int32"}, | ||
], | ||
"input_a_layout": [ttnn.TILE_LAYOUT], | ||
"input_b_layout": [ttnn.TILE_LAYOUT], | ||
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
"input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
"output_memory_config": [ttnn.DRAM_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_a_layout"] == ttnn.ROW_MAJOR_LAYOUT or test_vector["input_b_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 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_layout, | ||
input_b_layout, | ||
input_a_memory_config, | ||
input_b_memory_config, | ||
output_memory_config, | ||
*, | ||
device, | ||
) -> list: | ||
torch.manual_seed(0) | ||
if input_shape["input_dtype"] == "ttnn.bfloat16": | ||
input_dtype = ttnn.bfloat16 | ||
elif input_shape["input_dtype"] == "ttnn.float32": | ||
input_dtype = ttnn.float32 | ||
elif input_shape["input_dtype"] == "ttnn.int32": | ||
input_dtype = ttnn.int32 | ||
|
||
torch_input_tensor_a = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype | ||
)(input_shape["self"]) | ||
torch_input_tensor_b = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype | ||
)(input_shape["other"]) | ||
|
||
golden_function = ttnn.get_golden_function(ttnn.eq) | ||
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_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_dtype, | ||
layout=input_b_layout, | ||
device=device, | ||
memory_config=input_b_memory_config, | ||
) | ||
|
||
start_time = start_measuring_time() | ||
result = ttnn.eq(input_tensor_a, input_tensor_b, memory_config=output_memory_config) | ||
# ToDo: Update it once the tensor layout support with rank < 2 is supported in mid of Jan | ||
output_tensor = ttnn.to_torch(result, torch_rank=len(input_shape["self"])) | ||
e2e_perf = stop_measuring_time(start_time) | ||
|
||
return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] |
103 changes: 103 additions & 0 deletions
103
tests/sweep_framework/sweeps/eltwise/binary/ge/ge_forge.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,103 @@ | ||
# 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.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" 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 = { | ||
"xfail": { | ||
"input_shape": [[1]], | ||
"input_a_dtype": [ttnn.int32], | ||
"input_b_dtype": [ttnn.int32], | ||
"input_a_layout": [ttnn.TILE_LAYOUT], | ||
"input_b_layout": [ttnn.TILE_LAYOUT], | ||
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
"input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
"output_memory_config": [ttnn.DRAM_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 | ||
|
||
|
||
# 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_a_layout"] == ttnn.ROW_MAJOR_LAYOUT or test_vector["input_b_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 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_b_dtype, | ||
input_a_layout, | ||
input_b_layout, | ||
input_a_memory_config, | ||
input_b_memory_config, | ||
output_memory_config, | ||
*, | ||
device, | ||
) -> list: | ||
torch.manual_seed(0) | ||
|
||
torch_input_tensor_a = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.int32), input_a_dtype | ||
)(input_shape) | ||
torch_input_tensor_b = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.int32), input_b_dtype | ||
)(input_shape) | ||
|
||
golden_function = ttnn.get_golden_function(ttnn.ge) | ||
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.ge(input_tensor_a, input_tensor_b, memory_config=output_memory_config) | ||
# ToDo: Update it once the tensor layout support with rank < 2 is supported in mid of Jan | ||
output_tensor = ttnn.to_torch(result, torch_rank=len(input_shape)) | ||
e2e_perf = stop_measuring_time(start_time) | ||
|
||
return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] |
102 changes: 102 additions & 0 deletions
102
tests/sweep_framework/sweeps/eltwise/binary/gt/gt_forge.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,102 @@ | ||
# 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.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" 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 = { | ||
"xfail": { | ||
"input_shape": [[15, 15]], | ||
"input_a_dtype": [ttnn.int32], | ||
"input_b_dtype": [ttnn.int32], | ||
"input_a_layout": [ttnn.TILE_LAYOUT], | ||
"input_b_layout": [ttnn.TILE_LAYOUT], | ||
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
"input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG], | ||
"output_memory_config": [ttnn.DRAM_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 | ||
|
||
|
||
# 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_a_layout"] == ttnn.ROW_MAJOR_LAYOUT or test_vector["input_b_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 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_b_dtype, | ||
input_a_layout, | ||
input_b_layout, | ||
input_a_memory_config, | ||
input_b_memory_config, | ||
output_memory_config, | ||
*, | ||
device, | ||
) -> list: | ||
torch.manual_seed(0) | ||
|
||
torch_input_tensor_a = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.int32), input_a_dtype | ||
)(input_shape) | ||
torch_input_tensor_b = gen_func_with_cast_tt( | ||
partial(torch_random, low=-100, high=100, dtype=torch.int32), input_b_dtype | ||
)(input_shape) | ||
|
||
golden_function = ttnn.get_golden_function(ttnn.gt) | ||
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.gt(input_tensor_a, input_tensor_b, 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] |
Oops, something went wrong.