-
Notifications
You must be signed in to change notification settings - Fork 74
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
cfe78bb
commit d75c31a
Showing
5 changed files
with
119 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import Optional, Tuple | ||
|
||
import torch | ||
from tests.ttnn.utils_for_testing import check_with_pcc | ||
import ttnn | ||
|
||
|
||
parameters = { | ||
"act_shape": [[1, 7, 7, 2048], [1, 1, 32, 64]], | ||
"dtype": [ttnn.bfloat16], | ||
} | ||
|
||
|
||
def skip(**_) -> Tuple[bool, Optional[str]]: | ||
return False, None | ||
|
||
|
||
def is_expected_to_fail(**_) -> Tuple[bool, Optional[str]]: | ||
return False, None | ||
|
||
|
||
def run( | ||
act_shape, | ||
dtype, | ||
device, | ||
) -> Tuple[bool, Optional[str]]: | ||
torch.manual_seed(0) | ||
|
||
act = torch.randn(act_shape, dtype=torch.bfloat16) | ||
ttact = ttnn.from_torch(act, dtype=dtype, layout=ttnn.TILE_LAYOUT, device=device) | ||
|
||
out = ttnn.average_pool2d(ttact) | ||
|
||
out_pytorch = ttnn.to_torch(ttnn.from_device(out)) | ||
|
||
## reference | ||
act_channels_first = torch.permute(act, (0, 3, 1, 2)) # Torch operates on channels-first tensors | ||
golden_pytorch = torch.nn.AdaptiveAvgPool2d((1, 1))(act_channels_first) | ||
golden_pytorch = torch.permute(golden_pytorch, (0, 2, 3, 1)) | ||
|
||
## test for equivalance | ||
return check_with_pcc(golden_pytorch, out_pytorch) |
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,48 @@ | ||
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from loguru import logger | ||
|
||
import torch | ||
import pytest | ||
import math | ||
from models.utility_functions import skip_for_wormhole_b0 | ||
from tests.ttnn.utils_for_testing import assert_with_pcc | ||
import ttnn | ||
|
||
|
||
@skip_for_wormhole_b0() | ||
@pytest.mark.parametrize( | ||
"act_shape", | ||
(([1, 7, 7, 2048], ([1, 1, 32, 64]))), | ||
ids=["resnet50_unpadded", "tile_divisible"], | ||
) | ||
@pytest.mark.parametrize( | ||
"dtype", | ||
(ttnn.bfloat16,), | ||
ids=[ | ||
"BFLOAT16", | ||
], | ||
) | ||
def test_run_average_pool( | ||
act_shape, | ||
dtype, | ||
device, | ||
): | ||
torch.manual_seed(0) | ||
|
||
act = torch.randn(act_shape, dtype=torch.bfloat16) | ||
ttact = ttnn.from_torch(act, dtype=dtype, layout=ttnn.TILE_LAYOUT, device=device) | ||
|
||
out = ttnn.average_pool2d(ttact) | ||
|
||
out_pytorch = ttnn.to_torch(ttnn.from_device(out)) | ||
|
||
## reference | ||
act_channels_first = torch.permute(act, (0, 3, 1, 2)) # Torch operates on channels-first tensors | ||
golden_pytorch = torch.nn.AdaptiveAvgPool2d((1, 1))(act_channels_first) | ||
golden_pytorch = torch.permute(golden_pytorch, (0, 2, 3, 1)) | ||
|
||
## test for equivalance | ||
assert_with_pcc(golden_pytorch, out_pytorch) |
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
Empty file.
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