Skip to content

Commit

Permalink
#11512: Add frac, ceil and trunc sweeps
Browse files Browse the repository at this point in the history
  • Loading branch information
amalbasaTT committed Sep 17, 2024
1 parent 6085d0c commit cbb867f
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ttnn-run-sweeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- add
- line_all_gather
- logical_and_
- eltwise.frac
- eltwise.ceil
- eltwise.trunc
- matmul.full.matmul_default_block_sharded
- matmul.full.matmul_default_height_sharded
- matmul.full.matmul_default_interleaved
Expand Down
77 changes: 77 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/ceil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

import torch

import ttnn

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

# 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 = {
"suite_1": {
"input_shape": [
[8, 1, 33, 256],
[8, 1, 256, 32],
[8, 8, 256, 384],
[8, 5, 13, 512],
[8, 5, 32, 512],
[1, 1, 32, 16384],
],
"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:
torch_input_tensor_a = torch_random(input_shape, -100, 100, dtype=torch.bfloat16)

if input_a_dtype == ttnn.bfloat16:
torch_input_tensor_a = torch_input_tensor_a.to(torch.bfloat16)

elif input_a_dtype == ttnn.bfloat8_b:
tt_tensor = ttnn.from_torch(
torch_input_tensor_a, dtype=ttnn.bfloat8_b, layout=ttnn.TILE_LAYOUT, device=None, memory_config=None
)

torch_input_tensor_a = ttnn.to_torch(tt_tensor)

torch_output_tensor = torch.ceil(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]
77 changes: 77 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/frac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

import torch

import ttnn

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

# 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 = {
"suite_1": {
"input_shape": [
[8, 1, 33, 256],
[8, 1, 256, 32],
[8, 8, 256, 384],
[8, 5, 13, 512],
[8, 5, 32, 512],
[1, 1, 32, 16384],
],
"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:
torch_input_tensor_a = torch_random(input_shape, -100, 100, dtype=torch.bfloat16)

if input_a_dtype == ttnn.bfloat16:
torch_input_tensor_a = torch_input_tensor_a.to(torch.bfloat16)

elif input_a_dtype == ttnn.bfloat8_b:
tt_tensor = ttnn.from_torch(
torch_input_tensor_a, dtype=ttnn.bfloat8_b, layout=ttnn.TILE_LAYOUT, device=None, memory_config=None
)

torch_input_tensor_a = ttnn.to_torch(tt_tensor)

torch_output_tensor = torch.frac(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.frac(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]
77 changes: 77 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/trunc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

import torch

import ttnn

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

# 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 = {
"suite_1": {
"input_shape": [
[8, 1, 33, 256],
[8, 1, 256, 32],
[8, 8, 256, 384],
[8, 5, 13, 512],
[8, 5, 32, 512],
[1, 1, 32, 16384],
],
"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:
torch_input_tensor_a = torch_random(input_shape, -100, 100, dtype=torch.bfloat16)

if input_a_dtype == ttnn.bfloat16:
torch_input_tensor_a = torch_input_tensor_a.to(torch.bfloat16)

elif input_a_dtype == ttnn.bfloat8_b:
tt_tensor = ttnn.from_torch(
torch_input_tensor_a, dtype=ttnn.bfloat8_b, layout=ttnn.TILE_LAYOUT, device=None, memory_config=None
)

torch_input_tensor_a = ttnn.to_torch(tt_tensor)

torch_output_tensor = torch.trunc(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.trunc(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]

0 comments on commit cbb867f

Please sign in to comment.