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:
1 parent
1c9d2beec3
commit
15258f952a
8 files changed
+313
-5
No files matched your search
@@ -1,5 +1,6 @@
|
||||
# Rigby - MCTS chess engine
|
||||
# OpenBench calls: make EXE=<name> [EVALFILE=<net>] [CXX=<compiler>]
|
||||
# A policy network is built in with POLICYFILE=<net> (default: none).
|
||||
|
||||
SRC_DIR := src
|
||||
OBJ_DIR := obj
|
||||
@@ -7,6 +8,8 @@ OBJ_DIR := obj
|
||||
EXE ?= Rigby
|
||||
# The value network embedded into the binary
|
||||
EVALFILE ?= networks/rigby-value-v1.bin
|
||||
# The policy network embedded into the binary; none means move heuristics
|
||||
POLICYFILE ?=
|
||||
CXX ?= clang++
|
||||
ifeq ($(origin CXX),default)
|
||||
CXX := clang++
|
||||
@@ -57,6 +60,9 @@ else
|
||||
endif
|
||||
|
||||
CXXFLAGS += -DEVALFILE=\"$(EVALFILE)\"
|
||||
ifneq ($(POLICYFILE),)
|
||||
CXXFLAGS += -DPOLICYFILE=\"$(POLICYFILE)\"
|
||||
endif
|
||||
|
||||
CXXFLAGS += $(ARCH_FLAGS)
|
||||
LDFLAGS += $(ARCH_FLAGS)
|
||||
@@ -78,6 +84,9 @@ $(OBJ_DIR):
|
||||
|
||||
# Rebuild the network's translation unit when the network changes
|
||||
$(OBJ_DIR)/nnue.o: $(EVALFILE)
|
||||
ifneq ($(POLICYFILE),)
|
||||
$(OBJ_DIR)/policy.o: $(POLICYFILE)
|
||||
endif
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
|
||||
Reference in new issue
Block a user