reject input rank mismatch in transpose reshape#10545
Merged
copybara-service[bot] merged 2 commits intoJun 22, 2026
Merged
Conversation
dsharlet
reviewed
Jun 22, 2026
dsharlet
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for (another) fix!
| INSTANTIATE_TEST_SUITE_P(Transpose, TransposeF16, rank_params); | ||
| INSTANTIATE_TEST_SUITE_P(Transpose, TransposeF32, rank_params); | ||
|
|
||
| TEST(Transpose, reshape_rejects_input_rank_mismatch) { |
Collaborator
There was a problem hiding this comment.
Add #ifndef XNNPACK_USE_YNNPACK around this test. In YNNPACK, transpose can add or remove dimensions, so this check is overly conservative.
Contributor
Author
There was a problem hiding this comment.
Done, wrapped it in #ifndef XNNPACK_USE_YNNPACK with an #else note, same shape as the softmax test. The reshape check itself lives in src/subgraph/static-transpose.c, which YNNPACK doesn't route through (it has its own static_transpose), so only the test needed the guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Was poking at transpose with mismatched runtime shapes. A rank-3 transpose fed a rank-2 external input slips straight through reshape instead of being rejected:
reshape_transpose_operator takes its working rank from the permutation length, which is fixed at define time, and only ties it to the live input rank with an assert. xnn_reshape_external_value lets an external input be reshaped to any rank at run time, so under NDEBUG the assert is gone and the mismatched input is accepted. The op then transposes with a stale dimension count: it reads input->shape.dim[perm[i]] for slots past the live rank (stale values left over from the larger declared shape) and ends up walking the input buffer past what it actually holds.
The permutation length and the input rank must agree. Swapped the assert for a real check, same shape as the softmax and fully-connected runtime rank guards. The regression test reshapes a rank-3 transpose input down to rank 2 and expects invalid_parameter.