Skip to content

Commit

Permalink
test dequantize linear operator
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsalashanubhag committed Jan 28, 2025
1 parent e32bff3 commit 9d3d061
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
input: "x_scale"
input: "x_zero_point"
output: "output"
name: "dequantizelinear_op"
op_type: "DequantizeLinear"
attribute {
name: "axis"
i: 1
type: INT
}
domain: "com.microsoft"
}
input {
name: "x"
type {
tensor_type {
elem_type: 3
shape {
dim {
dim_value: 2
}
dim {
dim_value: 4
}
dim {
dim_value: 3
}
}
}
}
}
input {
name: "x_scale"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
}
}
}
}
input {
name: "x_zero_point"
type {
tensor_type {
elem_type: 3
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "output"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 4
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
domain: "com.microsoft"
version: 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
input: "x_scale"
output: "output"
name: "dequantizelinear_op"
op_type: "DequantizeLinear"
domain: "com.microsoft"
}
input {
name: "x"
type {
tensor_type {
elem_type: 3
shape {
dim {
dim_value: 2
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "x_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
output {
name: "output"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
domain: "com.microsoft"
version: 1
}
36 changes: 36 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 @@ -1702,3 +1702,39 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_fast_gelu) {
test_case.add_expected_output<float>(Shape{2, 4, 3}, expected_output);
test_case.run_with_tolerance_as_fp(0.0055f);
}

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

const std::vector<int8_t> X = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
const std::vector<float> scale = {0.1f};
const std::vector<int8_t> zero_point = {0};

const std::vector<float> expected_output = {0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f,
1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f};

= test_case.add_input<int8_t>(Shape{2, 4, 3}, X);
test_case.add_input<float>(Shape{1}, scale);
test_case.add_input<int8_t>(Shape{1}, zero_point);

test_case.add_expected_output<float>(Shape{2, 4, 3}, expected_output);
test_case.run();
}

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

const std::vector<int8_t> X = {10, 20, 30, 40, 50, 60, 70, 80};
const float scale = 0.2f;

const std::vector<float> expected_output = {2.f, 4.f, 6.f, 8.f, 10.f, 12.f, 14.f, 16.f};

test_case.add_input<int8_t>(Shape{2, 4}, X);
test_case.add_input<float>(Shape{}, {scale});

test_case.add_expected_output<float>(Shape{2, 4}, expected_output);
test_case.run();
}

0 comments on commit 9d3d061

Please sign in to comment.