-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
817dc0a
commit e7ef646
Showing
45 changed files
with
1,320 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tests/tt_eager/python_api_testing/sweep_tests/pytests/tt_dnn/test_prod.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# SPDX-FileCopyrightText: © 2023-24 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
import torch | ||
import random | ||
from functools import partial | ||
import tt_lib as ttl | ||
|
||
|
||
from tests.tt_eager.python_api_testing.sweep_tests import ( | ||
comparison_funcs, | ||
generation_funcs, | ||
) | ||
from tests.tt_eager.python_api_testing.sweep_tests.run_pytorch_ci_tests import ( | ||
run_single_pytorch_test, | ||
) | ||
|
||
mem_configs = [ | ||
ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.DRAM), | ||
ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.L1), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dim", | ||
(3, 2, 1, 0, -1, -2, -3, -4), | ||
) | ||
@pytest.mark.parametrize("all_dimensions", [False, True]) | ||
@pytest.mark.parametrize( | ||
"input_shapes", | ||
[ | ||
[[1, 1, 32, 32]], | ||
[[4, 3, 32, 32]], | ||
[[2, 2, 32, 32]], | ||
# [[6, 4, 32, 32]], #Fails for all_dimensions = True ( expected result is inf but the result generated in nan ) | ||
# [[1, 1, 320, 320]], #Fails for all_dimensions = True ( expected result is inf but the result generated in nan ) | ||
# [[1, 3, 320, 64]], #Fails for all_dimensions = True ( expected result is inf but the result generated in nan ) | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"dst_mem_config", | ||
mem_configs, | ||
) | ||
class TestProd: | ||
def test_run_prod_op( | ||
self, | ||
all_dimensions, | ||
dim, | ||
input_shapes, | ||
dst_mem_config, | ||
device, | ||
): | ||
datagen_func = [ | ||
generation_funcs.gen_func_with_cast(partial(generation_funcs.gen_rand, low=1, high=1.5), torch.bfloat16) | ||
] | ||
test_args = generation_funcs.gen_default_dtype_layout_device(input_shapes)[0] | ||
test_args.update( | ||
{ | ||
"all_dimensions": all_dimensions, | ||
"dim": dim, | ||
} | ||
) | ||
test_args.update({"output_mem_config": dst_mem_config}) | ||
comparison_func = comparison_funcs.comp_pcc | ||
|
||
run_single_pytorch_test( | ||
"prod", | ||
input_shapes, | ||
datagen_func, | ||
comparison_func, | ||
device, | ||
test_args, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/tt_eager/python_api_testing/unit_testing/backward_ops/test_backward_prod.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import torch | ||
import pytest | ||
import tt_lib | ||
from tests.tt_eager.python_api_testing.unit_testing.backward_ops.utility_funcs import ( | ||
data_gen_pt_tt, | ||
data_gen_pt_tt_prod, | ||
compare_results, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_shapes", | ||
( | ||
(torch.Size([1, 1, 32, 32])), # 0 | ||
(torch.Size([1, 1, 320, 384])), # 1 | ||
(torch.Size([4, 2, 32, 32])), # 2 | ||
(torch.Size([1, 3, 320, 384])), # 3 | ||
(torch.Size([4, 3, 32, 32])), # 4 | ||
(torch.Size([4, 3, 64, 64])), # 5 | ||
(torch.Size([4, 3, 320, 320])), # 6 | ||
(torch.Size([4, 3, 32, 32])), # 7 | ||
(torch.Size([1, 3, 320, 320])), # 8 | ||
(torch.Size([1, 4, 320, 384])), # 9 | ||
(torch.Size([4, 4, 32, 32])), # 10 | ||
(torch.Size([5, 4, 32, 32])), # 11 | ||
(torch.Size([6, 4, 32, 32])), # 12 | ||
(torch.Size([4, 5, 32, 32])), # 13 | ||
(torch.Size([4, 6, 32, 32])), # 14 | ||
(torch.Size([4, 10, 32, 32])), # 15 | ||
(torch.Size([4, 20, 32, 32])), # 16 | ||
(torch.Size([4, 30, 32, 32])), # 17 | ||
(torch.Size([4, 31, 32, 32])), # 18 | ||
(torch.Size([4, 32, 32, 32])), # 19 | ||
(torch.Size([4, 33, 32, 32])), # 20 | ||
(torch.Size([4, 63, 32, 32])), # 21 | ||
(torch.Size([4, 64, 32, 32])), # 22 | ||
(torch.Size([32, 64, 32, 32])), # 23 | ||
), | ||
) | ||
@pytest.mark.parametrize( | ||
"dim", | ||
[-4, -3, -2, -1, 0, 1, 2, 3], | ||
) | ||
@pytest.mark.parametrize("all_dimensions", [True, False]) | ||
def test_bw_prod(input_shapes, all_dimensions, dim, device): | ||
in_data, input_tensor = data_gen_pt_tt(input_shapes, device, True) | ||
grad_data, grad_tensor = data_gen_pt_tt_prod(input_shapes, device, all_dimensions, dim) | ||
if all_dimensions == False: | ||
pyt_y = torch.prod(in_data, dim=dim, keepdim=True) | ||
else: | ||
pyt_y = torch.prod(in_data).view(1, 1, 1, 1) | ||
tt_output_tensor_on_device = tt_lib.tensor.prod_bw(grad_tensor, input_tensor, all_dimensions, dim) | ||
in_data.retain_grad() | ||
pyt_y.backward(gradient=grad_data) | ||
|
||
golden_tensor = [in_data.grad] | ||
|
||
comp_pass = compare_results(tt_output_tensor_on_device, golden_tensor) | ||
|
||
assert comp_pass |
Oops, something went wrong.