| @@ -208,6 +208,7 @@ set(pnnx_pass_level4_SRCS | |||
| ) | |||
| set(pnnx_pass_level5_SRCS | |||
| pass_level5/eliminate_dropout.cpp | |||
| pass_level5/eliminate_maxpool_indices.cpp | |||
| pass_level5/eliminate_slice.cpp | |||
| pass_level5/eliminate_view_reshape.cpp | |||
| @@ -251,7 +252,7 @@ set(pnnx_pass_ncnn_SRCS | |||
| pass_ncnn/F_adaptive_max_pool1d.cpp | |||
| pass_ncnn/F_adaptive_max_pool2d.cpp | |||
| pass_ncnn/F_adaptive_max_pool3d.cpp | |||
| pass_ncnn/F_alpha_dropout.cpp | |||
| #pass_ncnn/F_alpha_dropout.cpp | |||
| pass_ncnn/F_avg_pool1d.cpp | |||
| pass_ncnn/F_avg_pool2d.cpp | |||
| pass_ncnn/F_avg_pool3d.cpp | |||
| @@ -260,12 +261,12 @@ set(pnnx_pass_ncnn_SRCS | |||
| pass_ncnn/F_conv1d.cpp | |||
| pass_ncnn/F_conv2d.cpp | |||
| pass_ncnn/F_conv3d.cpp | |||
| pass_ncnn/F_dropout.cpp | |||
| pass_ncnn/F_dropout2d.cpp | |||
| pass_ncnn/F_dropout3d.cpp | |||
| #pass_ncnn/F_dropout.cpp | |||
| #pass_ncnn/F_dropout2d.cpp | |||
| #pass_ncnn/F_dropout3d.cpp | |||
| pass_ncnn/F_elu.cpp | |||
| pass_ncnn/F_embedding.cpp | |||
| pass_ncnn/F_feature_alpha_dropout.cpp | |||
| #pass_ncnn/F_feature_alpha_dropout.cpp | |||
| pass_ncnn/F_gelu.cpp | |||
| pass_ncnn/F_group_norm.cpp | |||
| pass_ncnn/F_hardsigmoid.cpp | |||
| @@ -302,7 +303,7 @@ set(pnnx_pass_ncnn_SRCS | |||
| pass_ncnn/nn_AdaptiveMaxPool1d.cpp | |||
| pass_ncnn/nn_AdaptiveMaxPool2d.cpp | |||
| pass_ncnn/nn_AdaptiveMaxPool3d.cpp | |||
| pass_ncnn/nn_AlphaDropout.cpp | |||
| #pass_ncnn/nn_AlphaDropout.cpp | |||
| pass_ncnn/nn_AvgPool1d.cpp | |||
| pass_ncnn/nn_AvgPool2d.cpp | |||
| pass_ncnn/nn_AvgPool3d.cpp | |||
| @@ -317,9 +318,9 @@ set(pnnx_pass_ncnn_SRCS | |||
| pass_ncnn/nn_Conv2d.cpp | |||
| pass_ncnn/nn_Conv3d.cpp | |||
| pass_ncnn/nn_ConvTranspose2d.cpp | |||
| pass_ncnn/nn_Dropout.cpp | |||
| pass_ncnn/nn_Dropout2d.cpp | |||
| pass_ncnn/nn_Dropout3d.cpp | |||
| #pass_ncnn/nn_Dropout.cpp | |||
| #pass_ncnn/nn_Dropout2d.cpp | |||
| #pass_ncnn/nn_Dropout3d.cpp | |||
| pass_ncnn/nn_ELU.cpp | |||
| pass_ncnn/nn_Embedding.cpp | |||
| pass_ncnn/nn_GELU.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| #include "pass_level5.h" | |||
| #include "pass_level5/eliminate_dropout.h" | |||
| #include "pass_level5/eliminate_slice.h" | |||
| #include "pass_level5/eliminate_view_reshape.h" | |||
| #include "pass_level5/eval_expression.h" | |||
| @@ -49,6 +50,8 @@ void pass_level5(Graph& g) | |||
| eliminate_view_reshape(g); | |||
| eliminate_dropout(g); | |||
| fuse_channel_shuffle(g); | |||
| dead_code_elimination(g); | |||
| @@ -0,0 +1,76 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "eliminate_dropout.h" | |||
| #include <algorithm> | |||
| #include "pass_level2.h" | |||
| namespace pnnx { | |||
| void eliminate_dropout(Graph& graph) | |||
| { | |||
| while (1) | |||
| { | |||
| bool matched = false; | |||
| for (size_t i = 0; i < graph.ops.size(); i++) | |||
| { | |||
| Operator* op = graph.ops[i]; | |||
| if (op->type != "F.alpha_dropout" && op->type != "F.dropout" && op->type != "F.dropout2d" && op->type != "F.dropout3d" && op->type != "F.feature_alpha_dropout" && op->type != "nn.AlphaDropout" && op->type != "nn.Dropout" && op->type != "nn.Dropout2d" && op->type != "nn.Dropout3d") | |||
| continue; | |||
| // delete noop-like dropout | |||
| matched = true; | |||
| for (auto& x : op->inputs) | |||
| { | |||
| x->remove_consumer(op); | |||
| } | |||
| Operand* slice_out = op->outputs[0]; | |||
| for (auto& x : slice_out->consumers) | |||
| { | |||
| for (size_t j = 0; j < x->inputs.size(); j++) | |||
| { | |||
| if (x->inputs[j] == slice_out) | |||
| x->inputs[j] = op->inputs[0]; | |||
| } | |||
| op->inputs[0]->consumers.push_back(x); | |||
| } | |||
| slice_out->producer = 0; | |||
| slice_out->consumers.clear(); | |||
| graph.operands.erase(std::find(graph.operands.begin(), graph.operands.end(), slice_out)); | |||
| delete slice_out; | |||
| op->inputs.clear(); | |||
| op->outputs.clear(); | |||
| graph.ops.erase(graph.ops.begin() + i); | |||
| delete op; | |||
| break; | |||
| } | |||
| if (!matched) | |||
| break; | |||
| } | |||
| } | |||
| } // namespace pnnx | |||
| @@ -12,38 +12,10 @@ | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| #include "ir.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class nn_Dropout : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| nn.Dropout op_0 1 1 input out | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(nn_Dropout, 20) | |||
| } // namespace ncnn | |||
| void eliminate_dropout(Graph& graph); | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class F_alpha_dropout : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| F.alpha_dropout op_0 1 1 input out p=* training=* | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "alpha_dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_alpha_dropout, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class F_dropout : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| F.dropout op_0 1 1 input out p=* training=* | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_dropout, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class F_dropout2d : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| F.dropout2d op_0 1 1 input out p=* training=* | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout2d"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_dropout2d, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class F_dropout3d : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| F.dropout3d op_0 1 1 input out p=* training=* | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout3d"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_dropout3d, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class F_feature_alpha_dropout : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| F.feature_alpha_dropout op_0 1 1 input out p=* training=* | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "feature_alpha_dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_feature_alpha_dropout, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class nn_AlphaDropout : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| nn.AlphaDropout op_0 1 1 input out | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(nn_AlphaDropout, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class nn_Dropout2d : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| nn.Dropout2d op_0 1 1 input out | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(nn_Dropout2d, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||
| @@ -1,49 +0,0 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #include "pass_ncnn.h" | |||
| namespace pnnx { | |||
| namespace ncnn { | |||
| class nn_Dropout3d : public GraphRewriterPass | |||
| { | |||
| public: | |||
| const char* match_pattern_graph() const | |||
| { | |||
| return R"PNNXIR(7767517 | |||
| 3 2 | |||
| pnnx.Input input 0 1 input | |||
| nn.Dropout3d op_0 1 1 input out | |||
| pnnx.Output output 1 0 out | |||
| )PNNXIR"; | |||
| } | |||
| const char* type_str() const | |||
| { | |||
| return "Noop"; | |||
| } | |||
| const char* name_str() const | |||
| { | |||
| return "dropout"; | |||
| } | |||
| }; | |||
| REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(nn_Dropout3d, 20) | |||
| } // namespace ncnn | |||
| } // namespace pnnx | |||