From c22ee0e74a0f7398d310122532ec5c0bfbbb4c93 Mon Sep 17 00:00:00 2001 From: Allen Guo Date: Thu, 21 Apr 2022 14:02:42 +0800 Subject: [PATCH] 2.3 add IpuStrategy.SetCompilationProgressLogger (#652) (#658) * add IpuStrategy.SetCompilationProgressLogger * change log level * add UT --- paddle/fluid/platform/device/ipu/ipu_strategy.cc | 14 ++++++++++++++ paddle/fluid/platform/device/ipu/ipu_strategy.h | 2 ++ paddle/fluid/pybind/pybind.cc | 5 ++++- .../tests/unittests/ipu/test_ipu_strategy_ipu.py | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/platform/device/ipu/ipu_strategy.cc b/paddle/fluid/platform/device/ipu/ipu_strategy.cc index cc6ff99f2a86d..d828f809d281c 100644 --- a/paddle/fluid/platform/device/ipu/ipu_strategy.cc +++ b/paddle/fluid/platform/device/ipu/ipu_strategy.cc @@ -417,6 +417,15 @@ IpuStrategy::IpuStrategy() { RegisterGetter(map_options_getter, options_type, "gcl_options", "map", [&]() { return popart_options.gclOptions; }); + + // Default options + + // Can also be set as a custom logger in python, like using tqdm + popart_options.compilationProgressLogger = [](int progress, int total) { + if (progress % 10 == 0) { + VLOG(1) << "compile progress: " << progress << "%"; + } + }; } void IpuStrategy::AddBoolOption(const std::string& option, bool value) { @@ -533,6 +542,11 @@ void IpuStrategy::AddCustomOp(const std::string& paddle_op, IpuCustomOpIdentifier(paddle_op, popart_op, domain, version)); } +void IpuStrategy::SetCompilationProgressLogger( + const std::function& logger) { + popart_options.compilationProgressLogger = logger; +} + std::string IpuStrategy::GetOption(const std::string& option) { return get(option, options_getter); } diff --git a/paddle/fluid/platform/device/ipu/ipu_strategy.h b/paddle/fluid/platform/device/ipu/ipu_strategy.h index 458e00ebce93f..985204b786193 100644 --- a/paddle/fluid/platform/device/ipu/ipu_strategy.h +++ b/paddle/fluid/platform/device/ipu/ipu_strategy.h @@ -126,6 +126,8 @@ class IpuStrategy { const std::vector &values); void AddCustomOp(const std::string &paddle_op, const std::string &popart_op, const std::string &domain, int version); + void SetCompilationProgressLogger( + const std::function &logger); std::string GetOption(const std::string &); std::vector GetVectorOption(const std::string &); diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 5f1ac9a79a4b8..83cd5c2f54227 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -4338,7 +4338,10 @@ All parameter, weight, gradient are variables in Paddle. for (auto element : opt) { auto option_name = element.first.cast(); VLOG(10) << "Set option: " << option_name; - if (py::isinstance(element.second)) { + if (option_name == "compilation_progress_logger") { + self.SetCompilationProgressLogger( + element.second.cast()); + } else if (py::isinstance(element.second)) { self.AddBoolOption(option_name, element.second.cast()); } else if (py::isinstance(element.second)) { self.AddDoubleOption(option_name, diff --git a/python/paddle/fluid/tests/unittests/ipu/test_ipu_strategy_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_ipu_strategy_ipu.py index 5fbfb36624af9..21a6655406729 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_ipu_strategy_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_ipu_strategy_ipu.py @@ -74,6 +74,7 @@ def test_set_other_options(self): 'autoReport.directory': 'path', 'autoReport.all': 'true' } + options['random_seed'] = 1234 for k, v in options.items(): ipu_strategy.set_options({k: v}) if (isinstance(v, list)): @@ -83,6 +84,10 @@ def test_set_other_options(self): assert v == ipu_strategy.get_option( k), f"set {k} to {v} failed " + # The custom logger need 2 int as inputs + logger = lambda progress, total: print(f"compile progrss: {progress}/{total}") + ipu_strategy.set_options({'compilation_progress_logger': logger}) + if __name__ == "__main__": unittest.main()