Revert D13740752: [c10] plug caffe2 into jit
authorZachary DeVito <zdevito@fb.com>
Fri, 25 Jan 2019 20:20:29 +0000 (12:20 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 25 Jan 2019 20:29:19 +0000 (12:29 -0800)
Differential Revision:
D13740752

Original commit changeset: 2d9383574d42

fbshipit-source-id: e9ff217a438720423340a10af7fa263b33f2ae24

caffe2/core/operator.cc
caffe2/core/operator.h
torch/csrc/jit/custom_operator.cpp [deleted file]
torch/csrc/jit/custom_operator.h
torch/csrc/jit/interpreter.cpp

index 7b7e3dd..9df184c 100644 (file)
@@ -332,7 +332,7 @@ void RunOperator(
   CAFFE_ENFORCE(
       fn_wrap,
       "Operator not registered with FunctionSchema constructor.",
-      name.toUnqualString());
+      name);
   auto fn = fn_wrap->getSchema();
   auto op = caffe2::FunctionSchemaOperatorRegistry()->Create(
       name.toUnqualString(), fn, inputs, outputs);
index 5641902..54cae81 100644 (file)
@@ -1098,7 +1098,7 @@ C10_DECLARE_REGISTRY(FunctionSchemaRegistry, FunctionSchemaStorageBase);
   C10_REGISTER_CLASS(FunctionSchemaOperatorRegistry, name, impl)              \
   struct FunctionSchemaStorageBase##name : public FunctionSchemaStorageBase { \
     c10::FunctionSchema getSchema() override {                                \
-      return c10::FunctionSchema("caffe2::" #name, inputs, outputs);          \
+      return c10::FunctionSchema(#name, inputs, outputs);                     \
     }                                                                         \
   };                                                                          \
   C10_REGISTER_CLASS(                                                         \
diff --git a/torch/csrc/jit/custom_operator.cpp b/torch/csrc/jit/custom_operator.cpp
deleted file mode 100644 (file)
index 05c0ef6..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <jit/custom_operator.h>
-
-namespace torch {
-namespace jit {
-
-Operator createOperatorFromC2(
-    const std::string& name
-    ) {
-  auto symbolic_name = c10::Symbol::fromQualString("caffe2::" + name);
-  auto fn_wrap = caffe2::FunctionSchemaRegistry()->Create(symbolic_name.toUnqualString());
-  CAFFE_ENFORCE(
-      fn_wrap,
-      "Operator not registered with FunctionSchema constructor.",
-      name);
-  auto fn = fn_wrap->getSchema();
-
-  return Operator(fn, [symbolic_name, fn](Stack& stack) {
-      const auto input_size = fn.arguments().size();
-      const auto output_size = fn.returns().size();
-      std::vector<c10::IValue> inputs;
-      for (auto i = 0; i < input_size; ++i) {
-        auto input = pop(stack);
-        // Tensors come in as variables but need to be unwrapped
-        if (input.isTensor()) {
-          input = torch::autograd::Variable(input.toTensor()).data();
-        }
-        inputs.emplace(inputs.begin(), std::move(input));
-      }
-
-      // We use a temporary stack for arguments passed into RunOperator
-      std::list<c10::IValue> outputs_real;
-      std::vector<c10::IValue*> outputs;
-      for (auto i = 0; i < output_size; ++i) {
-        if (TensorType::get() == fn.returns()[i].type()) {
-          caffe2::Tensor tensor(caffe2::CPU);
-          auto at_tensor = at::Tensor(c10::C10Tensor(std::move(tensor)));
-          outputs_real.emplace_back(c10::IValue(at_tensor));
-        } else {
-          outputs_real.emplace_back(c10::IValue());
-        }
-        outputs.emplace_back(&outputs_real.back());
-      }
-
-      caffe2::RunOperator(symbolic_name, inputs, outputs);
-
-      // We need to convert tensors back into variables
-      for (auto& t : outputs_real) {
-        if (t.isTensor()) {
-            push(stack, c10::IValue(torch::autograd::make_variable(t.toTensor())));
-        } else {
-            push(stack, std::move(t));
-        }
-      }
-
-      return 0;
-  });
-}
-
-}} // torch::jit
index 265bf7a..4d82bed 100644 (file)
@@ -6,8 +6,6 @@
 #include <torch/csrc/utils/variadic.h>
 
 #include <ATen/core/function_schema.h>
-#include <caffe2/core/operator.h>
-
 #include <c10/util/Metaprogramming.h>
 #include <c10/util/TypeList.h>
 
@@ -260,8 +258,6 @@ Operator createOperator(
   });
 }
 
-Operator createOperatorFromC2(const std::string& name);
-
 /// Registration class for new operators. Effectively calls
 /// `torch::jit::registerOperator` for every supplied operator, but allows doing
 /// so in the global scope when a `RegisterOperators` object is assigned to a
@@ -283,14 +279,6 @@ struct TORCH_API RegisterOperators {
     op(name, std::forward<Implementation>(implementation));
   }
 
-  /// Requires declaration of the FunctionSchema with
-  /// REGISTER_FUNCTION_SCHEMA_OPERATOR(name, ...)
-  static RegisterOperators&& Caffe2Operator(const std::string& name) {
-    auto r = RegisterOperators();
-    registerOperator(createOperatorFromC2(name));
-    return std::move(r);
-  }
-
   /// Creates a new operator from a name and implementation function (function
   /// pointer or function object/lambda) using `torch::jit::createOperator`, and
   /// then registers the operator.
index 36aca85..6d1fa9c 100644 (file)
@@ -15,8 +15,6 @@
 #include <torch/csrc/jit/script/jit_exception.h>
 #include <ATen/core/thread_pool.h>
 
-#include <caffe2/core/operator.h>
-
 #include <exception>
 #include <iostream>
 #include <memory>