-
Notifications
You must be signed in to change notification settings - Fork 608
Fix dim order in op_permute #6432
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
Conversation
* hardtanh * permute Change-Id: Ia1802bdc37d365af382835b3c14174d841892927
Permute vector needs to be permuted when dim_order != (0, 1, 2, 3) Change-Id: I2a35c6852376f9a57deeedd4fc38bda870e453a4 Signed-off-by: Oscar Andersson <[email protected]> Signed-off-by: Erik Lundell <[email protected]>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/6432
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit b86ae33 with merge base 0aa802d ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@@ -40,8 +88,33 @@ def define_node( | |||
) | |||
return | |||
|
|||
# The permutation vector describes a permutation P in default Pytorch dim_order. | |||
# For rank 4, the default dim_order NCHW. | |||
# E.g. (2,3,0,1) -> permute (n,c,h,w) to (w,c,n,h) |
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.
# E.g. (2,3,0,1) -> permute (n,c,h,w) to (w,c,n,h) | |
# E.g. (2,3,0,1) -> permute (n,c,h,w) to (h,w,n,c) |
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.
Your suggestion is correct, messed this up.
P = permutation_vector_to_matrix(permutation_vector) | ||
|
||
# The complete transformation is S * P * S_inverse. | ||
transformation_matrix = S.matmul(P.matmul(S_inverse)) |
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.
This is very cool, and I think I get what it is doing, but can you help me understand the math 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.
Sure, the problem I am addressing is how a permutation vector expressed in nchw should be modified to work for nhwc. The key idea is to view the dim order as a coordinate system (the index (1,2,3,4) in nchw-coordinates is the same as (1,3,4,2) in nhwc) and to realize that both transformations between the systems and a permutation ops are linear operations that can be described by matrices.
For each nhwc-index in the incoming tensor, the full transformation of the permute op can then be described by:
- translate from nhwc to nchw
- do the permutation in nchw coordinates
- translate back to nhwc
Since all steps are permutation transformations, we can combine them into one single permutation transformation, which can then be expressed by a permutation vector - this is the vector we were looking for.
ArmTester( | ||
module, | ||
example_inputs=test_data, | ||
compile_spec=common.get_tosa_compile_spec(), |
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.
can we test permute to nhwc here at least for u85?
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.
Good point, right now we are only testing the case when we already are in nhwc for rank 4 tensors.
@digantdesai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
No description provided.