Skip to content

Fusion for partial rotary embedding #2095

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 8 commits into from
Mar 12, 2025
Merged

Fusion for partial rotary embedding #2095

merged 8 commits into from
Mar 12, 2025

Conversation

gramalingam
Copy link
Collaborator

Add a fusion rule for recognizing partial rotary embedding, along with test case.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR adds support for partial rotary embedding by introducing a new fusion rule and a corresponding test case. Key changes include:

  • Introducing a partial rotary embedding fusion rule in the rotary_embedding module.
  • Adding a new test case for partial rotary embedding in cos_sin_cache_test.
  • Updating function signatures (e.g. fuse_cos_sin_cache now requires a debug flag) and enhancing utility functions.

Reviewed Changes

File Description
onnxscript/rewriter/ort_fusions/cos_sin_cache_test.py Added a new test method and updated import/test case list to include partial rotary embedding.
onnxscript/rewriter/ort_fusions/cos_sin_cache.py Modified fuse_cos_sin_cache signature to require a debug flag and added a new rewrite rule.
onnxscript/rewriter/ort_fusions/_rotary_embedding_models.py Added a partial rotary embedding test case and supporting class.
onnxscript/rewriter/ort_fusions/rotary_embedding.py Added PartialRotaryEmbeddingFusion rule and updated the fusion functions.
onnxscript/rewriter/_ir_utils.py Updated get_singleton_value to optionally validate tensor rank.
onnxscript/rewriter/llama_rule_sets.py Updated rule set to include squeeze_reshape_1d_rule.

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Copy link

codecov bot commented Mar 10, 2025

❌ 6 Tests Failed:

Tests completed Failed Passed Skipped
11765 6 11759 2406
View the top 1 failed test(s) by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0658_test_min_float64
Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_min_float64'

The above exception was the direct cause of the following exception:
.nox\test_torch_nightly\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_min_float64' (e=No module named 'tests.onnx_backend_test_code.test_min_float64') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_min_float64.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_min_float64.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import DOUBLE
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_min_float64(data_0: DOUBLE[3], data_1: DOUBLE[3]) -> (DOUBLE[3]):
E       result = opset13.Min(data_0, data_1)
E       return result
View the full list of 2 ❄️ flaky tests
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0818_test_reduce_l1_empty_set

Flake rate in main: 18.18% (Passed 9 times, Failed 2 times)

Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_reduce_l1_empty_set'

The above exception was the direct cause of the following exception:
.nox\test_torch_nightly\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_reduce_l1_empty_set' (e=No module named 'tests.onnx_backend_test_code.test_reduce_l1_empty_set') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_reduce_l1_empty_set.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_reduce_l1_empty_set.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT, INT64
E   from onnxscript.onnx_opset import opset18
E   
E   @script()
E   def bck_test_reduce_l1_empty_set(data: FLOAT[2,0,4], axes: INT64[1]) -> (FLOAT[2,1,4]):
E       reduced = opset18.ReduceL1(data, axes, keepdims=1)
E       return reduced
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0648_test_min_float16

Flake rate in main: 7.14% (Passed 26 times, Failed 2 times)

Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.12.9\x64\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_min_float16'

The above exception was the direct cause of the following exception:
.nox\test\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_min_float16' (e=No module named 'tests.onnx_backend_test_code.test_min_float16') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_min_float16.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_min_float16.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT16
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_min_float16(data_0: FLOAT16[3], data_1: FLOAT16[3]) -> (FLOAT16[3]):
E       result = opset13.Min(data_0, data_1)
E       return result

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@gramalingam gramalingam enabled auto-merge (squash) March 11, 2025 23:36
@gramalingam gramalingam merged commit 882a442 into main Mar 12, 2025
18 of 27 checks passed
@gramalingam gramalingam deleted the rama/partial-rotary branch March 12, 2025 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants