Skip to content

Commit

Permalink
#4225: Add YAML and unit tests for identity
Browse files Browse the repository at this point in the history
  • Loading branch information
npetrovic-tenstorrent committed Dec 7, 2023
1 parent bed7516 commit 708fd75
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import pytest
import torch

import tt_lib as ttl

from tests.tt_eager.python_api_testing.sweep_tests.comparison_funcs import comp_pcc

from tests.tt_eager.python_api_testing.sweep_tests.pytorch_ops import eltwise_identity as pt_identity
from tests.tt_eager.python_api_testing.sweep_tests.tt_lib_ops import eltwise_identity as tt_identity
from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_complex
from tests.tt_eager.python_api_testing.sweep_tests.common import set_slow_dispatch_mode


def run_identity_tests(input_shape, dtype, dlayout, in_mem_config, out_mem_config, data_seed, dispatch_mode, device):
torch.manual_seed(data_seed)
prev_dispatch_mode = set_slow_dispatch_mode(dispatch_mode)

if in_mem_config == "SYSTEM_MEMORY":
in_mem_config = None

x = torch.Tensor(size=input_shape).uniform_(-100, 100)
x_ref = x.detach().clone()

# get ref result
ref_value = pt_identity(x_ref)

tt_result = tt_identity(
x=x,
device=device,
dtype=[dtype],
layout=[dlayout],
input_mem_config=[in_mem_config],
output_mem_config=out_mem_config,
)

# compare tt and golden outputs
success, pcc_value = comp_pcc(ref_value, tt_result)
logger.debug(pcc_value)

set_slow_dispatch_mode(prev_dispatch_mode)
assert success


test_sweep_args = [
(
(6, 12, 40, 208),
ttl.tensor.DataType.BFLOAT16,
ttl.tensor.Layout.ROW_MAJOR,
(ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.L1)),
(ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.DRAM)),
13795575,
"1",
),
(
(5, 8, 100, 118),
ttl.tensor.DataType.BFLOAT16,
ttl.tensor.Layout.ROW_MAJOR,
(ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.L1)),
(ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.DRAM)),
3405120,
"1",
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, out_mem_config, data_seed, dispatch_mode",
(test_sweep_args),
)
def test_identity_test(input_shape, dtype, dlayout, in_mem_config, out_mem_config, data_seed, dispatch_mode, device):
run_identity_tests(input_shape, dtype, dlayout, in_mem_config, out_mem_config, data_seed, dispatch_mode, device)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
test-list:
- eltwise-identity:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 32, 32]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
env:
TT_METAL_SLOW_DISPATCH_MODE: ["", "1"]
# TT_PCI_DMA_BUF_SIZE: "1048576"
datagen:
function: gen_rand
dtype: bfloat16
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_dtype_layout_device
output-file: eltwise_identity_sweep.csv
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1", "SYSTEM_MEMORY"]
out-buffer-type: ["DRAM"]
- eltwise-identity:
shape:
start-shape: [1, 1, 2, 2]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 2, 2]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
env:
TT_METAL_SLOW_DISPATCH_MODE: ["", "1"]
# TT_PCI_DMA_BUF_SIZE: "1048576"
datagen:
function: gen_rand
dtype: bfloat16
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_dtype_layout_device
output-file: eltwise_identity_sweep.csv
args:
data-layout: ["ROW_MAJOR"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1", "SYSTEM_MEMORY"]
out-buffer-type: ["DRAM"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
test-list:
- eltwise-identity:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 32, 32]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
env:
TT_METAL_SLOW_DISPATCH_MODE: ["", "1"]
# TT_PCI_DMA_BUF_SIZE: "1048576"
datagen:
function: gen_rand
dtype: bfloat16
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_dtype_layout_device
output-file: eltwise_identity_sweep.csv
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1", "SYSTEM_MEMORY"]
out-buffer-type: ["DRAM"]
- eltwise-identity:
shape:
start-shape: [1, 1, 2, 2]
end-shape: [6, 12, 256, 256]
interval: [1, 1, 2, 2]
num-shapes: 1
num-samples: 64
args-sampling-strategy: "all"
env:
TT_METAL_SLOW_DISPATCH_MODE: ["", "1"]
# TT_PCI_DMA_BUF_SIZE: "1048576"
datagen:
function: gen_rand
dtype: bfloat16
args:
low: -100
high: 100
comparison:
function: comp_pcc
args-gen: gen_dtype_layout_device
output-file: eltwise_identity_sweep.csv
args:
data-layout: ["ROW_MAJOR"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1", "SYSTEM_MEMORY"]
out-buffer-type: ["DRAM"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
test-list:
- eltwise-identity:
shape:
start-shape: [1, 1, 32, 32]
end-shape: [12, 24, 512, 512]
interval: [1, 1, 32, 32]
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_dtype_layout_device
output-file: eltwise_identity_sweep.csv
args:
data-layout: ["TILE"]
data-type: ["BFLOAT16", "BFLOAT8_B"]
buffer-type: ["DRAM", "L1", "SYSTEM_MEMORY"]
out-buffer-type: ["DRAM"]
- eltwise-identity:
shape:
start-shape: [1, 1, 2, 2]
end-shape: [12, 24, 512, 512]
interval: [1, 1, 2, 2]
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_dtype_layout_device
output-file: eltwise_identity_sweep.csv
args:
data-layout: ["ROW_MAJOR"]
data-type: ["BFLOAT16"]
buffer-type: ["DRAM", "L1", "SYSTEM_MEMORY"]
out-buffer-type: ["DRAM"]

0 comments on commit 708fd75

Please sign in to comment.