Commit 9560c1fa authored by Michał Karzyński's avatar Michał Karzyński Committed by Scott Cyphers

[ONNX] Unit tests for QLinearMatMul (#2706)

* [ONNX] Unit test models for QLinearMatMul

* [ONNX] Extended types support for NgraphTestCase

* [ONNX] Move the value comparators to the NgraphTestCase class

* Add test cases

* Add shape checking

* disable GPU tests
parent d169f929
......@@ -128,6 +128,8 @@ model_quantize_linear_axis_negative
model_quant_conv_linear
model_quant_conv_linear_2d
model_quant_conv_linear_3d
model_qlinear_matmul
model_qlinear_matmul_3d
# This should be implemented
create_tensor_2_input
......
# Quantized convolution is not supported on interpreter
model_quant_conv_linear
model_qlinear_matmul
model_qlinear_matmul_3d
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "T1"
input: "a_scale"
input: "a_zero_point"
input: "T2"
input: "b_scale"
input: "b_zero_point"
input: "y_scale"
input: "y_zero_point"
output: "T3"
name: "node1"
op_type: "QLinearMatMul"
}
name: "test"
input {
name: "T1"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 2
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "a_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "a_zero_point"
type {
tensor_type {
elem_type: 2
shape {
}
}
}
}
input {
name: "T2"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 4
}
dim {
dim_value: 3
}
}
}
}
}
input {
name: "b_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "b_zero_point"
type {
tensor_type {
elem_type: 2
shape {
}
}
}
}
input {
name: "y_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "y_zero_point"
type {
tensor_type {
elem_type: 2
shape {
}
}
}
}
output {
name: "T3"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 2
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 10
}
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "T1"
input: "a_scale"
input: "a_zero_point"
input: "T2"
input: "b_scale"
input: "b_zero_point"
input: "y_scale"
input: "y_zero_point"
output: "T3"
name: "node1"
op_type: "QLinearMatMul"
}
name: "test"
input {
name: "T1"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "a_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "a_zero_point"
type {
tensor_type {
elem_type: 2
shape {
}
}
}
}
input {
name: "T2"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 2
}
dim {
dim_value: 4
}
dim {
dim_value: 3
}
}
}
}
}
input {
name: "b_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "b_zero_point"
type {
tensor_type {
elem_type: 2
shape {
}
}
}
}
input {
name: "y_scale"
type {
tensor_type {
elem_type: 1
shape {
}
}
}
}
input {
name: "y_zero_point"
type {
tensor_type {
elem_type: 2
shape {
}
}
}
}
output {
name: "T3"
type {
tensor_type {
elem_type: 2
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 10
}
......@@ -292,3 +292,49 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, model_quant_conv_linear_3d)
{1, 1, 4, 4, 4}, TEST_FILES, "onnx/qlinearconv3d/y.bin");
test_case.run();
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_qlinear_matmul)
{
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/qlinear_matmul.prototxt"));
auto test_case = ngraph::test::NgraphTestCase(function, "${BACKEND_NAME}");
test_case.add_input(std::vector<uint8_t>{208, 236, 0, 238, 3, 214, 255, 29}); // T1
test_case.add_input(std::vector<float>{0.0066f}); // a_scale
test_case.add_input(std::vector<uint8_t>{113}); // a_zero_point
test_case.add_input(
std::vector<uint8_t>{152, 51, 244, 60, 26, 255, 0, 127, 246, 127, 254, 247}); // T2
test_case.add_input(std::vector<float>{0.00705f}); // b_scale
test_case.add_input(std::vector<uint8_t>{114}); // b_zero_point
test_case.add_input(std::vector<float>{0.0107f}); // y_scale
test_case.add_input(std::vector<uint8_t>{118}); // y_zero_point
test_case.add_expected_output({2, 3}, std::vector<uint8_t>{168, 115, 255, 1, 66, 151}); // T3
test_case.run();
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_qlinear_matmul_3d)
{
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/qlinear_matmul_3d.prototxt"));
auto test_case = ngraph::test::NgraphTestCase(function, "${BACKEND_NAME}");
test_case.add_input(std::vector<uint8_t>{
208, 236, 0, 238, 3, 214, 255, 29, 208, 236, 0, 238, 3, 214, 255, 29}); // T1
test_case.add_input(std::vector<float>{0.0066f}); // a_scale
test_case.add_input(std::vector<uint8_t>{113}); // a_zero_point
test_case.add_input(std::vector<uint8_t>{152, 51, 244, 60, 26, 255, 0, 127,
246, 127, 254, 247, 152, 51, 244, 60,
26, 255, 0, 127, 246, 127, 254, 247}); // T2
test_case.add_input(std::vector<float>{0.00705f}); // b_scale
test_case.add_input(std::vector<uint8_t>{114}); // b_zero_point
test_case.add_input(std::vector<float>{0.0107f}); // y_scale
test_case.add_input(std::vector<uint8_t>{118}); // y_zero_point
test_case.add_expected_output(
{2, 2, 3},
std::vector<uint8_t>{168, 115, 255, 1, 66, 151, 168, 115, 255, 1, 66, 151}); // T3
test_case.run();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment