Back out "Enable test_api IMethodTest in OSS" (#62893)
authorWill Constable <whc@fb.com>
Fri, 6 Aug 2021 23:42:27 +0000 (16:42 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Fri, 6 Aug 2021 23:43:50 +0000 (16:43 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/62893

Original commit changeset: 50eb3689cf84

Test Plan: Confirm pytorch_linux_xenial_cuda11_1_cudnn8_py3_gcc7_test2 passes in OSS

Reviewed By: seemethere, alanwaketan

Differential Revision: D30159999

fbshipit-source-id: 74ff8975328409a3dc8222d3e2707a1bb0ab930c

test/cpp/api/CMakeLists.txt
test/cpp/api/imethod.cpp
torch/csrc/api/include/torch/imethod.h

index fc21afa..9bd9d67 100644 (file)
@@ -41,10 +41,6 @@ set(TORCH_API_TEST_SOURCES
   ${TORCH_API_TEST_DIR}/grad_mode.cpp
 )
 
-if(USE_DEPLOY)
-  list(APPEND TORCH_API_TEST_SOURCES ${TORCH_API_TEST_DIR}/imethod.cpp)
-endif()
-
 if(USE_CUDA)
   list(APPEND TORCH_API_TEST_SOURCES ${TORCH_API_TEST_DIR}/parallel.cpp)
 endif()
@@ -63,10 +59,6 @@ if(USE_CUDA)
   target_compile_definitions(test_api PRIVATE "USE_CUDA")
 endif()
 
-if(USE_DEPLOY)
-  target_link_libraries(test_api PRIVATE torch_deploy)
-endif()
-
 # Workaround for https://github.com/pytorch/pytorch/issues/40941
 if(USE_OPENMP AND CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0.0))
   # Compiling transformer.cpp or pow_test.cpp with -O2+ and both -fuse-openmp and -faligned-newout any optimization
index 83c5a96..3349d1b 100644 (file)
@@ -8,38 +8,30 @@
 using namespace ::testing;
 using namespace caffe2;
 
-const char* simple = "torch/csrc/deploy/example/generated/simple";
-const char* simpleJit = "torch/csrc/deploy/example/generated/simple_jit";
-
-// TODO(jwtan): Try unifying cmake and buck for getting the path.
-const char* path(const char* envname, const char* path) {
-  const char* env = getenv(envname);
-  return env ? env : path;
-}
-
+// TODO(T96218435): Enable the following tests in OSS.
 TEST(IMethodTest, CallMethod) {
-  auto scriptModel = torch::jit::load(path("SIMPLE_JIT", simpleJit));
-  auto scriptMethod = scriptModel.get_method("forward");
+  auto script_model = torch::jit::load(getenv("SIMPLE_JIT"));
+  auto script_method = script_model.get_method("forward");
 
   torch::deploy::InterpreterManager manager(3);
-  torch::deploy::Package package = manager.load_package(path("SIMPLE", simple));
-  auto pyModel = package.load_pickle("model", "model.pkl");
-  torch::deploy::PythonMethodWrapper pyMethod(pyModel, "forward");
+  torch::deploy::Package p = manager.load_package(getenv("SIMPLE"));
+  auto py_model = p.load_pickle("model", "model.pkl");
+  torch::deploy::PythonMethodWrapper py_method(py_model, "forward");
 
   auto input = torch::ones({10, 20});
-  auto outputPy = pyMethod({input});
-  auto outputScript = scriptMethod({input});
-  EXPECT_TRUE(outputPy.isTensor());
-  EXPECT_TRUE(outputScript.isTensor());
-  auto outputPyTensor = outputPy.toTensor();
-  auto outputScriptTensor = outputScript.toTensor();
-
-  EXPECT_TRUE(outputPyTensor.equal(outputScriptTensor));
-  EXPECT_EQ(outputPyTensor.numel(), 200);
+  auto output_py = py_method({input});
+  auto output_script = script_method({input});
+  EXPECT_TRUE(output_py.isTensor());
+  EXPECT_TRUE(output_script.isTensor());
+  auto output_py_tensor = output_py.toTensor();
+  auto output_script_tensor = output_script.toTensor();
+
+  EXPECT_TRUE(output_py_tensor.equal(output_script_tensor));
+  EXPECT_EQ(output_py_tensor.numel(), 200);
 }
 
 TEST(IMethodTest, GetArgumentNames) {
-  auto scriptModel = torch::jit::load(path("SIMPLE_JIT", simpleJit));
+  auto scriptModel = torch::jit::load(getenv("SIMPLE_JIT"));
   auto scriptMethod = scriptModel.get_method("forward");
 
   auto& scriptNames = scriptMethod.getArgumentNames();
@@ -47,7 +39,7 @@ TEST(IMethodTest, GetArgumentNames) {
   EXPECT_STREQ(scriptNames[0].c_str(), "input");
 
   torch::deploy::InterpreterManager manager(3);
-  torch::deploy::Package package = manager.load_package(path("SIMPLE", simple));
+  torch::deploy::Package package = manager.load_package(getenv("SIMPLE"));
   auto pyModel = package.load_pickle("model", "model.pkl");
   torch::deploy::PythonMethodWrapper pyMethod(pyModel, "forward");
 
index 78d7a9e..c26812f 100644 (file)
@@ -4,7 +4,7 @@
 
 namespace torch {
 
-class TORCH_API IMethod {
+class IMethod {
   /*
   IMethod provides a portable interface for torch methods, whether
   they are backed by torchscript or python/deploy.