mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 07:27:46 +00:00
Synchronize printed info regions in the learner and sfen reader.
This commit is contained in:
+21
-15
@@ -138,7 +138,8 @@ namespace Learner
|
|||||||
count = 0.0;
|
count = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(const std::string& prefix, ostream& s) const
|
template <typename StreamT>
|
||||||
|
void print(const std::string& prefix, StreamT& s) const
|
||||||
{
|
{
|
||||||
s << "==> " << prefix << "_cross_entropy_eval = " << cross_entropy_eval / count << endl;
|
s << "==> " << prefix << "_cross_entropy_eval = " << cross_entropy_eval / count << endl;
|
||||||
s << "==> " << prefix << "_cross_entropy_win = " << cross_entropy_win / count << endl;
|
s << "==> " << prefix << "_cross_entropy_win = " << cross_entropy_win / count << endl;
|
||||||
@@ -499,8 +500,9 @@ namespace Learner
|
|||||||
if (validation_set_file_name.empty()
|
if (validation_set_file_name.empty()
|
||||||
&& sfen_for_mse.size() != sfen_for_mse_size)
|
&& sfen_for_mse.size() != sfen_for_mse_size)
|
||||||
{
|
{
|
||||||
cout
|
auto out = sync_region_cout.new_region();
|
||||||
<< "Error reading sfen_for_mse. Read " << sfen_for_mse.size()
|
out
|
||||||
|
<< "INFO (learn): Error reading sfen_for_mse. Read " << sfen_for_mse.size()
|
||||||
<< " out of " << sfen_for_mse_size << '\n';
|
<< " out of " << sfen_for_mse_size << '\n';
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -514,7 +516,8 @@ namespace Learner
|
|||||||
latest_loss_sum = 0.0;
|
latest_loss_sum = 0.0;
|
||||||
latest_loss_count = 0;
|
latest_loss_count = 0;
|
||||||
|
|
||||||
cout << "initial loss: " << best_loss << endl;
|
auto out = sync_region_cout.new_region();
|
||||||
|
out << "INFO (learn): initial loss = " << best_loss << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_flag = false;
|
stop_flag = false;
|
||||||
@@ -585,7 +588,8 @@ namespace Learner
|
|||||||
if (pos.set_from_packed_sfen(ps.sfen, &si, &th) != 0)
|
if (pos.set_from_packed_sfen(ps.sfen, &si, &th) != 0)
|
||||||
{
|
{
|
||||||
// Malformed sfen
|
// Malformed sfen
|
||||||
cout << "Error! : illigal packed sfen = " << pos.fen() << endl;
|
auto out = sync_region_cout.new_region();
|
||||||
|
out << "ERROR: illigal packed sfen = " << pos.fen() << endl;
|
||||||
goto RETRY_READ;
|
goto RETRY_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,14 +678,16 @@ namespace Learner
|
|||||||
TT.new_search();
|
TT.new_search();
|
||||||
TimePoint elapsed = now() - Search::Limits.startTime + 1;
|
TimePoint elapsed = now() - Search::Limits.startTime + 1;
|
||||||
|
|
||||||
cout << "\n";
|
auto out = sync_region_cout.new_region();
|
||||||
cout << "PROGRESS (calc_loss): " << now_string()
|
|
||||||
|
out << "\n";
|
||||||
|
out << "PROGRESS (calc_loss): " << now_string()
|
||||||
<< ", " << total_done << " sfens"
|
<< ", " << total_done << " sfens"
|
||||||
<< ", " << total_done * 1000 / elapsed << " sfens/second"
|
<< ", " << total_done * 1000 / elapsed << " sfens/second"
|
||||||
<< ", epoch " << epoch
|
<< ", epoch " << epoch
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
cout << "==> learning rate = " << global_learning_rate << endl;
|
out << "==> learning rate = " << global_learning_rate << endl;
|
||||||
|
|
||||||
// For calculation of verification data loss
|
// For calculation of verification data loss
|
||||||
AtomicLoss test_loss_sum{};
|
AtomicLoss test_loss_sum{};
|
||||||
@@ -694,11 +700,11 @@ namespace Learner
|
|||||||
atomic<int> move_accord_count{0};
|
atomic<int> move_accord_count{0};
|
||||||
|
|
||||||
auto mainThread = Threads.main();
|
auto mainThread = Threads.main();
|
||||||
mainThread->execute_with_worker([](auto& th){
|
mainThread->execute_with_worker([&out](auto& th){
|
||||||
auto& pos = th.rootPos;
|
auto& pos = th.rootPos;
|
||||||
StateInfo si;
|
StateInfo si;
|
||||||
pos.set(StartFEN, false, &si, &th);
|
pos.set(StartFEN, false, &si, &th);
|
||||||
cout << "==> startpos eval = " << Eval::evaluate(pos) << endl;
|
out << "==> startpos eval = " << Eval::evaluate(pos) << endl;
|
||||||
});
|
});
|
||||||
mainThread->wait_for_worker_finished();
|
mainThread->wait_for_worker_finished();
|
||||||
|
|
||||||
@@ -721,19 +727,19 @@ namespace Learner
|
|||||||
|
|
||||||
if (psv.size() && test_loss_sum.count > 0.0)
|
if (psv.size() && test_loss_sum.count > 0.0)
|
||||||
{
|
{
|
||||||
test_loss_sum.print("test", cout);
|
test_loss_sum.print("test", out);
|
||||||
|
|
||||||
if (learn_loss_sum.count > 0.0)
|
if (learn_loss_sum.count > 0.0)
|
||||||
{
|
{
|
||||||
learn_loss_sum.print("learn", cout);
|
learn_loss_sum.print("learn", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "==> norm = " << sum_norm << endl;
|
out << "==> norm = " << sum_norm << endl;
|
||||||
cout << "==> move accuracy = " << (move_accord_count * 100.0 / psv.size()) << "%" << endl;
|
out << "==> move accuracy = " << (move_accord_count * 100.0 / psv.size()) << "%" << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "Error! : psv.size() = " << psv.size() << " , done = " << test_loss_sum.count << endl;
|
out << "ERROR: psv.size() = " << psv.size() << " , done = " << test_loss_sum.count << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
learn_loss_sum.reset();
|
learn_loss_sum.reset();
|
||||||
|
|||||||
@@ -209,18 +209,19 @@ namespace Learner{
|
|||||||
|
|
||||||
sfen_input_stream = open_sfen_input_file(currentFilename);
|
sfen_input_stream = open_sfen_input_file(currentFilename);
|
||||||
|
|
||||||
|
auto out = sync_region_cout.new_region();
|
||||||
if (sfen_input_stream == nullptr)
|
if (sfen_input_stream == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "INFO (sfen_reader): File does not exist: " << currentFilename << '\n';
|
out << "INFO (sfen_reader): File does not exist: " << currentFilename << '\n';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "INFO (sfen_reader): Opened file for reading: " << currentFilename << '\n';
|
out << "INFO (sfen_reader): Opened file for reading: " << currentFilename << '\n';
|
||||||
|
|
||||||
// in case the file is empty or was deleted.
|
// in case the file is empty or was deleted.
|
||||||
if (sfen_input_stream->eof())
|
if (sfen_input_stream->eof())
|
||||||
{
|
{
|
||||||
std::cout << "INFO (sfen_reader): File empty, nothing to read.\n";
|
out << "==> File empty, nothing to read.\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -232,7 +233,8 @@ namespace Learner{
|
|||||||
|
|
||||||
if (sfen_input_stream == nullptr && !open_next_file())
|
if (sfen_input_stream == nullptr && !open_next_file())
|
||||||
{
|
{
|
||||||
std::cout << "INFO (sfen_reader): End of files." << std::endl;
|
auto out = sync_region_cout.new_region();
|
||||||
|
out << "INFO (sfen_reader): End of files." << std::endl;
|
||||||
end_of_files = true;
|
end_of_files = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -271,7 +273,8 @@ namespace Learner{
|
|||||||
if(!open_next_file())
|
if(!open_next_file())
|
||||||
{
|
{
|
||||||
// There was no next file. Abort.
|
// There was no next file. Abort.
|
||||||
std::cout << "INFO (sfen_reader): End of files." << std::endl;
|
auto out = sync_region_cout.new_region();
|
||||||
|
out << "INFO (sfen_reader): End of files." << std::endl;
|
||||||
end_of_files = true;
|
end_of_files = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,7 +224,9 @@ namespace Eval::NNUE {
|
|||||||
const double avg_abs_eval_diff = abs_eval_diff_sum / batch_size;
|
const double avg_abs_eval_diff = abs_eval_diff_sum / batch_size;
|
||||||
const double avg_abs_discrete_eval = abs_discrete_eval_sum / batch_size;
|
const double avg_abs_discrete_eval = abs_discrete_eval_sum / batch_size;
|
||||||
|
|
||||||
std::cout << "INFO (update_parameters):"
|
auto out = sync_region_cout.new_region();
|
||||||
|
|
||||||
|
out << "INFO (update_parameters):"
|
||||||
<< " epoch = " << epoch
|
<< " epoch = " << epoch
|
||||||
<< " , avg_abs(trainer_eval-nnue_eval) = " << avg_abs_eval_diff
|
<< " , avg_abs(trainer_eval-nnue_eval) = " << avg_abs_eval_diff
|
||||||
<< " , avg_abs(nnue_eval) = " << avg_abs_discrete_eval
|
<< " , avg_abs(nnue_eval) = " << avg_abs_discrete_eval
|
||||||
|
|||||||
@@ -94,19 +94,24 @@ namespace Eval::NNUE {
|
|||||||
|
|
||||||
// Check if there are any problems with learning
|
// Check if there are any problems with learning
|
||||||
void check_health() {
|
void check_health() {
|
||||||
|
|
||||||
const auto largest_min_activation = *std::max_element(
|
const auto largest_min_activation = *std::max_element(
|
||||||
std::begin(min_activations_), std::end(min_activations_));
|
std::begin(min_activations_), std::end(min_activations_));
|
||||||
const auto smallest_max_activation = *std::min_element(
|
const auto smallest_max_activation = *std::min_element(
|
||||||
std::begin(max_activations_), std::end(max_activations_));
|
std::begin(max_activations_), std::end(max_activations_));
|
||||||
|
|
||||||
std::cout << "INFO (check_health):"
|
auto out = sync_region_cout.new_region();
|
||||||
<< " layer " << LayerType::kLayerIndex
|
|
||||||
<< " - " << LayerType::get_name()
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
std::cout << "==> largest min activation = " << largest_min_activation
|
out << "INFO (check_health):"
|
||||||
<< " , smallest max activation = " << smallest_max_activation
|
<< " layer " << LayerType::kLayerIndex
|
||||||
<< std::endl;
|
<< " - " << LayerType::get_name()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
out << "==> largest min activation = " << largest_min_activation
|
||||||
|
<< " , smallest max activation = " << smallest_max_activation
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
out.unlock();
|
||||||
|
|
||||||
std::fill(std::begin(min_activations_), std::end(min_activations_),
|
std::fill(std::begin(min_activations_), std::end(min_activations_),
|
||||||
std::numeric_limits<LearnFloatType>::max());
|
std::numeric_limits<LearnFloatType>::max());
|
||||||
|
|||||||
@@ -330,33 +330,38 @@ namespace Eval::NNUE {
|
|||||||
|
|
||||||
// Check if there are any problems with learning
|
// Check if there are any problems with learning
|
||||||
void check_health() {
|
void check_health() {
|
||||||
std::cout << "INFO (check_health):"
|
|
||||||
<< " layer " << LayerType::kLayerIndex
|
|
||||||
<< " - " << LayerType::get_name()
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
std::cout << "==> observed " << observed_features.count()
|
|
||||||
<< " (out of " << kInputDimensions << ") features"
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
constexpr LearnFloatType kPreActivationLimit =
|
constexpr LearnFloatType kPreActivationLimit =
|
||||||
std::numeric_limits<typename LayerType::WeightType>::max() /
|
std::numeric_limits<typename LayerType::WeightType>::max() /
|
||||||
kWeightScale;
|
kWeightScale;
|
||||||
|
|
||||||
std::cout << "==> (min, max) of pre-activations = "
|
|
||||||
<< min_pre_activation_ << ", "
|
|
||||||
<< max_pre_activation_ << " (limit = "
|
|
||||||
<< kPreActivationLimit << ")"
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
const auto largest_min_activation = *std::max_element(
|
const auto largest_min_activation = *std::max_element(
|
||||||
std::begin(min_activations_), std::end(min_activations_));
|
std::begin(min_activations_), std::end(min_activations_));
|
||||||
const auto smallest_max_activation = *std::min_element(
|
const auto smallest_max_activation = *std::min_element(
|
||||||
std::begin(max_activations_), std::end(max_activations_));
|
std::begin(max_activations_), std::end(max_activations_));
|
||||||
|
|
||||||
std::cout << "==> largest min activation = " << largest_min_activation
|
auto out = sync_region_cout.new_region();
|
||||||
<< " , smallest max activation = " << smallest_max_activation
|
|
||||||
<< std::endl;
|
out << "INFO (check_health):"
|
||||||
|
<< " layer " << LayerType::kLayerIndex
|
||||||
|
<< " - " << LayerType::get_name()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
out << "==> observed " << observed_features.count()
|
||||||
|
<< " (out of " << kInputDimensions << ") features"
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
out << "==> (min, max) of pre-activations = "
|
||||||
|
<< min_pre_activation_ << ", "
|
||||||
|
<< max_pre_activation_ << " (limit = "
|
||||||
|
<< kPreActivationLimit << ")"
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
out << "==> largest min activation = " << largest_min_activation
|
||||||
|
<< " , smallest max activation = " << smallest_max_activation
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
out.unlock();
|
||||||
|
|
||||||
std::fill(std::begin(min_activations_), std::end(min_activations_),
|
std::fill(std::begin(min_activations_), std::end(min_activations_),
|
||||||
std::numeric_limits<LearnFloatType>::max());
|
std::numeric_limits<LearnFloatType>::max());
|
||||||
|
|||||||
Reference in New Issue
Block a user