Skip to content

Commit

Permalink
2.3 add IpuStrategy.SetCompilationProgressLogger (PaddlePaddle#652) (P…
Browse files Browse the repository at this point in the history
…addlePaddle#658)

* add IpuStrategy.SetCompilationProgressLogger

* change log level

* add UT
  • Loading branch information
gglin001 authored Apr 21, 2022
1 parent 5b36637 commit c22ee0e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions paddle/fluid/platform/device/ipu/ipu_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<void(int, int)>& logger) {
popart_options.compilationProgressLogger = logger;
}

std::string IpuStrategy::GetOption(const std::string& option) {
return get(option, options_getter);
}
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/platform/device/ipu/ipu_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class IpuStrategy {
const std::vector<int> &values);
void AddCustomOp(const std::string &paddle_op, const std::string &popart_op,
const std::string &domain, int version);
void SetCompilationProgressLogger(
const std::function<void(int, int)> &logger);

std::string GetOption(const std::string &);
std::vector<std::string> GetVectorOption(const std::string &);
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/pybind/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,10 @@ All parameter, weight, gradient are variables in Paddle.
for (auto element : opt) {
auto option_name = element.first.cast<std::string>();
VLOG(10) << "Set option: " << option_name;
if (py::isinstance<py::bool_>(element.second)) {
if (option_name == "compilation_progress_logger") {
self.SetCompilationProgressLogger(
element.second.cast<py::function>());
} else if (py::isinstance<py::bool_>(element.second)) {
self.AddBoolOption(option_name, element.second.cast<bool>());
} else if (py::isinstance<py::float_>(element.second)) {
self.AddDoubleOption(option_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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()

0 comments on commit c22ee0e

Please sign in to comment.