Skip to content
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

First version of attention fusion #1986

Merged
merged 33 commits into from
Jan 15, 2025
Merged

First version of attention fusion #1986

merged 33 commits into from
Jan 15, 2025

Conversation

gramalingam
Copy link
Collaborator

@gramalingam gramalingam commented Dec 27, 2024

First version of attention fusion.

Limitations:

  • Targetting only static shapes for now. Dynamic shapes will alter the pattern.
  • Targetting only MHA and the new onnx Attention op.

val_217 = val_216 * 32.0
val_218 = opset18.Cast(val_217, to=7)
val_219 = opset18.Concat(val_209, val_212, val_218, axis=0)
_scaled_dot_product_flash_attention_for_cpu__1 = opset18.Expand(0.0, val_219)

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable _scaled_dot_product_flash_attention_for_cpu__1 is not used.
Copy link

codecov bot commented Dec 27, 2024

❌ 8 Tests Failed:

Tests completed Failed Passed Skipped
12317 8 12309 2012
View the top 1 failed tests by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0110_test_bitshift_left_uint32
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_bitshift_left_uint32'

The above exception was the direct cause of the following exception:
.nox\test_ort_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_bitshift_left_uint32' (e=No module named 'tests.onnx_backend_test_code.test_bitshift_left_uint32') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_bitshift_left_uint32.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_bitshift_left_uint32.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 UINT32
E   from onnxscript.onnx_opset import opset11
E   
E   @script()
E   def bck_test_bitshift_left_uint32(x: UINT32[3], y: UINT32[3]) -> (UINT32[3]):
E       z = opset11.BitShift(x, y, direction='LEFT')
E       return z
View the full list of 2 ❄️ flaky tests
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0878_test_reduce_mean_do_not_keepdims_random

Flake rate in main: 16.67% (Passed 20 times, Failed 4 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_mean_do_not_keepdims_random'

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_reduce_mean_do_not_keepdims_random' (e=No module named 'tests.onnx_backend_test_code.test_reduce_mean_do_not_keepdims_random') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_reduce_mean_do_not_keepdims_random.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_reduce_mean_do_not_keepdims_random.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_mean_do_not_keepdims_random(data: FLOAT[3,2,2], axes: INT64[1]) -> (FLOAT[3,2]):
E       reduced = opset18.ReduceMean(data, axes, keepdims=0)
E       return reduced
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0981_test_resize_upsample_sizes_nearest_axes_3_2

Flake rate in main: 10.00% (Passed 27 times, Failed 3 times)

Stack Traces | 0.004s 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_resize_upsample_sizes_nearest_axes_3_2'

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_resize_upsample_sizes_nearest_axes_3_2' (e=No module named 'tests.onnx_backend_test_code.test_resize_upsample_sizes_nearest_axes_3_2') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_resize_upsample_sizes_nearest_axes_3_2.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_resize_upsample_sizes_nearest_axes_3_2.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 opset19
E   
E   @script()
E   def bck_test_resize_upsample_sizes_nearest_axes_3_2(X: FLOAT[1,1,2,2], sizes: INT64[2]) -> (FLOAT[1,1,7,8]):
E       Y = opset19.Resize(X, None, None, sizes, axes=[3, 2], mode='nearest')
E       return Y

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@gramalingam gramalingam changed the title [DRAFT: WIP] First version of attention fusion First version of attention fusion Dec 30, 2024
@justinchuby justinchuby requested a review from Copilot January 7, 2025 21:53

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 13 changed files in this pull request and generated no comments.

Files not reviewed (7)
  • onnxscript/rewriter/onnxruntime/xformers/cos_sin_cache_test.py: Evaluated as low risk
  • onnxscript/rewriter/onnxruntime/xformers/skip_normalization_test.py: Evaluated as low risk
  • onnxscript/rewriter/onnxruntime/xformers/rms_normalization_test.py: Evaluated as low risk
  • onnxscript/rewriter/onnxruntime/xformers/cos_sin_cache.py: Evaluated as low risk
  • onnxscript/rewriter/onnxruntime/xformers/_smollm_1.py: Evaluated as low risk
  • onnxscript/rewriter/onnxruntime/xformers/init.py: Evaluated as low risk
  • onnxscript/rewriter/onnxruntime/xformers/rotary_embedding_test.py: Evaluated as low risk
@gramalingam gramalingam enabled auto-merge (squash) January 15, 2025 19:27
@justinchuby
Copy link
Collaborator

The mypy checks can be ignored here:

'onnxscript/rewriter/onnxruntime/transformers/fastgelu.py', # FIXME
'onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py', # FIXME
'onnxscript/rewriter/onnxruntime/xformers/_smollm_1layer.py', # onnxscript code

@gramalingam gramalingam merged commit fe15530 into main Jan 15, 2025
23 of 27 checks passed
@gramalingam gramalingam deleted the rama/fuse-attn-2 branch January 15, 2025 23:16
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