Merge pull request 'MCGS: remove the value hash' (#25) from mcgs-v-novaluehash into main
Removes the ValueHash; all Hash goes to the graph (MCGS variant 5c). Merged together with the stop rule (#24) at the owner's request; no SPRT has measured the two together. SPRT (Non-Regression, against mcgs-step3-reroot): https://bench.rektdie.com/test/5318/ Elo | 13.59 +- 7.51 (95%) SPRT | 8.0+0.08s Threads=1 Hash=64MB LLR | 3.16 (-2.94, 2.94) [-5.00, 0.00] Games | N: 3120 W: 1028 L: 906 D: 1186 Penta | [59, 283, 767, 379, 72] Bench: 608763
This commit was merged in pull request #25.
This commit is contained in:
commit
59677616f7
3 files changed
+25
-55
No files matched your search
+20
-2
@@ -703,7 +703,8 @@ At `go movetime 40` in the same replay, mean playouts per move were: main
|
||||
Games | N: 4600 W: 1533 L: 1371 D: 1696
|
||||
```
|
||||
|
||||
This measures steps 2, 3 and 3b together against `main`. It is not merged.
|
||||
This measures steps 2, 3 and 3b together against `main`. Merged into main
|
||||
as PR #23 (`75098c8`).
|
||||
|
||||
## Variants on top of step 3b (one branch and one SPRT each)
|
||||
|
||||
@@ -739,4 +740,21 @@ Notes:
|
||||
after every reuse, collection and search that every visited root edge is
|
||||
all draws exactly when its move draws.
|
||||
|
||||
Outcomes are to be filled in.
|
||||
Outcomes are in the table at the top. 5314, 5315 and 5319 were stopped
|
||||
unfinished at the owner's request and are to be revisited later.
|
||||
|
||||
## Merged into main
|
||||
|
||||
| PR | branch | merge commit | bench on main |
|
||||
| --- | --- | --- | ---: |
|
||||
| #23 | `mcgs-step3-reroot` (steps 2, 3, 3b) | `75098c8` | 764208 |
|
||||
| #24 | `mcgs-v-stop` (5a) | `150a876` | 609350 |
|
||||
| #25 | `mcgs-v-novaluehash` (5c) | see `main` | 608763 |
|
||||
|
||||
The stop rule and the ValueHash removal each passed against
|
||||
`mcgs-step3-reroot` alone. They were merged together at the owner's
|
||||
request; no SPRT has measured the two together. Before the last merge the
|
||||
combined code (`mcgs-v-novaluehash` with main merged in) passed the same
|
||||
gates: zero warnings in both builds, `verify` (a)–(d), 300 tree checks in
|
||||
the VERIFY searches with forced GC, the reuse sequences at Hash 64, Hash 1
|
||||
and from the 960 start, and the smoke positions. Bench 608763, twice.
|
||||
@@ -543,10 +543,6 @@ u32 Searcher::create_node(const Position& pos, bool is_root, float& value) {
|
||||
} else if (!is_root && pos.insufficient_material()) {
|
||||
node.state = TERMINAL_DRAW;
|
||||
value = 0.0f;
|
||||
} else if (float q; value_hash_.probe(pos.key, q)) {
|
||||
// A position searched before (dropped by a collection, or from an
|
||||
// earlier search) brings its Q along.
|
||||
value = q;
|
||||
} else {
|
||||
value = eval::value(pos);
|
||||
}
|
||||
@@ -735,10 +731,6 @@ void Searcher::playout() {
|
||||
node.visits++;
|
||||
node.base++;
|
||||
}
|
||||
if (leaf == NEW_NODE || leaf == TERMINAL || leaf == NOT_EXPANDED) {
|
||||
const Node& node = tree_.node(path_.back());
|
||||
value_hash_.store(node.key, -node.q, node.visits);
|
||||
}
|
||||
|
||||
// Up the path: each edge counts the visit (and the draw), and its parent
|
||||
// node recomputes its Q from its children. `value` is from the view of
|
||||
@@ -756,8 +748,6 @@ void Searcher::playout() {
|
||||
Node& node = tree_.node(path_[j]);
|
||||
node.visits++;
|
||||
recompute_q(node);
|
||||
// The Q from the view of the side to move at the node.
|
||||
value_hash_.store(node.key, -node.q, node.visits);
|
||||
}
|
||||
|
||||
iterations_++;
|
||||
|
||||
+5
-43
@@ -175,42 +175,6 @@ private:
|
||||
std::array<std::array<std::array<i16, 64>, 64>, 2> table_{};
|
||||
};
|
||||
|
||||
// Q of positions searched before, from the view of the side to move there
|
||||
// (as in Monty and Vine). Every node of a playout's path stores its Q here;
|
||||
// a leaf whose position is found takes that value instead of a fresh
|
||||
// evaluation. Transpositions are common: 37-85% of leaf evaluations in a
|
||||
// 5-second search repeat a position already evaluated in the same search.
|
||||
class ValueHash {
|
||||
public:
|
||||
void resize(size_t entries) {
|
||||
table_.assign(std::max<size_t>(entries, 1), Entry{});
|
||||
table_.shrink_to_fit();
|
||||
}
|
||||
void clear() { std::fill(table_.begin(), table_.end(), Entry{}); }
|
||||
bool probe(u64 key, float& q) const {
|
||||
const Entry& e = table_[key % table_.size()];
|
||||
if (!e.visits || e.check != u32(key >> 32)) return false;
|
||||
q = e.q;
|
||||
return true;
|
||||
}
|
||||
// A different position always replaces the entry; the same one only with
|
||||
// at least as many visits.
|
||||
void store(u64 key, float q, u32 visits) {
|
||||
Entry& e = table_[key % table_.size()];
|
||||
if (e.check == u32(key >> 32) && visits < e.visits) return;
|
||||
e = Entry{u32(key >> 32), visits, q};
|
||||
}
|
||||
static constexpr size_t ENTRY_BYTES = 12;
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
u32 check = 0;
|
||||
u32 visits = 0;
|
||||
float q = 0.0f;
|
||||
};
|
||||
std::vector<Entry> table_;
|
||||
};
|
||||
|
||||
struct SearchLimits {
|
||||
u64 nodes = 0;
|
||||
i64 movetime = 0;
|
||||
@@ -250,11 +214,11 @@ public:
|
||||
Searcher();
|
||||
|
||||
void set_hash(size_t mb) {
|
||||
// A 32nd of the memory goes to the value hash, the rest to the graph
|
||||
// (its arenas, split by Tree::EDGES_PER_NODE, and its table).
|
||||
const size_t bytes = mb * 1024 * 1024;
|
||||
value_hash_.resize(bytes / 32 / ValueHash::ENTRY_BYTES);
|
||||
tree_.resize_bytes(bytes - bytes / 32);
|
||||
// All of it goes to the graph (its arenas, split by
|
||||
// Tree::EDGES_PER_NODE, and its table). The graph shares a position's
|
||||
// value between move orders, which a separate value hash did in the
|
||||
// tree (plan variant 5c removed it).
|
||||
tree_.resize_bytes(mb * 1024 * 1024);
|
||||
tree_valid_ = false;
|
||||
}
|
||||
|
||||
@@ -262,7 +226,6 @@ public:
|
||||
void new_game() {
|
||||
tree_valid_ = false;
|
||||
butterfly_.clear();
|
||||
value_hash_.clear();
|
||||
}
|
||||
|
||||
// Synchronous search. `history` holds the keys of every position that led to
|
||||
@@ -283,7 +246,6 @@ private:
|
||||
// Kept between moves of a game, like the tree.
|
||||
ButterflyHistory butterfly_;
|
||||
Position root_pos_;
|
||||
ValueHash value_hash_;
|
||||
std::vector<u64> history_;
|
||||
size_t root_history_size_ = 0;
|
||||
// The nodes of a playout, from the root, and the edges it took
|
||||
|
||||
Reference in new issue
Block a user