-
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.
Browse files
Browse the repository at this point in the history
### Ticket Link to Github Issue #14863 ### Problem description Align ttnn.hardtanh arguments with pytorch ### What's changed Changed kw_args to positional args in pybind and golden function ### Checklist - [x] Post commit CI passes https://github.com/tenstorrent/tt-metal/actions/runs/11744299952 https://github.com/tenstorrent/tt-metal/actions/runs/11767253102 - [ ] Nightly fd https://github.com/tenstorrent/tt-metal/actions/runs/11767253759 - [ ] Blackhole Post commit (if applicable) - [ ] Model regression CI testing passes (if applicable) - [ ] Device performance regression CI testing passes (if applicable) - [x] New/Existing tests provide coverage for changes
- Loading branch information
1 parent
486862f
commit c8f7883
Showing
5 changed files
with
147 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
|
||
import torch | ||
|
||
import ttnn | ||
from tests.ttnn.utils_for_testing import assert_with_pcc | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"shapes", | ||
[[1, 1, 32, 32], [64, 64], [2, 2, 3, 256, 256]], | ||
) | ||
def test_hardtanh_default(device, shapes): | ||
torch.manual_seed(0) | ||
|
||
torch_input_tensor_a = torch.randn(shapes[0], dtype=torch.bfloat16) * 10 | ||
|
||
golden_fn = ttnn.get_golden_function(ttnn.hardtanh) | ||
torch_output_tensor = golden_fn(torch_input_tensor_a) | ||
|
||
input_tensor_a = ttnn.from_torch( | ||
torch_input_tensor_a, layout=ttnn.TILE_LAYOUT, device=device, memory_config=ttnn.DRAM_MEMORY_CONFIG | ||
) | ||
|
||
output_tensor = ttnn.hardtanh(input_tensor_a) | ||
output_tensor = ttnn.to_torch(output_tensor) | ||
|
||
assert ttnn.pearson_correlation_coefficient(torch_output_tensor, output_tensor) >= 0.9999 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"shapes", | ||
[[1, 1, 32, 32], [64, 64], [2, 2, 3, 256, 256]], | ||
) | ||
@pytest.mark.parametrize( | ||
"min", | ||
[0.25, 0.5, 0.66, -1], | ||
) | ||
@pytest.mark.parametrize( | ||
"max", | ||
[1, 2.5, 3, 6.6], | ||
) | ||
def test_hardtanh_args(device, shapes, min, max): | ||
torch.manual_seed(0) | ||
|
||
torch_input_tensor_a = torch.randn(shapes[0], dtype=torch.bfloat16) * 10 | ||
|
||
golden_fn = ttnn.get_golden_function(ttnn.hardtanh) | ||
torch_output_tensor = golden_fn(torch_input_tensor_a, min, max) | ||
|
||
input_tensor_a = ttnn.from_torch( | ||
torch_input_tensor_a, layout=ttnn.TILE_LAYOUT, device=device, memory_config=ttnn.DRAM_MEMORY_CONFIG | ||
) | ||
|
||
output_tensor = ttnn.hardtanh(input_tensor_a, min, max) | ||
output_tensor = ttnn.to_torch(output_tensor) | ||
|
||
assert ttnn.pearson_correlation_coefficient(torch_output_tensor, output_tensor) >= 0.9999 |
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