new ops tests for matmul, grouped conv, concat and reshape
Validate Operations / validate-operations (push) Has been cancelled

related fixes
This commit is contained in:
NiccoloN
2026-05-14 15:54:06 +02:00
parent d09e76c8f9
commit fe244d5aa1
10 changed files with 186 additions and 12 deletions
+96
View File
@@ -154,6 +154,33 @@ def conv_large_spatial():
save_model(model, "conv/large_spatial", "conv_large_spatial.onnx")
def conv_grouped_two_groups():
"""Grouped Conv with two groups, pointwise kernels, and bias."""
rng = np.random.default_rng(59)
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [1, 4, 4, 4])
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [1, 4, 4, 4])
W = numpy_helper.from_array(rng.uniform(-1, 1, (4, 2, 1, 1)).astype(np.float32), name="W")
B = numpy_helper.from_array(rng.uniform(-1, 1, (4,)).astype(np.float32), name="B")
node = helper.make_node("Conv", ["X", "W", "B"], ["Y"],
kernel_shape=[1, 1], strides=[1, 1], pads=[0, 0, 0, 0], group=2)
graph = helper.make_graph([node], "conv_grouped_two_groups", [X], [Y], initializer=[W, B])
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
save_model(model, "conv/grouped_two_groups", "conv_grouped_two_groups.onnx")
def conv_depthwise_grouped():
"""Depthwise-style grouped Conv with one input channel per group."""
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [1, 3, 4, 4])
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [1, 3, 2, 2])
W = numpy_helper.from_array(
np.random.default_rng(60).uniform(-1, 1, (3, 1, 3, 3)).astype(np.float32), name="W")
node = helper.make_node("Conv", ["X", "W"], ["Y"],
kernel_shape=[3, 3], strides=[1, 1], pads=[0, 0, 0, 0], group=3)
graph = helper.make_graph([node], "conv_depthwise_grouped", [X], [Y], initializer=[W])
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
save_model(model, "conv/depthwise_grouped", "conv_depthwise_grouped.onnx")
# ---------------------------------------------------------------------------
# GEMM tests
# ---------------------------------------------------------------------------
@@ -252,6 +279,33 @@ def gemm_transB_with_bias():
save_model(model, "gemm/transB_with_bias", "gemm_transB_with_bias.onnx")
# ---------------------------------------------------------------------------
# MatMul tests
# ---------------------------------------------------------------------------
def matmul_basic():
"""Direct 2D MatMul with constant RHS."""
A = helper.make_tensor_value_info("A", TensorProto.FLOAT, [2, 3])
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [2, 4])
B = numpy_helper.from_array(np.random.default_rng(49).uniform(-1, 1, (3, 4)).astype(np.float32), name="B")
node = helper.make_node("MatMul", ["A", "B"], ["Y"])
graph = helper.make_graph([node], "matmul_basic", [A], [Y], initializer=[B])
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
save_model(model, "matmul/basic", "matmul_basic.onnx")
def matmul_batched_3d():
"""Batched 3D MatMul with matching batch dimensions."""
rng = np.random.default_rng(50)
A = helper.make_tensor_value_info("A", TensorProto.FLOAT, [2, 2, 3])
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [2, 2, 4])
B = numpy_helper.from_array(rng.uniform(-1, 1, (2, 3, 4)).astype(np.float32), name="B")
node = helper.make_node("MatMul", ["A", "B"], ["Y"])
graph = helper.make_graph([node], "matmul_batched_3d", [A], [Y], initializer=[B])
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
save_model(model, "matmul/batched_3d", "matmul_batched_3d.onnx")
# ---------------------------------------------------------------------------
# Pooling tests
# ---------------------------------------------------------------------------
@@ -607,6 +661,36 @@ def gather_axis0_matrix_indices():
save_model(model, "gather/axis0_matrix_indices", "gather_axis0_matrix_indices.onnx")
# ---------------------------------------------------------------------------
# Concat tests
# ---------------------------------------------------------------------------
def concat_channel_axis():
"""Concat two runtime NCHW tensors along the channel axis."""
A = helper.make_tensor_value_info("A", TensorProto.FLOAT, [1, 1, 2, 2])
B = helper.make_tensor_value_info("B", TensorProto.FLOAT, [1, 2, 2, 2])
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [1, 3, 2, 2])
node = helper.make_node("Concat", ["A", "B"], ["Y"], axis=1)
graph = helper.make_graph([node], "concat_channel_axis", [A, B], [Y])
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
save_model(model, "concat/channel_axis", "concat_channel_axis.onnx")
# ---------------------------------------------------------------------------
# Reshape tests
# ---------------------------------------------------------------------------
def reshape_same_rank():
"""Runtime tensor Reshape with a static shape initializer and unchanged rank."""
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [2, 3])
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [3, 2])
shape = make_int64_initializer("shape", [3, 2])
node = helper.make_node("Reshape", ["X", "shape"], ["Y"])
graph = helper.make_graph([node], "reshape_same_rank", [X], [Y], initializer=[shape])
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
save_model(model, "reshape/same_rank", "reshape_same_rank.onnx")
# ---------------------------------------------------------------------------
# Add tests
# ---------------------------------------------------------------------------
@@ -757,6 +841,12 @@ if __name__ == "__main__":
conv_with_bias_3x3()
conv_batch_2()
conv_large_spatial()
conv_grouped_two_groups()
conv_depthwise_grouped()
print("\nGenerating MatMul tests:")
matmul_basic()
matmul_batched_3d()
print("\nGenerating Pooling tests:")
maxpool_basic()
@@ -802,6 +892,12 @@ if __name__ == "__main__":
gather_axis1()
gather_axis0_matrix_indices()
print("\nGenerating Concat tests:")
concat_channel_axis()
print("\nGenerating Reshape tests:")
reshape_same_rank()
print("\nGenerating Add tests:")
add_basic()
add_broadcast_row()