Skip to content

Commit

Permalink
#8638: Make unit and sweep tests to show ttnn max and ttnn min operat…
Browse files Browse the repository at this point in the history
…ion failures
  • Loading branch information
nemanjagrujic committed May 21, 2024
1 parent 6d4404a commit 25e4420
Show file tree
Hide file tree
Showing 14 changed files with 391 additions and 73 deletions.
4 changes: 0 additions & 4 deletions tests/tt_eager/python_api_testing/sweep_tests/pytorch_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,6 @@ def max_bw(x, y, z, *args, **kwargs):
return [in_data.grad, other_data.grad]


def minimum(x, y, *args, **kwargs):
return torch.minimum(x, y)


def min(x, y, *args, **kwargs):
return torch.min(x, y)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import random
import pytest
import torch
import ttnn

from tests.ttnn.utils_for_testing import assert_with_pcc
from tests.ttnn.python_api_testing.sweep_tests import ttnn_ops


def run_min_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.min(x, dim)

tt_result = ttnn_ops.min(
x,
dim=dim,
device=device,
dtype=dtype,
layout=dlayout,
input_mem_config=in_mem_config,
output_mem_config=output_mem_config,
)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert_with_pcc(ref_value, tt_result, 0.99)


def run_max_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.max(x, dim)

tt_result = ttnn_ops.max(
x,
dim=dim,
device=device,
dtype=dtype,
layout=dlayout,
input_mem_config=in_mem_config,
output_mem_config=output_mem_config,
)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert_with_pcc(ref_value, tt_result, 0.99)


test_sweep_args = [
(
[(198, 216)],
[ttnn.bfloat16],
[ttnn.TILE_LAYOUT],
[ttnn.DRAM_MEMORY_CONFIG],
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
-1,
),
(
[(7, 156, 245)],
[ttnn.bfloat16],
[ttnn.TILE_LAYOUT],
[ttnn.DRAM_MEMORY_CONFIG],
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
-1,
),
(
[(2, 5, 72, 49)],
[ttnn.bfloat16],
[ttnn.TILE_LAYOUT],
[ttnn.DRAM_MEMORY_CONFIG],
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
-1,
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim",
(test_sweep_args),
)
def test_min(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim, device):
run_min_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim, device)


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim",
(test_sweep_args),
)
def test_max(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim, device):
run_max_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, dim, device)
20 changes: 10 additions & 10 deletions tests/ttnn/python_api_testing/sweep_tests/op_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,21 @@
"tt_op": ttnn_ops.eltwise_lte,
"pytorch_op": pytorch_ops.lte,
},
"ttnn-eltwise-minimum": {
"tt_op": ttnn_ops.eltwise_minimum,
"pytorch_op": pytorch_ops.minimum,
},
"ttnn-min": {
"tt_op": ttnn_ops.eltwise_min,
"tt_op": ttnn_ops.min,
"pytorch_op": ttnn_pytorch_ops.min,
},
"ttnn-max": {
"tt_op": ttnn_ops.max,
"pytorch_op": ttnn_pytorch_ops.max,
},
"ttnn-eltwise-min": {
"tt_op": ttnn_ops.eltwise_min,
"pytorch_op": ttnn_pytorch_ops.eltwise_min,
},
"ttnn-eltwise-max": {
"tt_op": ttnn_ops.eltwise_max,
"pytorch_op": pytorch_ops.max,
"pytorch_op": ttnn_pytorch_ops.eltwise_max,
},
"ttnn-eltwise-rad2deg": {
"tt_op": ttnn_ops.eltwise_rad2deg,
Expand Down Expand Up @@ -621,10 +625,6 @@
"tt_op": ttnn_ops.nextafter,
"pytorch_op": pytorch_ops.nextafter,
},
"ttnn-max": {
"tt_op": ttnn_ops.max,
"pytorch_op": pytorch_ops.max,
},
"ttnn-empty": {
"tt_op": ttnn_ops.empty,
"pytorch_op": pytorch_ops.empty,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
test-list:
- ttnn-max:
shape:
start-shape: [1, 1, 1, 1]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 1, 1]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_equal
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: max_sweep.csv
- ttnn-max:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 32, 32]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: max_sweep.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
test-list:
- ttnn-min:
shape:
start-shape: [1, 1, 1, 1]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 1, 1]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_equal
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: min_sweep.csv
- ttnn-min:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 32, 32]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: min_sweep.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
test-list:
- ttnn-max:
shape:
start-shape: [1, 1, 1, 1]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 1, 1]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_equal
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: max_sweep.csv
- ttnn-max:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 32, 32]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: max_sweep.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
test-list:
- ttnn-min:
shape:
start-shape: [1, 1, 1, 1]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 1, 1]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_equal
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: min_sweep.csv
- ttnn-min:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 32, 32]
num-dims: [2, 3, 4]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
datagen:
function: gen_rand
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_min_max_dim_args
sanitize-args: False
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: min_sweep.csv
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ test-list:
data-type: ["BFLOAT16", "BFLOAT8_B"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: maximum_sweep.csv
output-file: eltwise_max_sweep.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
test-list:
- ttnn-eltwise-minimum:
- ttnn-eltwise-min:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
Expand All @@ -23,6 +23,6 @@ test-list:
data-type: ["BFLOAT16", "BFLOAT8_B"]
buffer-type: ["DRAM", "L1"]
out-buffer-type: ["DRAM", "L1"]
output-file: eltwise_minimum_sweep.csv
output-file: eltwise_min_sweep.csv
env:
# TT_PCI_DMA_BUF_SIZE: "1048576"
Loading

0 comments on commit 25e4420

Please sign in to comment.