Skip to content

Commit

Permalink
#12589: Migrate floor div sweep to new sweep framework
Browse files Browse the repository at this point in the history
  • Loading branch information
umadevimcw committed Jan 23, 2025
1 parent 8795d9b commit 59f4217
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ttnn-run-sweeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ on:
- eltwise.binary.fmod.fmod_unary
- eltwise.binary.fmod.fmod_unary_sharded
- eltwise.binary.floor_divide.floor_divide_pytorch2
- eltwise.binary.floor_divide.floor_divide
- eltwise.binary.logaddexp.logaddexp
- eltwise.binary.logaddexp2.logaddexp2
- eltwise.binary.ldexp.ldexp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# SPDX-FileCopyrightText: © 2025 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
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, is_wormhole_b0

# 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": [[1, 1, 32, 32], [1, 1, 320, 384], [1, 3, 320, 384]],
"input_a_dtype": [ttnn.bfloat16],
"input_b_dtype": [ttnn.bfloat16],
"input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT],
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
"input_b_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
},
}


def mesh_device_fixture():
device = ttnn.open_device(device_id=0)
assert ttnn.device.is_wormhole_b0(device) or ttnn.device.is_blackhole(device), "This op is not available for GS"
yield (device, "Wormhole_B0", "Blackhole")
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_layout"] == ttnn.ROW_MAJOR_LAYOUT:
return True, "Unary operation requires tensor to be in Tile layout when working with non-sharded input tensor"
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_layout,
input_a_memory_config,
input_b_memory_config,
output_memory_config,
*,
device,
) -> list:
if input_layout == ttnn.ROW_MAJOR_LAYOUT:
input_shape = sanitize_shape_rm(input_shape)

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_input_tensor_b = gen_func_with_cast_tt(
partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype
)(input_shape)

golden_function = ttnn.get_golden_function(ttnn.floor_div)
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_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_layout,
device=device,
memory_config=input_b_memory_config,
)

start_time = start_measuring_time()
output_tensor = ttnn.floor_div(input_tensor_a, input_tensor_b, memory_config=output_memory_config)
e2e_perf = stop_measuring_time(start_time)

output_tensor = ttnn.to_torch(output_tensor)

return [check_with_pcc(torch_output_tensor, output_tensor, 0.99), e2e_perf]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -39,7 +39,7 @@

def mesh_device_fixture():
device = ttnn.open_device(device_id=0)
assert ttnn.device.is_wormhole_b0(device) and ttnn.device.is_blackhole(device), "This op is not available for GS"
assert ttnn.device.is_wormhole_b0(device) or ttnn.device.is_blackhole(device), "This op is not available for GS"
yield (device, "Wormhole_B0", "Blackhole")
ttnn.close_device(device)
del device
Expand All @@ -51,8 +51,6 @@ def mesh_device_fixture():
def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]:
if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT:
return True, "Unary operation requires tensor to be in Tile layout when working with non-sharded input tensor"
if test_vector["input_a_dtype"] == ttnn.bfloat8_b:
return True, "Input_tensor_a doesn't support bfloat8_b"
return False, None


Expand Down

0 comments on commit 59f4217

Please sign in to comment.