Skip to content

Commit

Permalink
Shuffle tuner parameters to find good parameters quicker.
Browse files Browse the repository at this point in the history
Parameters are searched in a linear fashion currently. By shuffling them,
we will find a good instance more quickly.

Also, shuffing could help reduce possible bias due to grouped, similar
parameters that affect the environment (e.g. cache, branch predictor, ...),
leading to more accurate/fair results.

Additionally, this is a preparation for exiting the tuner during the search,
which becomes a possible option.

Pull request leela-zero#2225.
  • Loading branch information
nerai authored and gcp committed Apr 2, 2019
1 parent 31b795b commit b1907a4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Tuner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,8 @@ std::vector<Parameters> Tuner<net_t>::build_valid_params() {
};
}

// Don't use thead Rng or determinism will depend
// on whether tuner ran.
auto rng = Random{0};

auto valid_params = std::vector<Parameters>{};
auto build_from = [this, &rng, &valid_params](std::vector<Configurations> & opts, int tce) {
auto build_from = [this, &valid_params](std::vector<Configurations> & opts, int tce) {
auto cfgs = 1;
for (auto c = size_t{0}; c < opts.size(); c++) {
cfgs *= opts[c].second.size();
Expand All @@ -382,18 +378,22 @@ std::vector<Parameters> Tuner<net_t>::build_valid_params() {
Parameters param = get_parameters_by_int(opts, i);
param["TCE"] = tce;
if (valid_config_sgemm(param, cfg_sgemm_exhaustive)) {
if (cfg_sgemm_exhaustive) {
if (rng.randfix<16>() != 0) {
continue;
}
}
valid_params.push_back(param);
}
}
};
build_from(opts, 0);
build_from(topts, 1);

// Don't use thread RNG or determinism will depend on whether tuner ran.
auto rng = Random{0};
std::shuffle(begin(valid_params), end(valid_params), rng);

if (cfg_sgemm_exhaustive) {
// Likely too many valid params, cut out some of them
valid_params.resize(valid_params.size() / 16);
}

return valid_params;
}

Expand Down

0 comments on commit b1907a4

Please sign in to comment.