From 3a15ea15409d995e352d288a1eeccfbfb2751b8d Mon Sep 17 00:00:00 2001 From: Yuantao Feng Date: Tue, 13 Aug 2024 16:44:32 +0800 Subject: [PATCH] add models and data converted from onnx conformance --- testdata/dnn/onnx/data/input_top_k.pb | Bin 0 -> 56 bytes .../onnx/data/input_top_k_negative_axis.pb | Bin 0 -> 56 bytes .../dnn/onnx/data/input_top_k_smallest.pb | Bin 0 -> 56 bytes testdata/dnn/onnx/data/output_top_k_0.pb | Bin 0 -> 44 bytes testdata/dnn/onnx/data/output_top_k_1.pb | Bin 0 -> 80 bytes .../onnx/data/output_top_k_negative_axis_0.pb | Bin 0 -> 44 bytes .../onnx/data/output_top_k_negative_axis_1.pb | Bin 0 -> 80 bytes .../dnn/onnx/data/output_top_k_smallest_0.pb | Bin 0 -> 44 bytes .../dnn/onnx/data/output_top_k_smallest_1.pb | Bin 0 -> 80 bytes .../generate_onnx_models_with_onnxscript.py | 71 +++++++++++++++--- testdata/dnn/onnx/models/top_k.onnx | Bin 0 -> 214 bytes .../dnn/onnx/models/top_k_negative_axis.onnx | Bin 0 -> 237 bytes testdata/dnn/onnx/models/top_k_smallest.onnx | Bin 0 -> 254 bytes 13 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 testdata/dnn/onnx/data/input_top_k.pb create mode 100644 testdata/dnn/onnx/data/input_top_k_negative_axis.pb create mode 100644 testdata/dnn/onnx/data/input_top_k_smallest.pb create mode 100644 testdata/dnn/onnx/data/output_top_k_0.pb create mode 100644 testdata/dnn/onnx/data/output_top_k_1.pb create mode 100644 testdata/dnn/onnx/data/output_top_k_negative_axis_0.pb create mode 100644 testdata/dnn/onnx/data/output_top_k_negative_axis_1.pb create mode 100644 testdata/dnn/onnx/data/output_top_k_smallest_0.pb create mode 100644 testdata/dnn/onnx/data/output_top_k_smallest_1.pb create mode 100644 testdata/dnn/onnx/models/top_k.onnx create mode 100644 testdata/dnn/onnx/models/top_k_negative_axis.onnx create mode 100644 testdata/dnn/onnx/models/top_k_smallest.onnx diff --git a/testdata/dnn/onnx/data/input_top_k.pb b/testdata/dnn/onnx/data/input_top_k.pb new file mode 100644 index 0000000000000000000000000000000000000000..9b427a248fa32bc060984e5d313d8ccff78d6747 GIT binary patch literal 56 ucmd;J=3o(E^fF)og9dvbdE> literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/data/output_top_k_negative_axis_0.pb b/testdata/dnn/onnx/data/output_top_k_negative_axis_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..b021689446d811ce7a306bfe7a70759fe6342ebd GIT binary patch literal 44 scmd;J=3o|J^ipA9aByG%5)2Ft_6!UUfb;<%UI4@fjtmS6KrG-00Dh$gH~;_u literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/data/output_top_k_negative_axis_1.pb b/testdata/dnn/onnx/data/output_top_k_negative_axis_1.pb new file mode 100644 index 0000000000000000000000000000000000000000..4158cd01cf9fb6e1bdc2c75b115da18f849c3ba4 GIT binary patch literal 80 acmd;J=3o|J_wrz7fB+^a%?PDQ6$b!1%>dE> literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/data/output_top_k_smallest_0.pb b/testdata/dnn/onnx/data/output_top_k_smallest_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..7a3d13db91ffa0d017b5bf04db0427efb3e24ca1 GIT binary patch literal 44 ocmd;J=3o|J^ip8}g9dvb<-owu0K^M`_y7 ost.FLOAT[1, 8, 12, def matmul_bcast(x: ost.FLOAT[64, 1, 16]) -> ost.FLOAT[64, 1, 8]: return op.MatMul(x, op.Constant(value=onnx.numpy_helper.from_array(B))) make_model_and_data(matmul_bcast, np.random.randn(64, 1, 16).astype(np.float32)) + +''' TopK conformance +''' + +top_k_K_arr = np.array([3], dtype=np.int64) +@ost.script() +def top_k(x: ost.FLOAT[3, 4]) -> (ost.FLOAT[3, 3], ost.INT64[3, 3]): + values, indices = op.TopK(x, op.Constant(value=onnx.numpy_helper.from_array(top_k_K_arr)), axis=1) + return values, indices + +@ost.script() +def top_k_negative_axis(x: ost.FLOAT[3, 4]) -> (ost.FLOAT[3, 3], ost.INT64[3, 3]): + values, indices = op.TopK(x, op.Constant(value=onnx.numpy_helper.from_array(top_k_K_arr)), axis=-1) + return values, indices + +@ost.script() +def top_k_smallest(x: ost.FLOAT[3, 4]) -> (ost.FLOAT[3, 3], ost.INT64[3, 3]): + values, indices = op.TopK(x, op.Constant(value=onnx.numpy_helper.from_array(top_k_K_arr)), axis=1, largest=0, sorted=1) + return values, indices + +top_k_input0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] +top_k_input1 = [0, 1, 2, 3, 4, 5, 6, 7, 11, 10, 9, 8] +top_k_input0_arr = np.array(top_k_input0, dtype=np.float32).reshape(3, 4) +top_k_input1_arr = np.array(top_k_input1, dtype=np.float32).reshape(3, 4) +make_model_and_data(top_k, top_k_input0_arr, save_inputs_as_pb=True, save_outputs_as_pb=True) +make_model_and_data(top_k_negative_axis, top_k_input0_arr, save_inputs_as_pb=True, save_outputs_as_pb=True) +make_model_and_data(top_k_smallest, top_k_input1_arr, save_inputs_as_pb=True, save_outputs_as_pb=True) diff --git a/testdata/dnn/onnx/models/top_k.onnx b/testdata/dnn/onnx/models/top_k.onnx new file mode 100644 index 0000000000000000000000000000000000000000..9d00cd4ec913d89408d9396be01f47201a3f0c08 GIT binary patch literal 214 zcmY+8y$*sf6op$_?Dc90mIWCZnZ%J%H(i}v3@8Ks6p~iM`gJ1%siUNQL7lXwbCY6CW+8}<@aZqctCxz14f4HD9;G4k+%4yIu=cxqCf{u<%x-#mflZlgysX`2jKx{QU4)5p-SRtBt$v0fSU+Bj# ziVMlit(rQ;d