-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Adding support for custom ort tokenizer ops and ai.onnx.ml normalizer #34721
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
Merged
sfatimar
merged 26 commits into
openvinotoolkit:master
from
sfatimar:add_normalizer_ovtokenizer_ops
May 1, 2026
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d8b40d1
Add normalizer ovtokenizer ops (#3)
sfatimar 2a4c35c
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 639fd88
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar fd21dcb
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar cea5982
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 9ef97c7
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 3c111d7
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 69e6229
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 54095ef
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar b390d5e
Removed Layer tests
sfatimar f451665
Deleted Normalizer Model Prototxt
sfatimar e299998
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 90c88e4
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 82ab91b
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar b81d0f1
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 024bd0b
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar ce4a8c9
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 3e49732
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar a86e9d0
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar a040cf1
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar c116aa1
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 6e1dd9e
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 48aa283
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 46c46eb
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 93f0a4b
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar 8bddc6b
Merge branch 'master' into add_normalizer_ovtokenizer_ops
sfatimar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/frontends/onnx/frontend/src/op/ai.onnx.ml/normalizer.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| #include <cmath> | ||
| #include <numeric> | ||
|
|
||
| #include "core/operator_set.hpp" | ||
| #include "exceptions.hpp" | ||
| #include "openvino/frontend/exception.hpp" | ||
| #include "openvino/op/abs.hpp" | ||
| #include "openvino/op/constant.hpp" | ||
| #include "openvino/op/convert.hpp" | ||
| #include "openvino/op/divide.hpp" | ||
| #include "openvino/op/equal.hpp" | ||
| #include "openvino/op/multiply.hpp" | ||
| #include "openvino/op/power.hpp" | ||
| #include "openvino/op/reduce_max.hpp" | ||
| #include "openvino/op/reduce_sum.hpp" | ||
| #include "openvino/op/select.hpp" | ||
| #include "openvino/op/sqrt.hpp" | ||
| #include "utils/common.hpp" | ||
|
|
||
| using namespace ov::op; | ||
|
|
||
|
sfatimar marked this conversation as resolved.
|
||
| namespace ov { | ||
| namespace frontend { | ||
| namespace onnx { | ||
| namespace ai_onnx_ml { | ||
| namespace opset_1 { | ||
|
|
||
| const ov::Output<ov::Node> check_zero_divisor(const ov::Output<ov::Node>& val) { | ||
| const auto zero = ov::op::v0::Constant::create(val.get_element_type(), ov::Shape{}, {0.0f}); | ||
| const auto one_val = ov::op::v0::Constant::create(val.get_element_type(), ov::Shape{}, {1.0f}); | ||
| const auto is_zero = std::make_shared<ov::op::v1::Equal>(val, zero); | ||
| return std::make_shared<ov::op::v1::Select>(is_zero, one_val, val); | ||
| } | ||
|
|
||
| ov::OutputVector normalizer(const ov::frontend::onnx::Node& node) { | ||
| // Step 1: Get input tensor | ||
| const auto input = node.get_ov_inputs()[0]; | ||
|
|
||
| CHECK_VALID_NODE(node, | ||
| input.get_element_type() == ov::element::f64 || input.get_element_type() == ov::element::f32 || | ||
| input.get_element_type() == ov::element::i64 || input.get_element_type() == ov::element::i32, | ||
| "Unsupported input type, accepted FP32, FP64, I64, I32 got: ", | ||
| input.get_element_type()); | ||
|
|
||
| const auto normalization_type = node.get_attribute_value<std::string>("norm", "MAX"); | ||
|
|
||
| CHECK_VALID_NODE(node, | ||
| normalization_type == "MAX" || normalization_type == "L1" || normalization_type == "L2", | ||
| "Normalization Mode should be either MAX, L1 or L2, got ", | ||
| normalization_type); | ||
|
|
||
| auto float_input = std::make_shared<ov::op::v0::Convert>(input, ov::element::f32); | ||
| const auto x = std::make_shared<ov::op::v0::Abs>(float_input); | ||
| const auto axes = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); // e.g., last axis | ||
| if (normalization_type == "L1") { | ||
| const auto sum_x = std::make_shared<ov::op::v1::ReduceSum>(x, axes, true); | ||
| const auto safe_x = check_zero_divisor(sum_x); | ||
| return {std::make_shared<ov::op::v1::Divide>(float_input, safe_x)}; | ||
| } else if (normalization_type == "L2") { | ||
| const auto x_squared = std::make_shared<ov::op::v1::Multiply>(x, x); | ||
| const auto sum_sqrdx = std::make_shared<ov::op::v1::ReduceSum>(x_squared, axes, true); | ||
| const auto sqrt_sum_sqrdx = std::make_shared<ov::op::v0::Sqrt>(sum_sqrdx); | ||
| const auto safe_x = check_zero_divisor(sqrt_sum_sqrdx); | ||
| const auto result = std::make_shared<ov::op::v1::Divide>(float_input, safe_x); | ||
| return {result}; | ||
| } else { // Must be max | ||
| const auto max_x = std::make_shared<ov::op::v1::ReduceMax>(x, axes, /*keep_dims=*/true); | ||
| const auto safe_x = check_zero_divisor(max_x); | ||
| return {std::make_shared<ov::op::v1::Divide>(float_input, safe_x)}; | ||
| } | ||
| } | ||
|
|
||
| ONNX_OP("Normalizer", OPSET_SINCE(1), ai_onnx_ml::opset_1::normalizer, AIONNX_ML_DOMAIN); | ||
| } // namespace opset_1 | ||
| } // namespace ai_onnx_ml | ||
| } // namespace onnx | ||
| } // namespace frontend | ||
| } // namespace ov | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/frontends/onnx/tests/models/ai.onnx.ml/normalizer_l1.prototxt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ir_version: 7 | ||
| producer_name: "OpenVINO ONNX Frontend" | ||
| graph { | ||
| node { | ||
| input: "X" | ||
| output: "Y" | ||
| name: "Normalizer_L1" | ||
| op_type: "Normalizer" | ||
| attribute { | ||
| name: "norm" | ||
| s: "L1" | ||
| type: STRING | ||
| } | ||
| domain: "ai.onnx.ml" | ||
| } | ||
| name: "normalizer_l1_graph" | ||
| input { | ||
| name: "X" | ||
| type { | ||
| tensor_type { | ||
| elem_type: 1 | ||
| shape { | ||
| dim { | ||
| dim_value: 2 | ||
| } | ||
| dim { | ||
| dim_value: 3 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| output { | ||
| name: "Y" | ||
| type { | ||
| tensor_type { | ||
| elem_type: 1 | ||
| shape { | ||
| dim { | ||
| dim_value: 2 | ||
| } | ||
| dim { | ||
| dim_value: 3 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| opset_import { | ||
| version: 15 | ||
| } | ||
| opset_import { | ||
| domain: "ai.onnx.ml" | ||
| version: 3 | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/frontends/onnx/tests/models/ai.onnx.ml/normalizer_l2.prototxt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ir_version: 7 | ||
| producer_name: "OpenVINO ONNX Frontend" | ||
| graph { | ||
| node { | ||
| input: "X" | ||
| output: "Y" | ||
| name: "Normalizer_L2" | ||
| op_type: "Normalizer" | ||
| attribute { | ||
| name: "norm" | ||
| s: "L2" | ||
| type: STRING | ||
| } | ||
| domain: "ai.onnx.ml" | ||
| } | ||
| name: "normalizer_l2_graph" | ||
| input { | ||
| name: "X" | ||
| type { | ||
| tensor_type { | ||
| elem_type: 1 | ||
| shape { | ||
| dim { | ||
| dim_value: 3 | ||
| } | ||
| dim { | ||
| dim_value: 4 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| output { | ||
| name: "Y" | ||
| type { | ||
| tensor_type { | ||
| elem_type: 1 | ||
| shape { | ||
| dim { | ||
| dim_value: 3 | ||
| } | ||
| dim { | ||
| dim_value: 4 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| opset_import { | ||
| version: 15 | ||
| } | ||
| opset_import { | ||
| domain: "ai.onnx.ml" | ||
| version: 3 | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/frontends/onnx/tests/models/ai.onnx.ml/normalizer_max.prototxt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ir_version: 7 | ||
| producer_name: "OpenVINO ONNX Frontend" | ||
| graph { | ||
| node { | ||
| input: "X" | ||
| output: "Y" | ||
| name: "Normalizer_MAX" | ||
| op_type: "Normalizer" | ||
| attribute { | ||
| name: "norm" | ||
| s: "MAX" | ||
| type: STRING | ||
| } | ||
| domain: "ai.onnx.ml" | ||
| } | ||
| name: "normalizer_max_graph" | ||
| input { | ||
| name: "X" | ||
| type { | ||
| tensor_type { | ||
| elem_type: 1 | ||
| shape { | ||
| dim { | ||
| dim_value: 2 | ||
| } | ||
| dim { | ||
| dim_value: 5 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| output { | ||
| name: "Y" | ||
| type { | ||
| tensor_type { | ||
| elem_type: 1 | ||
| shape { | ||
| dim { | ||
| dim_value: 2 | ||
| } | ||
| dim { | ||
| dim_value: 5 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| opset_import { | ||
| version: 15 | ||
| } | ||
| opset_import { | ||
| domain: "ai.onnx.ml" | ||
| version: 3 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.