Skip to content

Commit

Permalink
#13373: PyTorch Tracing Sweeps for set 2 ops
Browse files Browse the repository at this point in the history
  • Loading branch information
VirdhatchaniKN committed Oct 4, 2024
1 parent d78ed37 commit 315eba0
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ttnn-run-sweeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- eltwise.unary.cos.cos
- eltwise.unary.sin.sin
- eltwise.unary.clamp.clamp
- eltwise.unary.clamp.clamp_pytorch2
- eltwise.unary.clip.clip
- eltwise.unary.cbrt.cbrt
- eltwise.unary.rsub.rsub
Expand Down Expand Up @@ -47,6 +48,8 @@ on:
- eltwise.unary.bitwise.bitwise_xor
- eltwise.unary.log_sigmoid.log_sigmoid
- eltwise.unary.logical_not_.logical_not_
- eltwise.unary.logical_not.logical_not_pytorch2
- eltwise.unary.neg.neg_pytorch2
- eltwise.unary.erf.erf
- eltwise.unary.erfinv.erfinv
- eltwise.unary.i0.i0
Expand All @@ -55,6 +58,8 @@ on:
- eltwise.unary.lgamma.lgamma
- eltwise.unary.sigmoid.sigmoid
- eltwise.unary.sigmoid_accurate.sigmoid_accurate
- eltwise.unary.hardswish.hardswish_pytorch2
- eltwise.unary.hardtanh.hardtanh_pytorch2
- eltwise.binary.subtract.subtract
- eltwise.binary.multiply.multiply
- eltwise.binary.div.div
Expand Down
132 changes: 132 additions & 0 deletions tests/sweep_framework/sweeps/eltwise/unary/clamp/clamp_pytorch2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# SPDX-FileCopyrightText: © 2024 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.utils import gen_shapes, gen_low_high_scalars
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 = 30

random.seed(0)

parameters = {
"clamp_1": {
"input_specs": [
{"shape": [0, 1], "max": 4.135166556742356},
{"shape": [0, 2], "min": 0, "max": 1066},
{"shape": [0, 2], "min": 0, "max": 800},
{"shape": [1, 1, 1, 42], "min": 0, "max": 82},
{"shape": [1, 1, 32, 1], "min": 0, "max": 49},
{"shape": [1066], "min": 0.0},
{"shape": [1066], "max": 639},
{"shape": [12, 1, 1], "max": 4.605170185988092},
{"shape": [120], "min": 0.0},
{"shape": [120], "max": 59},
{"shape": [128], "min": 0.0},
{"shape": [128], "max": 127},
{"shape": [128], "max": 15},
{"shape": [128], "max": 31},
{"shape": [128], "max": 63},
{"shape": [16, 1, 1], "max": 4.605170185988092},
{"shape": [160], "min": 0.0},
{"shape": [160], "max": 79},
{"shape": [24, 1, 1], "max": 4.605170185988092},
{"shape": [240], "min": 0.0},
{"shape": [240], "max": 119},
{"shape": [3, 1, 1], "max": 4.605170185988092},
{"shape": [300], "min": 0.0},
{"shape": [300], "max": 479},
{"shape": [300], "max": 639},
{"shape": [30], "min": 0.0},
{"shape": [30], "max": 14},
{"shape": [32, 1, 1], "max": 4.605170185988092},
{"shape": [320], "min": 0.0},
{"shape": [320], "max": 159},
{"shape": [320], "max": 319},
{"shape": [320], "max": 479},
{"shape": [320], "max": 639},
{"shape": [3234, 1], "max": 4.135166556742356},
{"shape": [3234, 2], "min": 0, "max": 320},
{"shape": [4, 1, 1], "max": 4.605170185988092},
{"shape": [4, 2], "min": 0, "max": 1},
{"shape": [40], "min": 0.0},
{"shape": [40], "max": 19},
{"shape": [480], "min": 0.0},
{"shape": [480], "max": 239},
{"shape": [6, 1, 1], "max": 4.605170185988092},
{"shape": [6, 2], "min": 0, "max": 1},
{"shape": [60], "min": 0.0},
{"shape": [60], "max": 29},
{"shape": [640], "min": 0.0},
{"shape": [640], "max": 319},
{"shape": [8, 1, 1], "max": 4.605170185988092},
{"shape": [800], "min": 0.0},
{"shape": [800], "max": 479},
{"shape": [80], "min": 0.0},
{"shape": [80], "max": 39},
{"shape": [8732, 1], "max": 4.135166556742356},
{"shape": [8732, 2], "min": 0, "max": 300},
{"shape": [1, 1, 38, 38], "min": 1e-12},
{"shape": [1, 1], "min": 1e-12},
{"shape": [1, 24, 64, 1], "min": 1e-12},
{"shape": [1, 32, 64, 1], "min": 1e-12},
{"shape": [16, 6, 64, 1], "min": 1e-12},
{"shape": [16, 8, 64, 1], "min": 1e-12},
{"shape": [4, 12, 64, 1], "min": 1e-12},
{"shape": [4, 16, 64, 1], "min": 1e-12},
{"shape": [64, 3, 64, 1], "min": 1e-12},
{"shape": [64, 4, 64, 1], "min": 1e-12},
],
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_a_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT],
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
},
}


def run(
input_specs,
input_a_dtype,
input_a_layout,
input_a_memory_config,
output_memory_config,
*,
device,
) -> list:
data_seed = random.randint(0, 20000000)
torch.manual_seed(data_seed)

torch_input_tensor_a = gen_func_with_cast_tt(
partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype
)(input_specs["shape"])

min_val = input_specs.get("min", None)
max_val = input_specs.get("max", None)

torch_output_tensor = torch.clamp(torch_input_tensor_a, min_val, max_val)

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.clamp(input_tensor_a, min_val, max_val, 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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# SPDX-FileCopyrightText: © 2024 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.utils import gen_shapes, gen_low_high_scalars
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 = 30

random.seed(0)

parameters = {
"hardswish_1": {
"input_shape": [
[1, 1024],
[1, 120, 14, 14],
[1, 1280],
[1, 144, 14, 14],
[1, 16, 112, 112],
[1, 16, 160, 160],
[1, 184, 14, 14],
[1, 184, 20, 20],
[1, 200, 14, 14],
[1, 200, 20, 20],
[1, 240, 14, 14],
[1, 240, 20, 20],
[1, 240, 28, 28],
[1, 240, 40, 40],
[1, 288, 14, 14],
[1, 288, 7, 7],
[1, 480, 10, 10],
[1, 480, 14, 14],
[1, 480, 20, 20],
[1, 576, 7, 7],
[1, 672, 10, 10],
[1, 672, 14, 14],
[1, 672, 20, 20],
[1, 672, 7, 7],
[1, 96, 14, 14],
[1, 96, 28, 28],
[1, 960, 7, 7],
],
"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],
},
}


def run(
input_shape,
input_dtype,
input_layout,
input_memory_config,
output_memory_config,
*,
device,
) -> list:
data_seed = random.randint(0, 20000000)
torch.manual_seed(data_seed)

torch_input_tensor_a = gen_func_with_cast_tt(
partial(torch_random, low=-100, high=100, dtype=torch.float32), input_dtype
)(input_shape)

torch_output_tensor = torch.nn.functional.hardswish(torch_input_tensor_a)

input_tensor_a = ttnn.from_torch(
torch_input_tensor_a,
dtype=input_dtype,
layout=input_layout,
device=device,
memory_config=input_memory_config,
)

start_time = start_measuring_time()
result = ttnn.hardswish(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]
Loading

0 comments on commit 315eba0

Please sign in to comment.