temp commit: i will soft-reset and recommit after next changes
This commit is contained in:
@@ -242,6 +242,50 @@ def conv_yolo11n_stem():
|
||||
save_model(model, "conv/yolo11n_stem", "conv_yolo11n_stem.onnx")
|
||||
|
||||
|
||||
def conv_yolo11n_heavy():
|
||||
"""Two largest YOLO11n standard Conv-SiLU blocks by MAC count."""
|
||||
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [1, 64, 80, 80])
|
||||
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [1, 64, 80, 80])
|
||||
rng = np.random.default_rng(111)
|
||||
W0 = numpy_helper.from_array(rng.uniform(-1, 1, (64, 64, 3, 3)).astype(np.float32), name="W0")
|
||||
B0 = numpy_helper.from_array(rng.uniform(-1, 1, (64,)).astype(np.float32), name="B0")
|
||||
W1 = numpy_helper.from_array(rng.uniform(-1, 1, (64, 64, 3, 3)).astype(np.float32), name="W1")
|
||||
B1 = numpy_helper.from_array(rng.uniform(-1, 1, (64,)).astype(np.float32), name="B1")
|
||||
nodes = [
|
||||
helper.make_node("Conv", ["X", "W0", "B0"], ["C0"],
|
||||
kernel_shape=[3, 3], strides=[1, 1], pads=[1, 1, 1, 1]),
|
||||
helper.make_node("Sigmoid", ["C0"], ["S0"]),
|
||||
helper.make_node("Mul", ["C0", "S0"], ["A0"]),
|
||||
helper.make_node("Conv", ["A0", "W1", "B1"], ["C1"],
|
||||
kernel_shape=[3, 3], strides=[1, 1], pads=[1, 1, 1, 1]),
|
||||
helper.make_node("Sigmoid", ["C1"], ["S1"]),
|
||||
helper.make_node("Mul", ["C1", "S1"], ["Y"]),
|
||||
]
|
||||
graph = helper.make_graph(nodes, "conv_yolo11n_heavy", [X], [Y], initializer=[W0, B0, W1, B1])
|
||||
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
|
||||
save_model(model, "conv/yolo11n_heavy", "conv_yolo11n_heavy.onnx")
|
||||
|
||||
|
||||
def conv_yolo11n_depthwise_head():
|
||||
"""YOLO11n pointwise-to-depthwise head boundary at its largest feature map."""
|
||||
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [1, 64, 80, 80])
|
||||
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [1, 64, 80, 80])
|
||||
rng = np.random.default_rng(110)
|
||||
W0 = numpy_helper.from_array(rng.uniform(-1, 1, (64, 64, 1, 1)).astype(np.float32), name="W0")
|
||||
B0 = numpy_helper.from_array(rng.uniform(-1, 1, (64,)).astype(np.float32), name="B0")
|
||||
W1 = numpy_helper.from_array(rng.uniform(-1, 1, (64, 1, 3, 3)).astype(np.float32), name="W1")
|
||||
B1 = numpy_helper.from_array(rng.uniform(-1, 1, (64,)).astype(np.float32), name="B1")
|
||||
nodes = [
|
||||
helper.make_node("Conv", ["X", "W0", "B0"], ["P"],
|
||||
kernel_shape=[1, 1], strides=[1, 1], pads=[0, 0, 0, 0]),
|
||||
helper.make_node("Conv", ["P", "W1", "B1"], ["Y"],
|
||||
kernel_shape=[3, 3], strides=[1, 1], pads=[1, 1, 1, 1], group=64),
|
||||
]
|
||||
graph = helper.make_graph(nodes, "conv_yolo11n_depthwise_head", [X], [Y], initializer=[W0, B0, W1, B1])
|
||||
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
|
||||
save_model(model, "conv/yolo11n_depthwise_head", "conv_yolo11n_depthwise_head.onnx")
|
||||
|
||||
|
||||
def conv_pointwise_tiled_chain():
|
||||
"""Chained pointwise Convs with a tiled intermediate."""
|
||||
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [1, 1024, 1, 1])
|
||||
@@ -760,6 +804,22 @@ def matmul_batched_3d_dynamic():
|
||||
save_model(model, "matmul/batched_3d_dynamic", "matmul_batched_3d_dynamic.onnx")
|
||||
|
||||
|
||||
def matmul_yolo_attention():
|
||||
"""YOLO11n attention chain with rank-4 dynamic matrices."""
|
||||
Q = helper.make_tensor_value_info("Q", TensorProto.FLOAT, [1, 2, 400, 32])
|
||||
K = helper.make_tensor_value_info("K", TensorProto.FLOAT, [1, 2, 32, 400])
|
||||
V = helper.make_tensor_value_info("V", TensorProto.FLOAT, [1, 2, 64, 400])
|
||||
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [1, 2, 64, 400])
|
||||
scale = numpy_helper.from_array(np.asarray([0.1767767], dtype=np.float32), name="scale")
|
||||
nodes = [helper.make_node("MatMul", ["Q", "K"], ["scores"]),
|
||||
helper.make_node("Mul", ["scores", "scale"], ["scaled"]),
|
||||
helper.make_node("Transpose", ["scaled"], ["weights"], perm=[0, 1, 3, 2]),
|
||||
helper.make_node("MatMul", ["V", "weights"], ["Y"])]
|
||||
graph = helper.make_graph(nodes, "matmul_yolo_attention", [Q, K, V], [Y], initializer=[scale])
|
||||
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
|
||||
save_model(model, "matmul/yolo_attention", "matmul_yolo_attention.onnx")
|
||||
|
||||
|
||||
def matmul_batched_left_constant():
|
||||
"""Batched 3D MatMul with constant LHS and runtime RHS."""
|
||||
rng = np.random.default_rng(70)
|
||||
@@ -2057,6 +2117,8 @@ if __name__ == "__main__":
|
||||
conv_huge_pointwise_1024()
|
||||
conv_huge_pointwise_1024_dynamic()
|
||||
conv_yolo11n_stem()
|
||||
conv_yolo11n_heavy()
|
||||
conv_yolo11n_depthwise_head()
|
||||
conv_pointwise_tiled_chain()
|
||||
conv_large_output_channels_1x1()
|
||||
conv_large_input_channels_1x1()
|
||||
@@ -2078,6 +2140,7 @@ if __name__ == "__main__":
|
||||
matmul_dynamic()
|
||||
matmul_batched_3d()
|
||||
matmul_batched_3d_dynamic()
|
||||
matmul_yolo_attention()
|
||||
matmul_batched_left_constant()
|
||||
matmul_batched_rhs_broadcast()
|
||||
matmul_batched_lhs_broadcast()
|
||||
|
||||
Reference in New Issue
Block a user