[passes] Introduce ConvertPermuteToReshape pass#521
[passes] Introduce ConvertPermuteToReshape pass#521llFreetimell wants to merge 1 commit intoSamsung:mainfrom
Conversation
| # 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: |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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>
12208d1 to
72801c0
Compare
| 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]),), {} |
There was a problem hiding this comment.
FYI, by simply moving this class into test/op/..., operation test can be done.
There was a problem hiding this comment.
Oh...?
You mean passes are automatically applied to test/op/... during the operation tests?
There was a problem hiding this comment.
It simply perform 'tico.convert' to the graph module, so it will perform your newly-added pass.
|
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 :) |
This commit introduces
ConvertPermuteToReshapepass.TICO-DCO-1.0-Signed-off-by: Seok Namkoong seok9311@naver.com
For #475
Draft #517