Skip to content

[passes] Introduce ConvertPermuteToReshape pass#521

Open
llFreetimell wants to merge 1 commit intoSamsung:mainfrom
llFreetimell:permute_to_reshape
Open

[passes] Introduce ConvertPermuteToReshape pass#521
llFreetimell wants to merge 1 commit intoSamsung:mainfrom
llFreetimell:permute_to_reshape

Conversation

@llFreetimell
Copy link
Contributor

@llFreetimell llFreetimell commented Feb 25, 2026

This commit introduces ConvertPermuteToReshape pass.

TICO-DCO-1.0-Signed-off-by: Seok Namkoong seok9311@naver.com


For #475
Draft #517

Comment on lines +70 to +77
# For example, if
# - input.shape = [1, x, 1, y]
# - torch.permute(input, [1, 2, 3, 0])
# then permute dims 2 and 0 keeps same order for 'x' and 'y'.
is_same_order = True
last_dim = -1
for dim in dims:
if input_shape[dim] == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you normalize the input shape for negative integer cases?

ndims = len(input_shape)
normalized_dims = [(d if d >= 0 else d + ndims) for d in dims]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed the negative integer cases :(
Thanks!!

This commit introduces `ConvertPermuteToReshape` pass.

TICO-DCO-1.0-TICO-DCO-1.0-Signed-off-by: Seok Namkoong <seok9311@naver.com>
Comment on lines +24 to +32
class PermuteBasic(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, x):
return torch.permute(x, (1, 2, 3, 0))

def get_example_inputs(self):
return (torch.rand([1, 5, 1, 3]),), {}
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, by simply moving this class into test/op/..., operation test can be done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh...?
You mean passes are automatically applied to test/op/... during the operation tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

It simply perform 'tico.convert' to the graph module, so it will perform your newly-added pass.

Copy link
Contributor

@dayo09 dayo09 left a comment

Choose a reason for hiding this comment

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

LGTM

@mhs4670go
Copy link
Contributor

Just curiosity, is it better to have Reshape instead of Permute ops?

@llFreetimell
Copy link
Contributor Author

Just curiosity, is it better to have Reshape instead of Permute ops?

Usually it's correct because permute op requires data movement, while reshape op does not :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants