Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix training data being generated without its flag #274

Merged
merged 2 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be emplace_back?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one copy with push_back() and probably one copy with emplace_back() too (surely not less).
I don't really have a preference here actually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, forgot that the argument to push_back isn't actually a constructor call lol

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