Add initial support for RotaryEmbedding fusion for onnx opset 23#2450
Add initial support for RotaryEmbedding fusion for onnx opset 23#2450gramalingam merged 7 commits intomainfrom
Conversation
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
❌ 9 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
| # def rotate_half(x): | ||
| # """Rotates half the hidden dims of the input.""" | ||
| # x1 = x[..., : x.shape[-1] // 2] | ||
| # x2 = x[..., x.shape[-1] // 2 :] | ||
| # return torch.cat((-x2, x1), dim=-1) | ||
| # and | ||
| # q_embed = (q * cos) + (rotate_half(q) * sin) |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
The best way to address the issue is to remove the commented-out code and replace it with a concise, well-structured explanation of the referenced logic. The explanation can include a link to the external function's implementation in Hugging Face's repository and a summary of what the function does, ensuring clarity without including raw commented-out code.
Specifically:
- Remove the commented-out
rotate_halffunction code (lines 13-20). - Replace it with a concise comment explaining the logic and its relevance to
_rotate_half_pattern. - Retain the link to the external repository for further reference.
| @@ -10,15 +10,11 @@ | ||
|
|
||
| # Basic pattern: For example, see | ||
| # https://github.com/huggingface/transformers/blob/541bed22d6e4f97946a3a7d74f7e1a353e58643b/src/transformers/models/llama/modeling_llama.py#L104 | ||
| # def rotate_half(x): | ||
| # """Rotates half the hidden dims of the input.""" | ||
| # x1 = x[..., : x.shape[-1] // 2] | ||
| # x2 = x[..., x.shape[-1] // 2 :] | ||
| # return torch.cat((-x2, x1), dim=-1) | ||
| # and | ||
| # q_embed = (q * cos) + (rotate_half(q) * sin) | ||
| # The Hugging Face implementation includes a function `rotate_half` that splits the input tensor | ||
| # into two halves along the last dimension, rotates one half, and concatenates them back. | ||
| # This logic is used in operations like `q_embed = (q * cos) + (rotate_half(q) * sin)`. | ||
| # The `_rotate_half_pattern` function below implements equivalent functionality using ONNX ops. | ||
|
|
||
|
|
||
| def _rotate_half_pattern(op, x, start1, end1, start2, end2): | ||
| # Slice(input, starts, ends, axes, steps) | ||
| x1 = op.Slice(x, start1, end1, [3], [1]) |
|
Looks like there is merge conflicts |
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Resolved |
Add initial support for RotaryEmbedding fusion for onnx opset 23