Skip to content

Commit

Permalink
Implement scalable smart pruning, with CLOP-tuned default (#123)
Browse files Browse the repository at this point in the history
Implement EARLY-C strategy from https://pdfs.semanticscholar.org/a2e6/299fd3c8ab17e3a1a783d518688b55bb2363.pdf. I came up with this independently and tried it in lczero as well https://github.com/glinscott/leela-chess/pull/556/files and found it helped CPU but not GPU for some reason...

Average of mean and max from CLOP tune 7-28
  • Loading branch information
jjoshua2 authored and dubslow committed Jul 29, 2018
1 parent 598462f commit b1301aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void EngineController::PopulateOptions(OptionsParser* options) {
options->Add<ChoiceOption>(kNnBackendStr, backends, "backend") =
backends.empty() ? "<none>" : backends[0];
options->Add<StringOption>(kNnBackendOptionsStr, "backend-opts");
options->Add<FloatOption>(kSlowMoverStr, 0.0f, 100.0f, "slowmover") = 1.95f;
options->Add<FloatOption>(kSlowMoverStr, 0.0f, 100.0f, "slowmover") = 2.66f;
options->Add<IntOption>(kMoveOverheadStr, 0, 10000, "move-overhead") = 100;
options->Add<FloatOption>(kTimeCurvePeak, -1000.0f, 1000.0f,
"time-curve-peak") = 26.2f;
Expand Down
12 changes: 7 additions & 5 deletions src/mcts/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const char* Search::kTemperatureStr = "Initial temperature";
const char* Search::kTempDecayMovesStr = "Moves with temperature decay";
const char* Search::kNoiseStr = "Add Dirichlet noise at root node";
const char* Search::kVerboseStatsStr = "Display verbose move stats";
const char* Search::kSmartPruningStr = "Enable smart pruning";
const char* Search::kAggressiveTimePruningStr = "Aggressive smart pruning threshold";
const char* Search::kFpuReductionStr = "First Play Urgency Reduction";
const char* Search::kCacheHistoryLengthStr =
"Length of history to include in cache";
Expand Down Expand Up @@ -78,7 +78,8 @@ void Search::PopulateUciParams(OptionsParser* options) {
options->Add<IntOption>(kTempDecayMovesStr, 0, 100, "tempdecay-moves") = 0;
options->Add<BoolOption>(kNoiseStr, "noise", 'n') = false;
options->Add<BoolOption>(kVerboseStatsStr, "verbose-move-stats") = false;
options->Add<BoolOption>(kSmartPruningStr, "smart-pruning") = true;
options->Add<FloatOption>(kAggressiveTimePruningStr, 0.0f, 10.0f,
"smart-pruning-aggresiveness") = 0.68f;
options->Add<FloatOption>(kFpuReductionStr, -100.0f, 100.0f,
"fpu-reduction") = 0.0f;
options->Add<IntOption>(kCacheHistoryLengthStr, 0, 7,
Expand Down Expand Up @@ -110,7 +111,7 @@ Search::Search(const NodeTree& tree, Network* network,
kTempDecayMoves(options.Get<int>(kTempDecayMovesStr)),
kNoise(options.Get<bool>(kNoiseStr)),
kVerboseStats(options.Get<bool>(kVerboseStatsStr)),
kSmartPruning(options.Get<bool>(kSmartPruningStr)),
kAggressiveTimePruning(options.Get<float>(kAggressiveTimePruningStr)),
kFpuReduction(options.Get<float>(kFpuReductionStr)),
kCacheHistoryLength(options.Get<int>(kCacheHistoryLengthStr)),
kPolicySoftmaxTemp(options.Get<float>(kPolicySoftmaxTempStr)),
Expand Down Expand Up @@ -296,7 +297,7 @@ void Search::MaybeTriggerStop() {
}

void Search::UpdateRemainingMoves() {
if (!kSmartPruning) return;
if (kAggressiveTimePruning <= 0.0f) return;
SharedMutex::Lock lock(nodes_mutex_);
remaining_playouts_ = std::numeric_limits<int>::max();
// Check for how many playouts there is time remaining.
Expand All @@ -307,7 +308,8 @@ void Search::UpdateRemainingMoves() {
(time_since_start - kSmartPruningToleranceMs) +
1;
int64_t remaining_time = limits_.time_ms - time_since_start;
int64_t remaining_playouts = remaining_time * nps / 1000;
// Put early_exit scaler here so calculation doesn't have to be done on every node.
int64_t remaining_playouts = kAggressiveTimePruning * remaining_time * nps / 1000;
// Don't assign directly to remaining_playouts_ as overflow is possible.
if (remaining_playouts < remaining_playouts_)
remaining_playouts_ = remaining_playouts;
Expand Down
4 changes: 2 additions & 2 deletions src/mcts/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Search {
static const char* kTempDecayMovesStr;
static const char* kNoiseStr;
static const char* kVerboseStatsStr;
static const char* kSmartPruningStr;
static const char* kAggressiveTimePruningStr;
static const char* kFpuReductionStr;
static const char* kCacheHistoryLengthStr;
static const char* kPolicySoftmaxTempStr;
Expand Down Expand Up @@ -170,7 +170,7 @@ class Search {
const int kTempDecayMoves;
const bool kNoise;
const bool kVerboseStats;
const bool kSmartPruning;
const float kAggressiveTimePruning;
const float kFpuReduction;
const bool kCacheHistoryLength;
const float kPolicySoftmaxTemp;
Expand Down
6 changes: 3 additions & 3 deletions src/selfplay/tournament.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ void SelfPlayTournament::PopulateOptions(OptionsParser* options) {
SelfPlayGame::PopulateUciParams(options);
auto defaults = options->GetMutableDefaultsOptions();
defaults->Set<int>(Search::kMiniBatchSizeStr, 32); // Minibatch size
defaults->Set<bool>(Search::kSmartPruningStr, false); // No smart pruning
defaults->Set<float>(Search::kTemperatureStr, 1.0); // Temperature = 1.0
defaults->Set<float>(Search::kAggressiveTimePruningStr, 0.0f); // No smart pruning
defaults->Set<float>(Search::kTemperatureStr, 1.0f); // Temperature = 1.0
defaults->Set<bool>(Search::kNoiseStr, true); // Dirichlet noise
defaults->Set<float>(Search::kFpuReductionStr, 0.0); // No FPU reduction.
defaults->Set<float>(Search::kFpuReductionStr, 0.0f); // No FPU reduction.
}

SelfPlayTournament::SelfPlayTournament(const OptionsDict& options,
Expand Down

0 comments on commit b1301aa

Please sign in to comment.