tt-metal: [Bug Report] Argmax invalid result with padding
Describe the bug A clear and concise description of what the bug is.
When there is padding, the result of argmax is incorrect.
To Reproduce Steps to reproduce the behavior:
- Copy below code
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
# SPDX-License-Identifier: Apache-2.0
import torch
import pytest
import tt_lib
from loguru import logger
from tests.tt_eager.python_api_testing.sweep_tests import comparison_funcs
@pytest.mark.parametrize(
"input_shapes",
(
(torch.Size([1, 1, 1, 10])),
),
)
@pytest.mark.parametrize(
"dim",
(3,),
)
@pytest.mark.parametrize("all", (True,))
class TestArgmax:
def test_argmax(self, input_shapes, dim, all, device):
torch.manual_seed(10)
input_data = torch.tensor([5,3,2,1,10,9,6,7,4,8]).reshape(input_shapes).bfloat16()
print("input_data", input_data)
input_tensor = (
tt_lib.tensor.Tensor(input_data, tt_lib.tensor.DataType.BFLOAT16).pad_to_tile(100).to(tt_lib.tensor.Layout.TILE).to(device)
)
tt_output_tensor_on_device = tt_lib.tensor.argmax(input_tensor, dim=dim, all=all)
tt_out_tensor = tt_output_tensor_on_device.cpu().to(tt_lib.tensor.Layout.ROW_MAJOR).to_torch()
# tt_out_tensor = tt_output_tensor_on_device.cpu().to(tt_lib.tensor.Layout.ROW_MAJOR)
if all:
golden_tensor = torch.argmax(input_data)
tt_out_tensor = tt_out_tensor[0, 0, 0, 0]
else:
golden_tensor = torch.argmax(input_data, dim=dim)
if dim == 1 or dim == -3 or dim == 0 or dim == -4:
tt_out_tensor = tt_out_tensor[0]
else:
if input_shapes[1] != 1 or input_shapes[0] != 1:
tt_out_tensor = tt_out_tensor[0]
else:
tt_out_tensor = tt_out_tensor[0, 0, 0]
pt_out_tensor = golden_tensor
comp_pass, comp_out = comparison_funcs.comp_pcc(pt_out_tensor, tt_out_tensor, pcc=0.99)
comp_all, _ = comparison_funcs.comp_allclose(pt_out_tensor, tt_out_tensor, atol=4, rtol=1e-1)
logger.info(comp_pass)
logger.info(comp_all)
logger.info(comp_out)
status = comp_pass | comp_all
print("pt_out_tensor", pt_out_tensor)
print("tt_out_tensor", tt_out_tensor)
assert status
- Check result
input_data tensor([[[[ 5., 3., 2., 1., 10., 9., 6., 7., 4., 8.]]]], dtype=torch.bfloat16)
pt_out_tensor tensor(4)
tt_out_tensor tensor(10., dtype=torch.bfloat16)
Expected behavior A clear and concise description of what you expected to happen.
It seems that when the value of padding is greater than the value of the tensor, argmax returns the index of the padding value.
Screenshots If applicable, add screenshots to help explain your problem.
Please complete the following environment information:
- OS: [e.g. Ubuntu 20.04]
- Version of software (eg. commit a059360c5f356621d37963009ccd5a8089a71432)
- Arch: wormhole_b0
Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (14 by maintainers)
Commits related to this issue
- #7571: Support padding by user for argmax — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Support padding by user for argmax — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Add test files for argmax padding — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Remove using eqz op — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Remove using eqz op and test file prints — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Support padding by user for argmax — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Add test files for argmax padding — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Remove using eqz op and test file prints — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Support padding by user for argmax — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Add test files for argmax padding — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Remove using eqz op and test file prints — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Update index calculation module for all mode — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Update index module for dimension 3 and 2 — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Update index module for dim 1, 0 and test files — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Support padding by user for argmax — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Add test files for argmax padding — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Remove using eqz op and test file prints — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Update index calculation module for all mode — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Update index module for dimension 3 and 2 — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
- #7571: Update index module for dim 1, 0 and test files — committed to tenstorrent/tt-metal by umadevimcw 3 years ago
@hschoi4448 Can you retest this PR #8202 (it doesn’t include the int format output)?