Skip to content

Commit

Permalink
fix int16 overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Valery Chernov committed Jan 11, 2023
1 parent e43242e commit 1aa2093
Showing 1 changed file with 1 addition and 72 deletions.
73 changes: 1 addition & 72 deletions tests/python/relay/test_op_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,73 +2159,7 @@ def get_conv2d_nchw(
out_dtype=out_dtype,
)

# def verify_by_ort(x_data, w_data, b_data, data_dtype, out):
# from onnx import helper, mapping, TensorProto
# from onnxruntime import backend as ort_bk

# def get_onnx_model(data_dtype, x_shape, w_shape, b_shape, out_shape):
# x_dtype = data_dtype
# w_dtype = "int8"
# b_dtype = "int32"
# x_proto_type = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(x_dtype)]
# w_proto_type = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(w_dtype)]
# b_proto_type = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(b_dtype)]

# y_dtype = "int32"
# y_proto_type = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(y_dtype)]

# input_nodes = [
# helper.make_tensor_value_info("x", x_proto_type, list(x_shape)),
# helper.make_tensor_value_info("w", w_proto_type, list(w_shape)),
# helper.make_tensor_value_info("B", b_proto_type, list(b_shape)),
# ]
# initializer = [
# helper.make_tensor("x_scale", TensorProto.FLOAT, [], [1.]),
# helper.make_tensor("x_zero_point", x_proto_type, [], [0]),
# helper.make_tensor("w_scale", TensorProto.FLOAT, [], [1.]),
# helper.make_tensor("w_zero_point", w_proto_type, [], [0]),
# helper.make_tensor("y_scale", TensorProto.FLOAT, [], [1.]),
# helper.make_tensor("y_zero_point", y_proto_type, [], [0]),
# ]
# input_names = [
# "x",
# "x_scale",
# "x_zero_point",
# "w",
# "w_scale",
# "w_zero_point",
# "y_scale",
# "y_zero_point",
# "B"
# ]

# node_conv = helper.make_node(
# "QLinearConv",
# inputs=input_names,
# outputs=["y"],
# )

# graph = helper.make_graph(
# [node_conv],
# "ort_conv2d_int8_test",
# inputs=input_nodes,
# initializer=initializer,
# outputs=[helper.make_tensor_value_info("y", y_proto_type, list(out_shape))],
# )
# model = helper.make_model(graph, producer_name="ort_conv2d_int8_test")
# return model

# onnx_model = get_onnx_model(data_dtype, x_data.shape, w_data.shape, b_data.shape, out.shape)
# ort_exec = ort_bk.prepare(onnx_model.SerializeToString(), "CPU")
# ort_out = ort_exec.run([x_data, w_data, b_data])
# # Unpack output if there's only a single value.
# if len(ort_out) == 1:
# ort_out = ort_out[0]
# if len(out) == 1:
# out = out[0]
# np.testing.assert_equal(out, ort_out)

I, O, H, W = 64, 64, 56, 56
I, O, H, W = 1, 1, 56, 56
kH = kW = 3

data_shape = (1, I, H, W)
Expand Down Expand Up @@ -2271,11 +2205,6 @@ def get_conv2d_nchw(

out = rt_mod.get_output(0).numpy()

# print("COMPARE ORT and OUT")
# verify_by_ort(data_np, weight_np, bias_np, data_dtype, out)
# print("COMPARE ORT and REF")
# verify_by_ort(data_np, weight_np, bias_np, data_dtype, ref)

np.testing.assert_equal(out, ref)


Expand Down

0 comments on commit 1aa2093

Please sign in to comment.