-
Notifications
You must be signed in to change notification settings - Fork 360
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
feat: support aten.pixel_shuffle dynamo converter #2596
feat: support aten.pixel_shuffle dynamo converter #2596
Conversation
004810f
to
e2c7081
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall - just asked a clarifying question about the implementation details.
shape = input.shape | ||
in_channels, in_height, in_width = shape[-3:] | ||
out_channels = in_channels // (upscale_factor**2) | ||
out_height = in_height * upscale_factor | ||
out_width = in_width * upscale_factor | ||
new_shape = shape[:-3] + ( | ||
out_channels, | ||
upscale_factor, | ||
upscale_factor, | ||
in_height, | ||
in_width, | ||
) | ||
reshaped_tensor = reshape( | ||
ctx, target, source_ir, f"{name}_reshape1", input, new_shape | ||
) | ||
rank = len(shape) | ||
permute_shape = list(range(rank)) | ||
permute_shape.insert(-2, rank) | ||
permute_shape.insert(-1, rank + 1) | ||
permuted_tensor = impl.permutation.permute( | ||
ctx, target, source_ir, f"{name}_permute", reshaped_tensor, permute_shape | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for the intermediate reshape and permute here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. This is because if we directly use reshape, the output shape will be correct, but the values won't. For example:
>>> x = torch.randn((8,2,3))
>>> x.reshape((2,4,6))
tensor([[[-1.4204, -0.4205, -1.3309, -1.1576, -1.8777, -1.3462],
[-0.5689, -0.1234, -0.5276, 1.2325, 0.2859, 0.4005],
[-0.7908, -0.4946, -0.7183, 0.2497, -0.6588, -1.0771],
[ 0.5446, -0.0980, 0.9309, -2.9004, 1.9834, -0.2377]],
[[ 1.3769, 0.5741, -0.3463, 0.6038, -0.9376, 1.1402],
[-0.1754, 0.4850, -3.5597, -0.5911, 1.7931, -1.7492],
[ 0.9871, -0.2294, 0.7445, -0.0991, 0.0278, 0.6699],
[-0.1543, -1.4414, -0.6795, -0.0403, 0.4620, -1.2007]]])
>>> torch.nn.functional.pixel_shuffle(x, upscale_factor=2)
tensor([[[-1.4204, -0.5689, -0.4205, -0.1234, -1.3309, -0.5276],
[-0.7908, 0.5446, -0.4946, -0.0980, -0.7183, 0.9309],
[-1.1576, 1.2325, -1.8777, 0.2859, -1.3462, 0.4005],
[ 0.2497, -2.9004, -0.6588, 1.9834, -1.0771, -0.2377]],
[[ 1.3769, -0.1754, 0.5741, 0.4850, -0.3463, -3.5597],
[ 0.9871, -0.1543, -0.2294, -1.4414, 0.7445, -0.6795],
[ 0.6038, -0.5911, -0.9376, 1.7931, 1.1402, -1.7492],
[-0.0991, -0.0403, 0.0278, 0.4620, 0.6699, -1.2007]]])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example - that's very helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Description
Support
aten.pixel_shuffle
dynamo converter.Fixes #2594
Type of change
Checklist: