Relax check on outputs (#15458)
authorBram Wasti <bwasti@fb.com>
Fri, 21 Dec 2018 22:11:26 +0000 (14:11 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 21 Dec 2018 22:19:37 +0000 (14:19 -0800)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15458

many nets in the wild seem to have outputs that are never produced by the net.

Reviewed By: ZolotukhinM

Differential Revision: D13534185

fbshipit-source-id: 2b23b39c28404c53f68868f3bf6df53c5fea9eab

caffe2/opt/converter.cc
caffe2/python/transformations_test.py

index 4d701ed..2f9c8fb 100644 (file)
@@ -384,10 +384,13 @@ repr::NNModule convertToNNModule(
 
   for (const auto& outputName : net.external_output()) {
     CAFFE_ENFORCE(
-        blobMap.count(outputName),
-        "NetDef has ill-formed external_output: \"",
-        outputName,
-        "\"");
+        !strict || blobMap.count(outputName),
+        "NetDef has ill-formed external_output:",
+        outputName);
+    if (!blobMap.count(outputName)) {
+      LOG(ERROR) << "NetDef has ill-formed external_output: " << outputName;
+      continue;
+    }
     module.outputs.insert(blobMap[outputName]);
   }
 
index 502c844..567b31e 100644 (file)
@@ -328,16 +328,15 @@ class TestTransformations(tu.TestCase):
             atol=1e-04
         )
 
-    def test_converterEnforceUnusedInputs(self):
+    def test_converterDontEnforceUnusedInputs(self):
         net = core.Net("net")
         net.Relu(["X"], ["Y"])
         net.Proto().external_input.extend(["fake"])
         # This should now work
         transformer.AddNNPACK(net)  # just testing the converter
 
-    def test_converterEnforceUnusedOutputs(self):
+    def test_converterDontEnforceUnusedOutputs(self):
         net = core.Net("net")
         net.Relu(["X"], ["Y"])
         net.Proto().external_output.extend(["fake"])
-        with self.assertRaises(Exception):
-            transformer.AddNNPACK(net)  # just testing the converter
+        transformer.AddNNPACK(net)  # just testing the converter