Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] invalid isclose result #6672

Open
Tracked by #6633 ...
hschoi4448 opened this issue Mar 22, 2024 · 2 comments
Open
Tracked by #6633 ...

[Bug Report] invalid isclose result #6672

hschoi4448 opened this issue Mar 22, 2024 · 2 comments
Assignees
Labels
bug Something isn't working forward MCW moreh moreh contribution op_cat: eltwise P2

Comments

@hschoi4448
Copy link
Contributor

hschoi4448 commented Mar 22, 2024

Describe the bug
A clear and concise description of what the bug is.

The isclose function returns an invalid value.

To Reproduce
Steps to reproduce the behavior:

  1. Copy and past below code
# 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, compare_results

import ttnn
from tests.tt_eager.python_api_testing.sweep_tests import pytorch_ops

def data_gen_pt_tt(input_shapes, device, required_grad=False, val=1):
    pt_tensor = (torch.ones(input_shapes, requires_grad=required_grad) * val).bfloat16()
    tt_tensor = (
        tt_lib.tensor.Tensor(pt_tensor, tt_lib.tensor.DataType.BFLOAT16).to(tt_lib.tensor.Layout.TILE).to(device)
    )
    return pt_tensor, tt_tensor

@pytest.mark.parametrize(
    "input_shapes",
    (
        (torch.Size([1, 1, 32, 32])),
    ),
)
@pytest.mark.parametrize(
    "params",
    (
        [
            (float('nan'), float('nan'), False),
            (float('nan'), float('nan'), True),
         ]
    ),
)
def test_bw(input_shapes, params, device):
    val1, val2, equal_nan = params
    in_data, input_tensor = data_gen_pt_tt(input_shapes, device, True, val=val1)
    other_data, other_tensor = data_gen_pt_tt(input_shapes, device, True, val=val2)
    
    print("input_tensor", input_tensor)
    print("other_tensor", other_tensor)

    rtol = 0.01
    atol = 0.01
        
    golden_tensor = pytorch_ops.isclose(in_data, other_data, rtol=rtol, atol=atol, equal_nan=equal_nan)

    tt_output_tensor_on_device = tt_lib.tensor.isclose(input_tensor, other_tensor, rtol=rtol, atol=atol, equal_nan=equal_nan)

    output_tensor = ttnn.to_torch(tt_output_tensor_on_device).bool()

    print("tt_output_tensor_on_device", tt_output_tensor_on_device)
    print("golden_tensor", golden_tensor)
    print("output_tensor", output_tensor)
    golden_tensor = golden_tensor
    comp_pass = torch.allclose(output_tensor, golden_tensor)
    
    assert comp_pass
  1. Run with pytest
input_tensor ttnn.Tensor([[[[-nan    , -nan    ,  ..., -nan    , -nan    ],
               [-nan    , -nan    ,  ..., -nan    , -nan    ],
               ...,
               [-nan    , -nan    ,  ..., -nan    , -nan    ],
               [-nan    , -nan    ,  ..., -nan    , -nan    ]]]], shape=Shape([1, 1, 32, 32]), dtype=DataType::BFLOAT16, layout=Layout::TILE)
other_tensor ttnn.Tensor([[[[-nan    , -nan    ,  ..., -nan    , -nan    ],
               [-nan    , -nan    ,  ..., -nan    , -nan    ],
               ...,
               [-nan    , -nan    ,  ..., -nan    , -nan    ],
               [-nan    , -nan    ,  ..., -nan    , -nan    ]]]], shape=Shape([1, 1, 32, 32]), dtype=DataType::BFLOAT16, layout=Layout::TILE)
tt_output_tensor_on_device ttnn.Tensor([[[[ 1.00000,  1.00000,  ...,  1.00000,  1.00000],
               [ 1.00000,  1.00000,  ...,  1.00000,  1.00000],
               ...,
               [ 1.00000,  1.00000,  ...,  1.00000,  1.00000],
               [ 1.00000,  1.00000,  ...,  1.00000,  1.00000]]]], shape=Shape([1, 1, 32, 32]), dtype=DataType::BFLOAT16, layout=Layout::TILE)
tt_output_torch_tensor TorchTensor([[[[True, True, True,  ..., True, True, True],
               [True, True, True,  ..., True, True, True],
               [True, True, True,  ..., True, True, True],
               ...,
               [True, True, True,  ..., True, True, True],
               [True, True, True,  ..., True, True, True],
               [True, True, True,  ..., True, True, True]]]])
golden_tensor tensor([[[[False, False, False,  ..., False, False, False],
          [False, False, False,  ..., False, False, False],
          [False, False, False,  ..., False, False, False],
          ...,
          [False, False, False,  ..., False, False, False],
          [False, False, False,  ..., False, False, False],
          [False, False, False,  ..., False, False, False]]]])

Expected behavior
A clear and concise description of what you expected to happen.

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 903fb49)
  • Device: wormhole_b0

Additional context
Add any other context about the problem here.

@VirdhatchaniKN
Copy link
Contributor

Hi @tt-aho , @jliangTT , @eyonland , @hschoi4448

Isclose is dependent on isnan operation, but due to hardware restrictions, we are facing issue related to nan : Discussion.
Kindly share your inputs / thoughts on how we could proceed further .

@VirdhatchaniKN
Copy link
Contributor

This issue is now currently handled here : #14077. Will be assigned to TT. Hence moving this to blocked

@razorback3 razorback3 added P2 and removed P1 labels Dec 13, 2024
@eyonland eyonland added the MCW label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working forward MCW moreh moreh contribution op_cat: eltwise P2
Projects
None yet
Development

No branches or pull requests

5 participants