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

Implement LayerNormalization fusion #280

Merged
merged 3 commits into from
Jul 12, 2024
Merged

Implement LayerNormalization fusion #280

merged 3 commits into from
Jul 12, 2024

Conversation

robertknight
Copy link
Owner

@robertknight robertknight commented Jul 12, 2024

This fuses subgraphs like below, excluding the "Add" in the top left corner, into a LayerNormalization operator:

Layer norm fusion

So far this has been tested with BERT, GPT-2 and Whisper models.

This is a rather complex fusion and as a result, is liable to be brittle. That is, other equivalent ways of expressing the operator will not match. Also it doesn't help with operators which are variations of this such as RMSNorm (used in Llama etc.). In future it would probably make sense to break this up so that the individual sub-steps (centering, variance normalization, shift + scale) are fused separately.

TODO:

  • Tests

@robertknight robertknight force-pushed the fuse-layer-norm branch 2 times, most recently from 5e90d30 to 779d6e3 Compare July 12, 2024 07:19
This is useful for extracting constant values from nodes when creating graph
optimizations.
 - Add the ability to create symbols which match only constant values
 - Add the ability to give operators in patterns an identifier which can be used
   to look up the operator node after the pattern has matched.  This is useful
   to perform additional tests on the operator such as matching particular
   attributes.
@robertknight robertknight marked this pull request as ready for review July 12, 2024 18:18
@robertknight robertknight merged commit 8eabc81 into main Jul 12, 2024
2 checks passed
@robertknight robertknight deleted the fuse-layer-norm branch July 12, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant