From 6fb310ae298041e1b17a36c8a89641619e4aaa17 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 26 Aug 2019 15:21:20 +0800 Subject: [PATCH] Fix bug of getting bool Flags from os.environ (#19349) * fix bug of getting bool Flags from os.environ, test=develop * add empty loss_name in CompiledProgram for inplace grad test, test=develop --- paddle/fluid/pybind/pybind.cc | 6 ++++++ .../slim/tests/test_mkldnn_int8_quantization_strategy.py | 2 +- python/paddle/fluid/tests/unittests/op_test.py | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 5944c93a055..3a19effff23 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -86,6 +86,9 @@ DEFINE_bool(reader_queue_speed_test_mode, false, "If set true, the queue.pop will only get data from queue but not " "remove the data from queue for speed testing"); DECLARE_bool(use_mkldnn); +#ifdef PADDLE_WITH_NGRAPH +DECLARE_bool(use_ngraph); +#endif // disable auto conversion to list in Python PYBIND11_MAKE_OPAQUE(paddle::framework::LoDTensorArray); @@ -740,6 +743,9 @@ All parameter, weight, gradient are variables in Paddle. return framework::OpInfoMap::Instance().Get(op_type).HasInferInplace(); }); m.def("get_flags_use_mkldnn", []() { return FLAGS_use_mkldnn; }); +#ifdef PADDLE_WITH_NGRAPH + m.def("get_flags_use_ngraph", []() { return FLAGS_use_ngraph; }); +#endif m.def("prune", [](const ProgramDesc &origin, const std::vector> &targets) { diff --git a/python/paddle/fluid/contrib/slim/tests/test_mkldnn_int8_quantization_strategy.py b/python/paddle/fluid/contrib/slim/tests/test_mkldnn_int8_quantization_strategy.py index 36242efb8b3..d41ea349071 100644 --- a/python/paddle/fluid/contrib/slim/tests/test_mkldnn_int8_quantization_strategy.py +++ b/python/paddle/fluid/contrib/slim/tests/test_mkldnn_int8_quantization_strategy.py @@ -162,7 +162,7 @@ class TestMKLDNNPostTrainingQuantStrategy(unittest.TestCase): fetch_targets] = fluid.io.load_inference_model( model_path, exe, 'model', 'params') - use_mkldnn = bool(os.getenv("FLAGS_use_mkldnn", False)) + use_mkldnn = fluid.core.get_flags_use_mkldnn() if (use_mkldnn): graph = IrGraph( core.Graph(inference_program.desc), for_test=True) diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 2b45bc07b1d..da3d9cb1b91 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -680,7 +680,8 @@ class OpTest(unittest.TestCase): return [] places = [fluid.CPUPlace()] cpu_only = self._cpu_only if hasattr(self, '_cpu_only') else False - use_ngraph = bool(os.getenv("FLAGS_use_ngraph", False)) + use_ngraph = fluid.core.is_compiled_with_ngraph( + ) and fluid.core.get_flags_use_ngraph() if use_ngraph: cpu_only = True if core.is_compiled_with_cuda() and core.op_support_gpu(self.op_type)\ -- GitLab