From 235d47760b2dc9e899f488a7d87348adfd9742c6 Mon Sep 17 00:00:00 2001 From: Bram Wasti Date: Fri, 21 Dec 2018 14:11:26 -0800 Subject: [PATCH] Relax check on outputs (#15458) 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 | 11 +++++++---- caffe2/python/transformations_test.py | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/caffe2/opt/converter.cc b/caffe2/opt/converter.cc index 4d701ed..2f9c8fb 100644 --- a/caffe2/opt/converter.cc +++ b/caffe2/opt/converter.cc @@ -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]); } diff --git a/caffe2/python/transformations_test.py b/caffe2/python/transformations_test.py index 502c844..567b31e 100644 --- a/caffe2/python/transformations_test.py +++ b/caffe2/python/transformations_test.py @@ -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 -- 2.7.4