feat: policy network inference

src/policy.cpp runs the network train/policy writes: 3072 threat
inputs (side to move's view, flipped horizontally when its king is on
files e-h, +768 attacked, +1536 defended), a hidden layer with CReLU
and pairwise product, and one output row per move, i8 weights scaled
by 128. The hidden width is read from the file's size, so any trained
width loads. When a network is loaded, eval::policy uses its logits
plus the butterfly-history bias instead of the move heuristics; the
temperature and softmax are unchanged.

A network is built in with make POLICYFILE=<net> (default: none, so
the engine plays as before) or loaded at runtime with the UCI option
PolicyFile. policyfens prints the priors of the trainer's --check
positions.

Checked: with a smoke-trained network policyfens matches the trainer's
float output to a few tenths of a percent in all six positions (black
to move, mirrored king, castling, promotion). Speed with a network:
-13% nps at 512 hidden, -41% at 2048. A zero network built in with
POLICYFILE gives uniform priors. Without a network the bench is
unchanged.

Bench: 529903

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 21:27:38 +01:00
1 parent 1c9d2beec3
commit 15258f952a
8 files changed
+313 -5

No files matched your search

+8 -3
View File
@@ -18,8 +18,10 @@ Every change is validated with SPRT on OpenBench.
two-fold repetition, 50-move and insufficient-material draws inside the tree.
- Value: a `(768 -> 128)x2 -> 1` network trained with bullet on Lc0 data
(`networks/rigby-value-v1.bin`, embedded at build time; see `train/README.md`),
behind a capture-only quiescence search. Policy: move heuristics (captures,
promotions, checks, pawn threats) until a policy network exists.
behind a capture-only quiescence search.
- Policy: a network trained on Lc0 visit distributions (`train/policy`), loaded
with `PolicyFile` or built in with `POLICYFILE`; without one, move heuristics
(captures, promotions, checks, pawn threats).
- Tree reuse between moves: the subtree of the new position is packed to the
front of the node arena in place, so it costs no extra memory.
- When the arena is full, the least visited parts of the tree are cut back to
@@ -38,7 +40,8 @@ make EXE=Rigby-dev
make EVALFILE=path/to/quantised.bin
```
`EVALFILE` defaults to `networks/rigby-value-v1.bin`.
`EVALFILE` defaults to `networks/rigby-value-v1.bin`. `POLICYFILE=<net>` builds a
policy network in; by default there is none and the move heuristics are used.
Compiling with `-DRIGBY_VERIFY_TREE` checks the whole tree before and after every
reuse and after every collection (legal moves, visit counts) and aborts on the first
@@ -60,6 +63,7 @@ Extra commands:
| `perft <depth>` | Perft with per-move breakdown |
| `perftsuite [maxdepth]` | Standard perft positions with expected counts |
| `perftfile <epd> [maxdepth]` | Perft of every `<fen> ;D1 <n> ;D2 <n> ...` line of a file (e.g. a Chess960 suite) |
| `policyfens` | Policy network priors of fixed positions, to compare with the trainer's `--check` |
| `bench [playouts]` | Fixed playout search over the bench positions |
`go depth N` limits the mean playout depth. `nodes` in `info` lines are playouts.
@@ -87,6 +91,7 @@ terminal).
| FPUReduction | 30 | First-play urgency reduction x100. |
| PolicyTemp | 100 | Policy softmax temperature x100. |
| UCI_Chess960 | false | Write and read castling as the king taking its rook (`e1h1`). |
| PolicyFile | `<empty>` | Policy network file to use instead of the built-in one or the heuristics. |
## Bench