From: Duc Ngo Date: Wed, 13 Mar 2019 03:05:36 +0000 (-0700) Subject: Remove sinkMaxPool transformation (#17694) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~844 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66556f48e3f5c6f6d6f81ae61e37460bf4906c52;p=platform%2Fupstream%2Fpytorch.git Remove sinkMaxPool transformation (#17694) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/17694 Remove sinkMaxPool transformation as it's unused Differential Revision: D14328624 fbshipit-source-id: bd245403b756157120faa61a0f9253c15120e7a8 --- diff --git a/caffe2/opt/sink.cc b/caffe2/opt/sink.cc deleted file mode 100644 index ed4cd8a..0000000 --- a/caffe2/opt/sink.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "caffe2/core/logging.h" -#include "caffe2/opt/converter.h" -#include "caffe2/opt/mobile.h" -#include "caffe2/opt/passes.h" - -namespace caffe2 { -namespace opt { - -using namespace nom; - -C10_EXPORT void sinkMaxPool(nom::repr::NNModule* nn) { - for (auto max_pool_node : - repr::nn::nodeIterator(nn->dataFlow)) { - if (repr::nn::getInputs(max_pool_node).size() != 1) { - continue; - } - - auto max_pool_outputs = repr::nn::getOutputs(max_pool_node); - if (max_pool_outputs.size() != 1) { - continue; - } - - auto consumers = repr::nn::getConsumers(max_pool_outputs.front()); - if (consumers.size() != 1) { - continue; - } - - // TODO Sink MaxPool in more cases. - auto relu_node = consumers.front(); - if (!repr::nn::is(relu_node)) { - continue; - } - - if (repr::nn::getOutputs(relu_node).size() != 1) { - continue; - } - - // input -> MaxPool -> intermediate -> Relu -> output - nn->dataFlow.swapNodes(max_pool_node, relu_node); - // input -> Relu -> intermediate -> MaxPool -> output - } -} - -REGISTER_OPT_PASS_FROM_FUNC(SinkMaxPool, sinkMaxPool); - -} // namespace opt -} // namespace caffe2 diff --git a/caffe2/opt/sink.h b/caffe2/opt/sink.h deleted file mode 100644 index 54992f7..0000000 --- a/caffe2/opt/sink.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef CAFFE2_OPT_SINK_H_ -#define CAFFE2_OPT_SINK_H_ - -#include "caffe2/core/common.h" -#include "caffe2/proto/caffe2_pb.h" -#include "nomnigraph/Representations/NeuralNet.h" - -namespace caffe2 { -namespace opt { - -CAFFE2_API void sinkMaxPool(nom::repr::NNModule* nn); - -} // namespace opt -} // namespace caffe2 - -#endif // CAFFE2_OPT_SINK_H_ diff --git a/caffe2/python/pybind_state.cc b/caffe2/python/pybind_state.cc index 95ea452..1bc772a 100644 --- a/caffe2/python/pybind_state.cc +++ b/caffe2/python/pybind_state.cc @@ -25,7 +25,6 @@ #include "caffe2/opt/onnxifi_transformer.h" #include "caffe2/opt/optimize_ideep.h" #include "caffe2/opt/passes.h" -#include "caffe2/opt/sink.h" #include "caffe2/predictor/predictor.h" #include "caffe2/python/pybind_state_registry.h" #include "caffe2/utils/cpuid.h" @@ -1745,19 +1744,6 @@ void addGlobalMethods(py::module& m) { return py::bytes(out); }); - m.def("transform_sinkMaxPool", [](py::bytes def) { - caffe2::NetDef proto; - CAFFE_ENFORCE(ParseProtoFromLargeString(def.cast(), &proto)); - - auto nn = caffe2::convertToNNModule(proto); - opt::sinkMaxPool(&nn); - auto new_proto = caffe2::convertToCaffe2Proto(nn, proto); - - std::string out; - new_proto.SerializeToString(&out); - return py::bytes(out); - }); - auto initialize = [&]() { // Initialization of the module #ifdef USE_NUMPY diff --git a/caffe2/python/transformations.py b/caffe2/python/transformations.py index b48b73d..2f9fc7a 100644 --- a/caffe2/python/transformations.py +++ b/caffe2/python/transformations.py @@ -46,12 +46,6 @@ def fuseNNPACKConvRelu(net): ) -def sinkMaxPool(net): - net.Proto().ParseFromString( - C.transform_sinkMaxPool(net.Proto().SerializeToString()) - ) - - def optimizeForIDEEP(net, training_mode = False): net.Proto().ParseFromString( C.transform_optimizeForIDEEP(net.Proto().SerializeToString(), training_mode) diff --git a/caffe2/python/transformations_test.py b/caffe2/python/transformations_test.py index 567b31e..363ceb1 100644 --- a/caffe2/python/transformations_test.py +++ b/caffe2/python/transformations_test.py @@ -108,14 +108,6 @@ class TestTransformations(tu.TestCase): assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0] assert net.Proto().op[1].output[0] != net.Proto().op[1].input[0] - def test_transformer_SinkMaxPool(self): - net = self._base_test_net() - net.MaxPool(["Y"], ["Y1"], kernel=3) - net.Relu(["Y1"], ["Y1"]) - transformer.SinkMaxPool(net) - assert tu.str_compare(net.Proto().op[1].type, "Relu") - assert tu.str_compare(net.Proto().op[2].type, "MaxPool") - @given( size=st.integers(7, 10), input_channels=st.integers(1, 10),