From 789d8686c7fc270e5579f2fad680e2aa1af4e3b4 Mon Sep 17 00:00:00 2001 From: nihui Date: Fri, 16 Aug 2024 18:48:39 +0800 Subject: [PATCH] pnnx functionize do not create shadow op for identity consumers (#5632) --- tools/pnnx/src/pass_level2.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/pnnx/src/pass_level2.cpp b/tools/pnnx/src/pass_level2.cpp index bc7e51b8d..de44a3553 100644 --- a/tools/pnnx/src/pass_level2.cpp +++ b/tools/pnnx/src/pass_level2.cpp @@ -1166,6 +1166,18 @@ static void functionize(Graph& graph) if (out0->consumers.size() == 1) continue; + bool all_consumers_are_same = true; + for (size_t j = 1; j < out0->consumers.size(); j++) + { + if (out0->consumers[j] != out0->consumers[0]) + { + all_consumers_are_same = false; + break; + } + } + if (all_consumers_are_same) + continue; + for (int j = (int)out0->consumers.size() - 1; j > 0; j--) { Operator* op1 = out0->consumers[j];