microsoft / microsoft/onnxruntime

LayerNormFusion should reject shape-expanding scale and bias patterns

Open
#32,603 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

LayerNormFusion::ApplyImpl selects scale and bias primarily by rank and only compares their concrete dim_value() fields. It does not verify that the trailing Mul/Add preserve the normalized input shape.

As noted during review of #32058, an expanding pattern such as Mul([1, 1], [2]) + [2] can therefore be replaced with LayerNormalization, which preserves the input shape and changes semantics or fails at runtime. Different symbolic dimensions can also compare equal because dim_value() is zero when only dim_param is present.

Follow-up work:

  • Select scale and bias by graph connectivity rather than rank alone.
  • Reject fusion when the trailing broadcast is known to expand the normalized tensor.
  • Compare symbolic dimensions correctly.
  • Add positive operand-order and negative expanding-broadcast regression tests.

Related: #25855 and the sibling SimplifiedLayerNormFusion fix in #32058.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at LayerNormFusion::ApplyImpl and compare it with the sibling SimplifiedLayerNormFusion fix in #32058. Trace scale and bias through the graph, then add positive operand-order and negative expanding-broadcast regression tests; done means symbolic dimensions are distinguished and invalid expansions no longer fuse.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.