Skip to content

Commit

Permalink
tenstorrent#15246: Add sweeps for isclose, isclose sharded, ldexp sha…
Browse files Browse the repository at this point in the history
…rded, log… (tenstorrent#17300)

### Ticket
[Link to Github
Issue](tenstorrent#11512)

### Problem description
We need to increase sweep test coverage of our ops.

### What's changed
Added sweep tests for multiple ops

### Pass rates for new sweeps:
sweeps/eltwise/binary/rpow/rpow.py: 3 fail, 381 pass (99%)
sweeps/eltwise/binary/rpow/rpow_sharded.py: 87 fail, 297 pass (77%)
sweeps/eltwise/binary/ldexp/ldexp_sharded.py: 640 fail, 128 pass (15%)
sweeps/eltwise/binary/logaddexp/logaddexp_sharded.py: 940 fail, 212 pass
(18%)
sweeps/eltwise/binary/logaddexp2/logaddexp2_sharded.py: 1139 fail, 13
pass (1%)
sweeps/eltwise/binary/isclose/isclose.py: 3 fail, 765 pass (99%)
sweeps/eltwise/binary/isclose/isclose_sharded.py: 169 fail, 599 pass
(77%)
sweeps/eltwise/binary_backward/ldexp_bw/ldexp_bw_sharded.py: 84 fail,
300 pass (78%)
sweeps/eltwise/binary_backward/logaddexp_bw/logaddexp_bw_sharded.py: 84
fail, 300 pass (78%)
sweeps/eltwise/binary_backward/logaddexp2_bw/logaddexp2_bw_sharded.py:
84 fail, 300 pass (78%)
sweeps/eltwise/binary_bw/sub_bw/sub_bw_sharded.py: 768 fail, 0 pass (0%)
sweeps/eltwise/unary_bw/sub_bw/sub_bw.py: 0 fail, 768 pass (100%) 
sweeps/eltwise/unary_bw/sub_bw/sub_bw_sharded.py: 768 fail, 0 pass (0%)
sweeps/eltwise/binary_bw/atan2/atan2.py: 768 fail, 0 pass (0%) 
sweeps/eltwise/binary_bw/atan2/atan2_sharded.py: 768 fail, 0 pass (0%) 
sweeps/eltwise/binary/polyval/polyval_sharded.py: 174 fail, 594 pass
(77%)

### Checklist
- [X] Post commit CI passes
(https://github.com/tenstorrent/tt-metal/actions/runs/13074500921)
- [X] Sweep tests pass
  • Loading branch information
nemanjagrujic authored Feb 5, 2025
1 parent 281088f commit c428ab5
Show file tree
Hide file tree
Showing 20 changed files with 2,076 additions and 6 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/ttnn-run-sweeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ on:
- eltwise.unary_backward.rsqrt_bw.rsqrt_bw
- eltwise.unary_backward.rsqrt_bw.rsqrt_bw_sharded
- eltwise.unary_backward.sigmoid_bw.sigmoid_bw
- eltwise.unary_backward.sub_bw.sub_bw
- eltwise.unary_backward.sub_bw.sub_bw_sharded
- eltwise.unary_backward.tan_bw.tan_bw
- eltwise.unary_backward.tan_bw.tan_bw_sharded
- eltwise.unary_backward.trunc_bw.trunc_bw
Expand Down Expand Up @@ -319,6 +321,8 @@ on:
- eltwise.binary.add.add_different_memory_configs
- eltwise.binary.add.add_forge
- eltwise.binary.add.add_llama
- eltwise.binary.atan2.atan2
- eltwise.binary.atan2.atan2_sharded
- eltwise.unary.gtz.gtz
- eltwise.unary.ltz.ltz
- eltwise.unary.gez.gez
Expand Down Expand Up @@ -365,12 +369,15 @@ on:
- eltwise.binary.logical_and.logical_and_forge
- eltwise.binary.logical_and.logical_and_sharded
- eltwise.binary.polyval.polyval
- eltwise.binary.polyval.polyval_sharded
- eltwise.binary.remainder.remainder
- eltwise.binary.remainder.remainder_scalar_pytorch2
- eltwise.binary.remainder.remainder_forge
- eltwise.binary.remainder.remainder_unary
- eltwise.binary.remainder.remainder_unary_sharded
- eltwise.binary.remainder.remainder_shape
- eltwise.binary.rpow.rpow
- eltwise.binary.rpow.rpow_sharded
- eltwise.binary.squared_difference.squared_difference
- eltwise.binary.squared_difference_output.squared_difference_output
- eltwise.binary.scatter.scatter_forge
Expand All @@ -388,24 +395,33 @@ on:
- eltwise.binary.floor_divide.floor_divide_pytorch2
- eltwise.binary.floor_divide.floor_divide
- eltwise.binary.logaddexp.logaddexp
- eltwise.binary.logaddexp.logaddexp_sharded
- eltwise.binary.logaddexp2.logaddexp2
- eltwise.binary.logaddexp2.logaddexp2_sharded
- eltwise.binary.ldexp.ldexp
- eltwise.binary.ldexp.ldexp_sharded
- eltwise.binary.lt.lt_tensor_pytorch2
- eltwise.binary.lt.lt_scalar_pytorch2
- eltwise.binary.lt.lt_forge
- eltwise.binary.ne.ne_scalar_pytorch2
- eltwise.binary.ne.ne_forge
- eltwise.binary.isclose.isclose
- eltwise.binary.isclose.isclose_sharded
- eltwise.binary.hypot.hypot
- eltwise.binary.xlogy.xlogy
- eltwise.binary_backward.ldexp_bw.ldexp_bw
- eltwise.binary_backward.logaddexp_bw
- eltwise.binary_backward.logaddexp2_bw
- eltwise.binary_backward.ldexp_bw.ldexp_bw_sharded
- eltwise.binary_backward.logaddexp_bw.logaddexp_bw
- eltwise.binary_backward.logaddexp_bw.logaddexp_bw_sharded
- eltwise.binary_backward.logaddexp2_bw.logaddexp2_bw
- eltwise.binary_backward.logaddexp2_bw.logaddexp2_bw_sharded
- eltwise.binary_backward.addalpha_bw.addalpha_bw
- eltwise.binary_backward.subalpha_bw.subalpha_bw
- eltwise.binary_backward.xlogy_bw.xlogy_bw
- eltwise.binary_backward.hypot_bw.hypot_bw
- eltwise.binary_backward.add_bw.add_bw
- eltwise.binary_backward.sub_bw.sub_bw
- eltwise.binary_backward.sub_bw.sub_bw_sharded
- eltwise.binary_backward.mul_bw.mul_bw
- eltwise.binary_backward.div_bw.div_bw
- eltwise.binary_backward.fmod_bw.fmod_bw
Expand Down
91 changes: 91 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/binary/atan2/atan2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 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, 32], [6, 12, 256, 256], [1, 1, 32, 32], 16)
+ gen_shapes([1, 32, 32], [12, 256, 256], [1, 32, 32], 16)
+ gen_shapes([32, 32], [256, 256], [32, 32], 16),
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_b_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_a_layout": [ttnn.TILE_LAYOUT],
"input_b_layout": [ttnn.TILE_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],
}
}


# 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 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_b_dtype,
input_a_layout,
input_b_layout,
input_a_memory_config,
input_b_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.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_b_dtype
)(input_shape)

golden_function = ttnn.get_golden_function(ttnn.atan2)
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.atan2(input_tensor_a, input_tensor_b)
output_tensor = ttnn.to_torch(result)
e2e_perf = stop_measuring_time(start_time)

pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999)
return [pcc, e2e_perf]
129 changes: 129 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/binary/atan2/atan2_sharded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from typing import Optional, Tuple
from functools import partial

import json
import torch
import random
import ttnn
import math
from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm
from tests.sweep_framework.sweep_utils.sharding_utils import (
gen_sharded_spec_unary,
parse_sharding_spec,
invalidate_vector_sharding,
)
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 = 120

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_spec": gen_sharded_spec_unary(12, max_tensor_size_per_core=20 * 1024, layouts=["TILE_LAYOUT"]),
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_b_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
},
}


# 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]]:
input_layout = test_vector["input_spec"]["input_layout"]
sharding_invalidated, output_str = invalidate_vector_sharding(test_vector["input_spec"])

if input_layout == "ROW_MAJOR_LAYOUT":
return True, "Input to eltwise binary must be tilized"
if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b:
return True, "bfloat8_b is only supported on tiled layout"
if sharding_invalidated:
return sharding_invalidated, output_str

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_spec,
input_a_dtype,
input_b_dtype,
*,
device,
) -> list:
data_seed = random.randint(0, 20000000)
torch.manual_seed(data_seed)

