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

+3 -2
View File
@@ -5,7 +5,8 @@
namespace rigby::eval {
// Value: the network trained on Lc0 data, behind a capture-only quiescence
// search. Policy: move heuristics until a policy network exists.
// search. Policy: the policy network when one is loaded (see policy.h),
// otherwise move heuristics.
void init();
@@ -23,7 +24,7 @@ int quiescence(const Position& pos, int alpha, int beta, int ply);
float value(const Position& pos);
// Writes softmax-normalised priors for `moves` into `out`. `bias`, when not
// null, is added to each move's logit before the softmax.
// null, is added to each move's logit before the softmax (and the temperature).
void policy(const Position& pos, const MoveList& moves, float temperature, const float* bias, float* out);
// Conversion between centipawns and Q in [-1, 1]. One scale for both directions,