Repository navigation
[Relax][ONNX] Add LpNormalization converter - #20818
Conversation
486e344 to
1198e63
Compare
|
@mshr-h, would you have time to review this ONNX converter, or advise how to consolidate it with the overlapping #20973? I've rebased onto current main and fixed the CPU CI oracle failure: TVM still runs all opset 13/22 cases, while the separate ONNX Runtime reference model uses its supported opset 13 kernel. The 150 related tests pass with CI's pinned ONNX/ONNX Runtime versions, including float16/bfloat16 promotion and zero-norm handling. Fresh CI results are pending. Thank you. |
1198e63 to
e23fa89
Compare
e23fa89 to
31192cd
Compare
|
you're earlier so lets work on yours. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
data.ty.dtypeis likely not a valid/portable way to access a Relax expr's dtype (Relax commonly… · New Several intermediate expressions (terms,safe_norm,result) are created without… · New This parametrization produces 144 cases, and each case compiles a fresh TVM module (via… · New This parametrization produces 144 cases, and each case compiles a fresh TVM module (via… · New
What changed in this PR
Adds Relax ONNX frontend support for the LpNormalization operator so checker-valid ONNX models can be imported and executed correctly.
Changes:
- Register a new ONNX converter for
LpNormalizationin the Relax ONNX frontend. - Implement L1/L2 normalization lowering in Relax, including fp16/bf16 accumulation in fp32.
- Add a comprehensive ONNX frontend test matrix for
LpNormalization, including invalid-pand bf16 cases.
| File | Description |
|---|---|
| tests/python/relax/test_frontend_onnx.py | Adds parameterized tests covering opsets, axes, norms (p), dtypes, symbolic shapes, and error handling for LpNormalization. |
| python/tvm/relax/frontend/onnx/onnx_frontend.py | Introduces and registers an LpNormalization converter implemented via existing Relax ops. |
Review effort: Lite
|
please check open copilot reviews. @hiyufan |
|
Thanks, @mshr-h. Addressed both open Copilot threads: made intermediate bindings explicit, and verified that All 150 related tests pass with CI-pinned ONNX/ONNX Runtime, along with file-scoped pre-commit checks. The 16 local import checks also preserve the previous IR after binding canonicalization. Fresh CI results for the follow-up commit are pending. |


The Relax ONNX frontend rejects checker-valid
LpNormalizationmodels because no converter is registered.Compose existing Relax operators for L1 and L2 normalization. Honor the default
axis=-1andp=2, use absolute values for L1, and return zero for zero-norm slices. Float16/bfloat16 inputs accumulate and divide in float32 before casting back, avoiding float16 overflow. Other input dtypes are preserved. Reject unsupported values ofp.Related to #20124 (LpNormalization only).
Validation against main
f0267a0a3e, Python 3.11, LLVM 21.1.8, and the CI-pinned ONNX 1.20.1 / ONNX Runtime 1.23.2:bb.emitbindings; 16 local L1/L2 imports across four dtypes and static/symbolic shapes remain well formed and structurally equal to the earlier version afterCanonicalizeBindings.The original CPU Jenkins failures were in the opset 22 ONNX Runtime oracle. The reference model now uses its supported opset 13 kernel without changing the model tested by TVM or skipping cases.
Prepared with OpenAI Codex assistance. The LLVM build and validation above were executed locally using the pinned TIRx/FFI sources.
The previous revision passed all eight CI checks. Fresh CI results for the review follow-up are pending.