Skip to content

[Feature][Relax][ONNX] Support LpNormalization operator in Relax ONNX frontend #20969

Open

Description

@Chaitanya140904

Feature Description

Support the ONNX LpNormalization operator in the Apache TVM Relax ONNX frontend (python/tvm/relax/frontend/onnx/onnx_frontend.py).

Motivation

LpNormalization computes $ vector normalization (most commonly $ or $ norm) along a specified axis. It is universally used as the final projection layer in text embedding, multi-modal embedding, and vector retrieval models (such as BGE, E5, OpenAI CLIP, and sentence-transformers) to normalize feature vectors onto the unit sphere for cosine similarity and vector search.

Importing embedding models containing LpNormalization currently fails in the Relax ONNX frontend with:

NotImplementedError: The following operators are not supported: ['LpNormalization']

This operator was also highlighted in the ONNX operator coverage RFC tracking issue #20124 under Activations / Math operators.

Operator Specification (ONNX Opset 1+)

  • Inputs:
    1. input: N-D input tensor of floating-point type (float32, float16, bfloat16).
  • Attributes:
    • axis: int (default -1) - the axis along which the norm is computed.
    • p: int (default 2) - the order of the norm (=1$ for $, =2$ for $).
  • Outputs:
    1. output: Normalized tensor with identical shape and dtype as input.

Expected Behavior

The Relax ONNX frontend should implement LpNormalization using Relax arithmetic operations:

  1. For =2$: compute norm = relax.op.sqrt(relax.op.sum(relax.op.square(input), axis=axis, keepdims=True)) and return relax.op.divide(input, norm) (with safe numerical epsilon).
  2. For =1$: compute norm = relax.op.sum(relax.op.abs(input), axis=axis, keepdims=True) and return relax.op.divide(input, norm).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions