diff --git a/src/Parameters.cpp b/src/Parameters.cpp index 25a6b3065..bf9193cbf 100644 --- a/src/Parameters.cpp +++ b/src/Parameters.cpp @@ -89,7 +89,7 @@ void Parameters::setup_default_parameters() { #endif cfg_puct = 0.6f; cfg_softmax_temp = 1.0f; - cfg_fpu_reduction = 0.0f; + cfg_fpu_reduction = 0.1f; cfg_fpu_dynamic_eval = true; cfg_root_temp_decay = 0; cfg_min_resign_moves = 20; diff --git a/src/UCTNode.cpp b/src/UCTNode.cpp index 773d7a800..412bc7a67 100644 --- a/src/UCTNode.cpp +++ b/src/UCTNode.cpp @@ -354,7 +354,7 @@ UCTNode* UCTNode::uct_select_child(Color color, bool is_root) { // Estimated eval for unknown nodes = original parent NN eval - reduction // Or curent parent eval - reduction if dynamic_eval is enabled. - auto fpu_eval = (cfg_fpu_dynamic_eval ? get_eval(color) : net_eval) - fpu_reduction; + auto fpu_eval = (cfg_fpu_dynamic_eval ? get_raw_eval(color) : net_eval) - fpu_reduction; for (const auto& child : m_children) { if (!child->active()) { diff --git a/src/UCTSearch.cpp b/src/UCTSearch.cpp index ec33bd31c..dc1e0bc14 100644 --- a/src/UCTSearch.cpp +++ b/src/UCTSearch.cpp @@ -59,13 +59,16 @@ void UCTSearch::set_quiet(bool quiet) { quiet_ = quiet; } -SearchResult UCTSearch::play_simulation(BoardHistory& bh, UCTNode* const node) { +SearchResult UCTSearch::play_simulation(BoardHistory& bh, UCTNode* const node, int ndepth) { const auto& cur = bh.cur(); const auto color = cur.side_to_move(); auto result = SearchResult{}; node->virtual_loss(); + if (ndepth > m_maxdepth) { + m_maxdepth = ndepth; + } if (!node->has_children()) { bool drawn = cur.is_draw(); @@ -102,7 +105,7 @@ SearchResult UCTSearch::play_simulation(BoardHistory& bh, UCTNode* const node) { auto next = node->uct_select_child(color, node == m_root.get()); auto move = next->get_move(); bh.do_move(move); - result = play_simulation(bh, next); + result = play_simulation(bh, next, ndepth+1); } if (result.valid()) { @@ -266,8 +269,7 @@ void UCTSearch::dump_analysis(int64_t elapsed, bool force_output) { float feval = m_root->get_raw_eval(color); // UCI-like output wants a depth and a cp, so convert winrate to a cp estimate. int cp = 290.680623072 * tan(3.096181612 * (feval - 0.5)); - // same for nodes to depth, assume nodes = 1.8 ^ depth. - int depth = log(float(m_nodes)) / log(1.8); + int depth = m_maxdepth; // To report nodes, use visits. // - Only includes expanded nodes. // - Includes nodes carried over from tree reuse. @@ -364,7 +366,7 @@ bool UCTSearch::pv_limit_reached() const { void UCTWorker::operator()() { do { BoardHistory bh = bh_.shallow_clone(); - auto result = m_search->play_simulation(bh, m_root); + auto result = m_search->play_simulation(bh, m_root, 0); if (result.valid()) { m_search->increment_playouts(); } @@ -390,6 +392,7 @@ Move UCTSearch::think(BoardHistory&& new_bh) { } m_playouts = 0; + m_maxdepth = 0; m_nodes = m_root->count_nodes(); m_tbhits = 0; // TODO: Both UCI and the next line do shallow_clone. @@ -447,13 +450,12 @@ Move UCTSearch::think(BoardHistory&& new_bh) { int last_update = 0; do { auto currstate = bh_.shallow_clone(); - auto result = play_simulation(currstate, m_root.get()); + auto result = play_simulation(currstate, m_root.get(), 0); if (result.valid()) { increment_playouts(); } - // assume nodes = 1.8 ^ depth. - int depth = log(float(m_nodes)) / log(1.8); + int depth = m_maxdepth; if (depth != last_update) { last_update = depth; dump_analysis(Time.elapsed(), false); @@ -506,7 +508,7 @@ void UCTSearch::ponder() { } do { auto bh = bh_.shallow_clone(); - auto result = play_simulation(bh, m_root.get()); + auto result = play_simulation(bh, m_root.get(), 0); if (result.valid()) { increment_playouts(); } diff --git a/src/UCTSearch.h b/src/UCTSearch.h index dbed91767..23b3d3e09 100644 --- a/src/UCTSearch.h +++ b/src/UCTSearch.h @@ -81,7 +81,7 @@ class UCTSearch { void increment_playouts(); bool should_halt_search(); void please_stop(); - SearchResult play_simulation(BoardHistory& bh, UCTNode* const node); + SearchResult play_simulation(BoardHistory& bh, UCTNode* const node, int sdepth); private: void dump_stats(BoardHistory& pos, UCTNode& parent); @@ -95,6 +95,7 @@ class UCTSearch { std::unique_ptr m_root; std::atomic m_nodes{0}; std::atomic m_playouts{0}; + std::atomic m_maxdepth{0}; std::atomic m_tbhits{0}; int64_t m_target_time{0}; int64_t m_max_time{0}; diff --git a/src/config.h b/src/config.h index bc51701d9..2d52f7f2b 100644 --- a/src/config.h +++ b/src/config.h @@ -37,7 +37,7 @@ #endif static constexpr int SELFCHECK_PROBABILITY = 2000; static constexpr int SELFCHECK_MIN_EXPANSIONS = 2'000'000; -//#define USE_TUNER +#define USE_TUNER #define PROGRAM_VERSION "v0.7" diff --git a/src/main.cpp b/src/main.cpp index 716fd56e3..71993438a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,6 +101,7 @@ static std::string parse_commandline(int argc, char *argv[]) { #endif #ifdef USE_TUNER ("puct", po::value()) + ("fpu_reduction", po::value()) ("softmax_temp", po::value()) #endif ; @@ -150,6 +151,9 @@ static std::string parse_commandline(int argc, char *argv[]) { if (vm.count("puct")) { cfg_puct = vm["puct"].as(); } + if (vm.count("fpu_reduction")) { + cfg_fpu_reduction = vm["fpu_reduction"].as(); + } if (vm.count("softmax_temp")) { cfg_softmax_temp = vm["softmax_temp"].as(); }