feat: cpuct scaled by the variance of Q
Monty raises exploration where a node's results spread widely and lowers it where they agree: cpuct *= 1 + weight * (frac - 1) with frac = stddev(Q) / scale, pulled towards 1 by (1 - frac) / (1 + warmup * N) while the node has few visits. Rigby now does the same with Monty's weight 0.8462 and warmup 0.4988; Monty's scale 0.2710 is for Q in [0, 1], so it is doubled to 0.5420 for Rigby's [-1, 1]. The variance needs the running mean of the squared results, a new float per node: Node grows from 20 to 24 bytes, so the same Hash holds a sixth fewer nodes (README updated). Checked: bench deterministic; RIGBY_VERIFY_TREE build driven over UCI with pauses (tree reuse up to 208k nodes, collections at Hash 1 MB, wtime/winc, movetime, mate-in-one positions found, go infinite + stop) without an abort. Bench: 764580 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
74fb5eb2fb
commit
05e902c683
3 files changed
+19
-3
No files matched your search
@@ -84,7 +84,7 @@ terminal).
|
||||
|
||||
| Option | Default | Meaning |
|
||||
| --- | --- | --- |
|
||||
| Hash | 64 | Tree memory in MB. A node takes 20 bytes. |
|
||||
| Hash | 64 | Tree memory in MB. A node takes 24 bytes. |
|
||||
| Threads | 1 | Only 1 for now. |
|
||||
| MoveOverhead | 20 | Milliseconds kept back per move. |
|
||||
| CPuct | 160 | Exploration constant x100. |
|
||||
|
||||
+8
-1
@@ -373,7 +373,13 @@ u32 Searcher::select_child(u32 idx) const {
|
||||
const float n = float(std::max<u32>(node.visits, 1));
|
||||
// The root, where the move is chosen, explores more.
|
||||
const float base_cpuct = idx == Tree::root() ? params.root_cpuct : params.cpuct;
|
||||
const float cpuct = base_cpuct * (1.0f + std::log((n + params.cpuct_visit_scale) / params.cpuct_visit_scale));
|
||||
float cpuct = base_cpuct * (1.0f + std::log((n + params.cpuct_visit_scale) / params.cpuct_visit_scale));
|
||||
// A node whose results spread widely explores more, a settled one less.
|
||||
if (node.visits > 1) {
|
||||
float frac = std::sqrt(node.variance()) / params.cpuct_var_scale;
|
||||
frac += (1.0f - frac) / (1.0f + params.cpuct_var_warmup * float(node.visits));
|
||||
cpuct *= 1.0f + params.cpuct_var_weight * (frac - 1.0f);
|
||||
}
|
||||
const float explore = cpuct * std::sqrt(n);
|
||||
|
||||
u32 best = node.first_child;
|
||||
@@ -443,6 +449,7 @@ void Searcher::playout() {
|
||||
Node& node = tree_[path_[i]];
|
||||
node.visits++;
|
||||
node.q += (value - node.q) / float(node.visits);
|
||||
node.sq_q += (value * value - node.sq_q) / float(node.visits);
|
||||
if (i) butterfly_.update(root_pos_.stm ^ int((i - 1) & 1), Move::from_raw(node.move), bonus);
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -19,18 +19,20 @@ enum NodeState : u8 {
|
||||
TERMINAL_DRAW,
|
||||
};
|
||||
|
||||
// 20 bytes. Children of a node sit next to each other in the arena, so a node
|
||||
// 24 bytes. Children of a node sit next to each other in the arena, so a node
|
||||
// only needs the index of its first child.
|
||||
struct Node {
|
||||
u32 first_child = 0;
|
||||
u32 visits = 0;
|
||||
float q = 0.0f; // running mean, from the view of the side that played `move`
|
||||
float sq_q = 0.0f; // running mean of the squared results, for the variance of Q
|
||||
u16 move = 0;
|
||||
u16 policy = 0; // prior scaled to 0..65535
|
||||
u8 num_children = 0;
|
||||
u8 state = UNEXPANDED;
|
||||
|
||||
float prior() const { return float(policy) * (1.0f / 65535.0f); }
|
||||
float variance() const { return std::max(sq_q - q * q, 0.0f); }
|
||||
};
|
||||
|
||||
class Tree {
|
||||
@@ -102,6 +104,13 @@ struct SearchParams {
|
||||
// cpuct is multiplied by 1 + ln((N + scale) / scale) for a node with N visits
|
||||
// (Monty: 64 x 128).
|
||||
float cpuct_visit_scale = 8192.0f;
|
||||
// cpuct grows with the standard deviation of a node's Q (Monty's
|
||||
// cpuct_var_scale, _weight, _warmup): x(1 + weight * (frac - 1)) with
|
||||
// frac = stddev / scale, pulled towards 1 while the node has few visits.
|
||||
// Monty's scale 0.2710 is for Q in [0, 1]; doubled for Rigby's [-1, 1].
|
||||
float cpuct_var_scale = 0.5420f;
|
||||
float cpuct_var_weight = 0.8462f;
|
||||
float cpuct_var_warmup = 0.4988f;
|
||||
float fpu_reduction = 0.30f;
|
||||
float policy_temperature = 1.00f;
|
||||
i64 move_overhead = 20;
|
||||
|
||||
Reference in new issue
Block a user