(
input_shape,
core_grid,
sharding_strategy,
shard_orientation,
tensor_hw_as_shard_shape,
input_layout,
shard_height_mul_of_32,
) = parse_sharding_spec(input_spec)

if input_layout == ttnn.ROW_MAJOR_LAYOUT:
input_shape = sanitize_shape_rm(input_shape)

sharded_config = ttnn.create_sharded_memory_config_(
shape=input_shape,
core_grid=core_grid,
strategy=sharding_strategy,
orientation=shard_orientation,
use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape,
tile_layout=shard_height_mul_of_32,
)

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_b_dtype
)(input_shape)

golden_function = ttnn.get_golden_function(ttnn.atan2)
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=sharded_config,
)

input_tensor_b = ttnn.from_torch(
torch_input_tensor_b,
dtype=input_b_dtype,
layout=input_layout,
device=device,
memory_config=sharded_config,
)

start_time = start_measuring_time()
output_tensor = ttnn.atan2(input_tensor_a, input_tensor_b, memory_config=sharded_config)
e2e_perf = stop_measuring_time(start_time)
output_tensor = ttnn.to_torch(output_tensor)

pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999)
return [pcc, e2e_perf]
100 changes: 100 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/binary/isclose/isclose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from typing import Optional, Tuple
from functools import partial

import random
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, 1, 1], [6, 12, 256, 256], [1, 1, 1, 1], 32)
+ gen_shapes([1, 1, 1], [12, 256, 256], [1, 1, 1], 32)
+ gen_shapes([1, 1], [256, 256], [1, 1], 32),
"equal_nan": [True, False],
"input_a_dtype": [ttnn.bfloat16],
"input_b_dtype": [ttnn.bfloat16],
"input_a_layout": [ttnn.TILE_LAYOUT],
"input_b_layout": [ttnn.TILE_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],
}
}


# 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 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,
equal_nan,
input_a_dtype,
input_b_dtype,
input_a_layout,
input_b_layout,
input_a_memory_config,
input_b_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.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_b_dtype
)(input_shape)

rtol = random.choice([1e-1, 1e-2, 1e-3, 1e-4, 1e-6])
atol = random.choice([1e-4, 1e-5, 1e-6, 1e-7, 1e-8, 1e-9])

golden_function = ttnn.get_golden_function(ttnn.isclose)
torch_output_tensor = golden_function(
torch_input_tensor_a, torch_input_tensor_b, rtol=rtol, atol=atol, equal_nan=equal_nan
)

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.isclose(input_tensor_a, input_tensor_b, rtol=rtol, atol=atol, equal_nan=equal_nan)
output_tensor = ttnn.to_torch(result)
e2e_perf = stop_measuring_time(start_time)

pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.99)
# print(pcc)
return [pcc, e2e_perf]
Loading

0 comments on commit c428ab5

Please sign in to comment.