Skip to content
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

[ONNX]: Added Range from com.microsoft domain #28202

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/frontends/onnx/frontend/src/op/com.microsoft/range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2018-2024 Intel Corporation
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: Apache-2.0
//

#include "core/operator_set.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/ops.hpp"

using namespace ov::op;

namespace ov {
namespace frontend {
namespace onnx {
namespace com_microsoft {
namespace opset_1 {
ov::OutputVector range(const ov::frontend::onnx::Node& node) {
auto nodes = node.get_ov_inputs();
FRONT_END_GENERAL_CHECK(nodes.size() >= 2 && nodes.size() <= 3,
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
"Range takes 2 or 3 inputs. Provided " + std::to_string(nodes.size()));
auto start = nodes.at(0);
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
auto limit = nodes.at(1);
auto step =
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.Range

Documentation requires same input tensors for all inputs. Could you add a check for element types?

Like here:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this , but this is causing repeated code which I think is not preferred , so should I put this in a loop or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also I have changed step to delta to keep it consistent with documentation.
thank you

nodes.size() == 3 ? nodes.at(2) : ov::op::v0::Constant::create(start.get_element_type(), ov::Shape{}, {1});
return {std::make_shared<ov::op::v4::Range>(start, limit, step, start.get_element_type())};
}
ONNX_OP("Range", OPSET_SINCE(1), com_microsoft::opset_1::range, MICROSOFT_DOMAIN);
} // namespace opset_1
} // namespace com_microsoft
} // namespace onnx
} // namespace frontend
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ir_version: 6
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "start"
input: "limit"
input: "delta"
output: "output"
op_type: "Range"
}
name: "test_range_float_type_with_delta"
input {
name: "start"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "limit"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "delta"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
output {
name: "output"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 10
}
}
}
}
}
}
opset_import {
version: 1
domain: "com.microsoft"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ir_version: 6
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "start"
input: "limit"
output: "output"
op_type: "Range"
}
name: "test_range_float_type_without_delta"
input {
name: "start"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "limit"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
output {
name: "output"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 10
}
}
}
}
}
}
opset_import {
version: 1
domain: "com.microsoft"
}
23 changes: 23 additions & 0 deletions src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,3 +1488,26 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_matmul_integer_to_float) {

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_range_with_delta) {
const auto model = convert_model("com.microsoft/range_with_delta.onnx");
auto test_case = ov::test::TestCase(model, s_device);

test_case.add_input<float>({0.f});
test_case.add_input<float>({10.f});
test_case.add_input<float>({1.f});
test_case.add_expected_output<float>(Shape{10}, {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f});

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_range_without_delta) {
const auto model = convert_model("com.microsoft/range_without_delta.onnx");
auto test_case = ov::test::TestCase(model, s_device);

test_case.add_input<float>({0.f});
test_case.add_input<float>({10.f});
test_case.add_expected_output<float>(Shape{10}, {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f});

test_case.run();
}
Loading