Skip to content

Commit

Permalink
Fix training data being generated without its flag (#274)
Browse files Browse the repository at this point in the history
* Fix training data being generated without its flag

* Cleaner terminal node output in verbose stats
  • Loading branch information
dubslow authored Aug 19, 2018
1 parent c72d6d1 commit 95fcc2c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/mcts/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,9 @@ V3TrainingData Node::GetV3TrainingData(GameResult game_result,
result.version = 3;

// Populate probabilities.
float total_n = static_cast<float>(
GetN() - 1); // First visit was expansion of "this" itself.
float total_n = static_cast<float>(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()] =
Expand Down
2 changes: 1 addition & 1 deletion src/mcts/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/selfplay/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_) {
Expand Down
3 changes: 2 additions & 1 deletion src/selfplay/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/selfplay/tournament.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 95fcc2c

Please sign in to comment.