Skip to content

[ONNX FE] Use MAX bias mode for L2 norm to guard zero-vector inputs#36778

Open
gblong1 wants to merge 5 commits into
openvinotoolkit:masterfrom
gblong1:l2norm_replace_add_with_max
Open

[ONNX FE] Use MAX bias mode for L2 norm to guard zero-vector inputs#36778
gblong1 wants to merge 5 commits into
openvinotoolkit:masterfrom
gblong1:l2norm_replace_add_with_max

Conversation

@gblong1

@gblong1 gblong1 commented Jul 8, 2026

Copy link
Copy Markdown

Details

  • Switched the L2 branch of lp_norm from BiasMode::ADD to BiasMode::MAX, so the epsilon bias now floors the denominator (sqrt(max(sum_of_squares, eps))) instead of being added to it (sqrt(sum_of_squares + eps)).
  • The MAX mode only affects the zero-norm case; for any nonzero norm sum(x^2) >> eps, so the output is bit-identical to the unbiased computation and normal embeddings are not perturbed by the guard.
  • Prevents division-by-zero / NaN for zero-vector inputs during L2 normalization without altering results for typical inputs.
  • One-line change (1 insertion, 1 deletion); no signature or API changes — l2_norm already supported the BiasMode::MAX path.

Tickets:

AI Assistance:

  • AI assistance used: yes
  • Used to analyze CVS-189394 and to test the impact of this change
  • Used to create the testcase

zero-norm case (sqrt(max(sum, eps))). For any nonzero norm sum(x^2) >> eps,
so the result is bit-identical to the unbiased computation and the guard
does not perturb normal embeddings
@gblong1 gblong1 requested a review from a team as a code owner July 8, 2026 22:50
@github-actions github-actions Bot added the category: ONNX FE OpenVINO ONNX FrontEnd label Jul 8, 2026
@gblong1 gblong1 requested a review from Copilot July 8, 2026 23:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the ONNX Frontend’s internal lp_norm helper so that L2 norm uses a flooring epsilon bias (sqrt(max(sum(x^2), eps))) rather than an additive bias (sqrt(sum(x^2) + eps)), aiming to stabilize normalization behavior around zero-vector inputs.

Changes:

  • Switch lp_norm(..., p_norm==2) from BiasMode::ADD to BiasMode::MAX when computing the L2 denominator.

Comment thread src/frontends/onnx/frontend/src/utils/norm.cpp
Comment thread src/frontends/onnx/frontend/src/utils/norm.cpp
@gblong1

gblong1 commented Jul 15, 2026

Copy link
Copy Markdown
Author

@mvafin - any feedback on this one? it should be a simple review.

@mvafin mvafin self-assigned this Jul 15, 2026
@mvafin mvafin self-requested a review July 15, 2026 16:27
@gblong1 gblong1 enabled auto-merge July 15, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: ONNX FE OpenVINO ONNX FrontEnd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants