Remove sinkMaxPool transformation (#17694)
authorDuc Ngo <duc@fb.com>
Wed, 13 Mar 2019 03:05:36 +0000 (20:05 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 13 Mar 2019 03:10:46 +0000 (20:10 -0700)
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

caffe2/opt/sink.cc [deleted file]
caffe2/opt/sink.h [deleted file]
caffe2/python/pybind_state.cc
caffe2/python/transformations.py
caffe2/python/transformations_test.py

diff --git a/caffe2/opt/sink.cc b/caffe2/opt/sink.cc
deleted file mode 100644 (file)
index ed4cd8a..0000000
+++ /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<repr::MaxPool>(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<repr::Relu>(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 (file)
index 54992f7..0000000
+++ /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_
index 95ea452..1bc772a 100644 (file)
@@ -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<std::string>(), &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
index b48b73d..2f9fc7a 100644 (file)
@@ -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)
index 567b31e..363ceb1 100644 (file)
@@ -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),