Skip to content

Conversation

@Mi-Jiazhi
Copy link
Contributor

@Mi-Jiazhi Mi-Jiazhi commented Nov 9, 2023

decompose like:

import torch

def my_triu(x, diag):
    rows = torch.ops.aten.size(x, -2)
    cols = torch.ops.aten.size(x, -1)

    row_indices = torch.ops.aten.arange(rows).unsqueeze(1)
    col_indices = torch.ops.aten.arange(cols).unsqueeze(0)

    cond = torch.ops.aten.ge(
        col_indices, torch.ops.aten.add(row_indices, diag))
    return torch.ops.aten.where(cond, x, 0)

x = torch.rand(5, 7)
assert torch.allclose(my_triu(x, 0), torch.triu(x, 0))
assert torch.allclose(my_triu(x, 1), torch.triu(x, 1))
assert torch.allclose(my_triu(x, 2), torch.triu(x, 2))
assert torch.allclose(my_triu(x, -1), torch.triu(x, -1))

@Mi-Jiazhi Mi-Jiazhi requested a review from qingyunqu November 13, 2023 01:38
@qingyunqu qingyunqu requested a review from ramiro050 November 13, 2023 17:12
@Mi-Jiazhi Mi-Jiazhi force-pushed the decompose-TriuOp branch 2 times, most recently from ed1cac4 to 5618886 Compare November 14, 2023 11:56
Copy link
Collaborator

@qingyunqu qingyunqu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qingyunqu
Copy link
Collaborator

@ramiro050 Could you please review this PR?

@qingyunqu qingyunqu requested a review from ramiro050 November 27, 2023 06:36
Copy link
Collaborator

@ramiro050 ramiro050 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one request

@qingyunqu qingyunqu merged commit f7a92d3 into llvm:main Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants