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

1D shape is lost in conversion to TILE_LAYOUT tensor #280

Open
jerrysky3 opened this issue Oct 4, 2024 · 2 comments
Open

1D shape is lost in conversion to TILE_LAYOUT tensor #280

jerrysky3 opened this issue Oct 4, 2024 · 2 comments

Comments

@jerrysky3
Copy link
Contributor

jerrysky3 commented Oct 4, 2024

When converting an 1D tensor into TILE_LAYOUT, the result tensor will have the shape (1[32], x) and the original 1D shape information is lost during the process. When we want to convert the tiled tensor back to pytorch tensor, currently I don't know how to tell if the original shape is 1D.

For example, the code below is doing a round-trip conversion between pytorch and ttnn tensor and I expect to get the output (32,) but the result is (1, 32)

import torch
import ttnn


def main(device):
    input = torch.rand((32,), dtype=torch.bfloat16)
    input_tensor = ttnn.from_torch(input, layout=ttnn.TILE_LAYOUT, device=device)
    print(ttnn.to_torch(input_tensor).shape)


if __name__ == "__main__":
    device = ttnn.open_device(device_id=0)
    try:
        main(device)
    finally:
        ttnn.close_device(device)

I think this might be the root cause of the issues like tenstorrent/tt-metal#12671 where we get 2D output on elementwise op with 1D input

@jerrysky3
Copy link
Contributor Author

For the completeness of the conversion, maybe we need to store the actual original 1D shape in TTNN tensor object so to_torch can convert it back to the orignal shape?

@davorchap
Copy link

For the completeness of the conversion, maybe we need to store the actual original 1D shape in TTNN tensor object so to_torch can convert it back to the orignal shape?

Yes! @TT-BrianLiu and @ayerofieiev-tt are making the new amazing shape/layout in Tensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants