-
Notifications
You must be signed in to change notification settings - Fork 72
Optimize away zero-length concat operands #2150
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
Merged
Merged
Conversation
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
❌ 12 Tests Failed:
View the top 2 failed test(s) by shortest run time
View the full list of 1 ❄️ flaky tests
To view more test analytics, go to the Test Analytics Dashboard |
justinchuby
approved these changes
Mar 31, 2025
Some tests are failing |
bmehta001
pushed a commit
to bmehta001/onnxscript
that referenced
this pull request
Apr 11, 2025
We optimize `Concat (x1, x2, x3)` if one or more the concat operands has zero length along the concatenated axis-dimension. This pattern shows up, for example, in Phi models. See [this line](https://github.com/huggingface/transformers/blob/786d9c5ed920a099573ea7b6dbf265f1aeb32fc0/src/transformers/models/phi3/modeling_phi3.py#L152) in the implementation of partial-rotary-embedding: ```py q_embed = torch.cat([(q_rot * cos) + (rotate_half(q_rot) * sin), q_pass], dim=-1) ``` In the special case of total-rotary-embedding, the second operand `q_pass` of the concat is empty. This also interferes with the pattern-matching for GQA in the generated graph. Optimizing the redundant Concat away will help with GQA fusion as well. Handle the edge case when all operands have zero size.
bmehta001
pushed a commit
to bmehta001/onnxscript
that referenced
this pull request
Apr 11, 2025
We optimize `Concat (x1, x2, x3)` if one or more the concat operands has zero length along the concatenated axis-dimension. This pattern shows up, for example, in Phi models. See [this line](https://github.com/huggingface/transformers/blob/786d9c5ed920a099573ea7b6dbf265f1aeb32fc0/src/transformers/models/phi3/modeling_phi3.py#L152) in the implementation of partial-rotary-embedding: ```py q_embed = torch.cat([(q_rot * cos) + (rotate_half(q_rot) * sin), q_pass], dim=-1) ``` In the special case of total-rotary-embedding, the second operand `q_pass` of the concat is empty. This also interferes with the pattern-matching for GQA in the generated graph. Optimizing the redundant Concat away will help with GQA fusion as well. Handle the edge case when all operands have zero size.
bmehta001
pushed a commit
to bmehta001/onnxscript
that referenced
this pull request
Apr 11, 2025
We optimize `Concat (x1, x2, x3)` if one or more the concat operands has zero length along the concatenated axis-dimension. This pattern shows up, for example, in Phi models. See [this line](https://github.com/huggingface/transformers/blob/786d9c5ed920a099573ea7b6dbf265f1aeb32fc0/src/transformers/models/phi3/modeling_phi3.py#L152) in the implementation of partial-rotary-embedding: ```py q_embed = torch.cat([(q_rot * cos) + (rotate_half(q_rot) * sin), q_pass], dim=-1) ``` In the special case of total-rotary-embedding, the second operand `q_pass` of the concat is empty. This also interferes with the pattern-matching for GQA in the generated graph. Optimizing the redundant Concat away will help with GQA fusion as well. Handle the edge case when all operands have zero size.
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.
We optimize
Concat (x1, x2, x3)
if one or more the concat operands has zero length along the concatenated axis-dimension.This pattern shows up, for example, in Phi models. See this line in the implementation of partial-rotary-embedding:
In the special case of total-rotary-embedding, the second operand
q_pass
of the concat is empty. This also interferes with the pattern-matching for GQA in the generated graph. Optimizing the redundant Concat away will help with GQA fusion as well.Handle the edge case when all operands have zero size.