diff --git a/src/mcts/node.cc b/src/mcts/node.cc index bcde029ba5..36dab579c5 100644 --- a/src/mcts/node.cc +++ b/src/mcts/node.cc @@ -288,10 +288,9 @@ V3TrainingData Node::GetV3TrainingData(GameResult game_result, result.version = 3; // Populate probabilities. - float total_n = static_cast( - GetN() - 1); // First visit was expansion of "this" itself. + float total_n = static_cast(GetChildrenVisits()); // Prevent garbage/invalid training data from being uploaded to server. - if (total_n <= 0) throw Exception("Search generated invalid data!"); + if (total_n <= 0.0f) throw Exception("Search generated invalid data!"); std::memset(result.probabilities, 0, sizeof(result.probabilities)); for (const auto& child : Edges()) { result.probabilities[child.edge()->GetMove().as_nn_index()] = diff --git a/src/mcts/search.cc b/src/mcts/search.cc index 2e01dd211a..fd71db409a 100644 --- a/src/mcts/search.cc +++ b/src/mcts/search.cc @@ -251,7 +251,7 @@ void Search::SendMovesStats() const { } oss << ") "; - oss << "(T: " << edge.IsTerminal() << ") "; + if (edge.IsTerminal()) oss << "(T) "; info.comment = oss.str(); info_callback_(info); diff --git a/src/selfplay/game.cc b/src/selfplay/game.cc index feabf906f1..f73a2d2066 100644 --- a/src/selfplay/game.cc +++ b/src/selfplay/game.cc @@ -58,7 +58,7 @@ SelfPlayGame::SelfPlayGame(PlayerOptions player1, PlayerOptions player2, } void SelfPlayGame::Play(int white_threads, int black_threads, - bool enable_resign) { + bool training, bool enable_resign) { bool blacks_move = false; // Do moves while not end of the game. (And while not abort_) @@ -87,9 +87,11 @@ void SelfPlayGame::Play(int white_threads, int black_threads, search_->RunBlocking(blacks_move ? black_threads : white_threads); if (abort_) break; - // Append training data. The GameResult is later overwritten. - training_data_.push_back(tree_[idx]->GetCurrentHead()->GetV3TrainingData( - GameResult::UNDECIDED, tree_[idx]->GetPositionHistory())); + if (training) { + // Append training data. The GameResult is later overwritten. + training_data_.push_back(tree_[idx]->GetCurrentHead()->GetV3TrainingData( + GameResult::UNDECIDED, tree_[idx]->GetPositionHistory())); + } float eval = search_->GetBestEval(); eval = (eval + 1) / 2; @@ -137,6 +139,7 @@ void SelfPlayGame::Abort() { } void SelfPlayGame::WriteTrainingData(TrainingDataWriter* writer) const { + assert(!training_data_.empty()); bool black_to_move = tree_[0]->GetPositionHistory().Starting().IsBlackToMove(); for (auto chunk : training_data_) { diff --git a/src/selfplay/game.h b/src/selfplay/game.h index ae989b5d89..474fc246fc 100644 --- a/src/selfplay/game.h +++ b/src/selfplay/game.h @@ -64,7 +64,8 @@ class SelfPlayGame { static void PopulateUciParams(OptionsParser* options); // Starts the game and blocks until the game is finished. - void Play(int white_threads, int black_threads, bool enable_resign = true); + void Play(int white_threads, int black_threads, bool training, + bool enable_resign = true); // Aborts the game currently played, doesn't matter if it's synchronous or // not. void Abort(); diff --git a/src/selfplay/tournament.cc b/src/selfplay/tournament.cc index 4860ae47cf..044e5f7c7e 100644 --- a/src/selfplay/tournament.cc +++ b/src/selfplay/tournament.cc @@ -252,7 +252,8 @@ void SelfPlayTournament::PlayOneGame(int game_number) { bool enable_resign = Random::Get().GetFloat(100.0f) >= kResignPlaythrough; // PLAY GAME! - game.Play(kThreads[color_idx[0]], kThreads[color_idx[1]], enable_resign); + game.Play(kThreads[color_idx[0]], kThreads[color_idx[1]], kTraining, + enable_resign); // If game was aborted, it's still undecided. if (game.GetGameResult() != GameResult::UNDECIDED) {