feat: value network trained on Lc0 data

The static evaluation behind the quiescence search is now a
(768 -> 128)x2 -> 1 SCReLU network instead of the hand-written
evaluation. It was trained with bullet on linrock's Lc0-derived test80
2024-02 binpack, 40 superbatches (10 min on an RTX 3070), final loss
0.0220. The quiescence search itself is unchanged.

The network is embedded with incbin (EVALFILE, default
networks/rigby-value-v1.bin). Q is tanh(cp / 800), the same scale the
network was trained on (sigmoid(cp / 400) = expected score).

Checked: bullet's float evaluation of fixed positions (trainer --check)
and the engine's quantised inference (evalfens) agree within 6 cp; an
integer re-implementation in Python matches the engine exactly. Perft
passes, bench is deterministic.

Bench: 545914

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 04:12:52 +01:00
1 parent 530c4d67ed
commit 30b0c36cd5
14 files changed
+700 -68

No files matched your search

+34 -1
View File
@@ -6,6 +6,11 @@
//!
//! Usage:
//! cargo run --release -- [--data <file.binpack>]... [--superbatches N] [--id NAME]
//! cargo run --release -- --check checkpoints/<id>-<superbatch>
//!
//! `--check` loads a checkpoint and prints the network's evaluation (centipawns,
//! side to move) of a few fixed positions, as a reference for the engine's own
//! inference (Rigby's `evalfens` command prints the same list).
//!
//! The network is written to checkpoints/<id>-<superbatch>/quantised.bin every
//! SAVE_RATE superbatches and at the end. Inference in Rigby has to use the same
@@ -46,14 +51,28 @@ fn filter(entry: &TrainingDataEntry) -> bool {
&& entry.pos.piece_at(entry.mv.to()).piece_type() == PieceType::None
}
/// Positions for `--check`; keep in sync with Rigby's `evalfens` command.
const CHECK_FENS: [&str; 8] = [
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R b KQkq - 0 1",
"6k1/5pp1/1p2p2p/1Pq1Pn2/2P2P2/6P1/4Q1BP/6K1 w - - 1 30",
"8/8/3k4/2p1p3/2P1P3/3K4/8/8 w - - 0 1",
"4k3/8/8/8/8/8/8/R3K3 w - - 0 1",
"4k3/8/8/8/8/8/8/R3K3 b - - 0 1",
];
struct Args {
data: Vec<String>,
superbatches: usize,
id: String,
check: Option<String>,
}
fn parse_args() -> Args {
let mut args = Args { data: Vec::new(), superbatches: DEFAULT_SUPERBATCHES, id: "rigby-value".to_string() };
let mut args =
Args { data: Vec::new(), superbatches: DEFAULT_SUPERBATCHES, id: "rigby-value".to_string(), check: None };
let mut it = std::env::args().skip(1);
while let Some(arg) = it.next() {
match arg.as_str() {
@@ -62,9 +81,13 @@ fn parse_args() -> Args {
args.superbatches = it.next().expect("--superbatches needs a number").parse().expect("not a number")
}
"--id" => args.id = it.next().expect("--id needs a name"),
"--check" => args.check = Some(it.next().expect("--check needs a checkpoint directory")),
other => panic!("unknown argument: {other}"),
}
}
if args.check.is_some() {
return args;
}
if args.data.is_empty() {
args.data.push(DEFAULT_DATA.to_string());
}
@@ -97,6 +120,16 @@ fn main() {
l1.forward(stm_hidden.concat(ntm_hidden))
});
if let Some(checkpoint) = &args.check {
trainer.load_from_checkpoint(checkpoint);
for fen in CHECK_FENS {
// bulletformat's text form: <fen> | <score> | <result>
let raw = trainer.eval(&format!("{fen} | 0 | 0.5"));
println!("{:6.0} cp {fen}", raw * SCALE as f32);
}
return;
}
let schedule = TrainingSchedule {
net_id: args.id.clone(),
eval_scale: SCALE as f32,