feat: value network v2, 1024 hidden trained on linrock S2

Replaces the (768 -> 128)x2 value net with (768 -> 1024)x2 -> 1 SCReLU, same
inputs, quantisation and output scale, trained on much more data: the 12 S2
files of huggingface.co/datasets/linrock/bullet-training-data (6.6B positions,
already filtered and shuffled; v1 had one month of test80).

Training: 170 superbatches of 100M positions (17B positions, about 2.6
passes over S2), AdamW, LR 1e-3 cosine to 2.4e-6, target 0.4 * result +
0.6 * sigmoid(score / 400) as in v1. 1h34m on the RTX 3070 at ~3M
positions/s (GPU-bound); final running loss 0.01278 (not comparable to v1's
0.0220, other data). The width was picked for the 2 hour budget: 1024 trains
at 3-4M/s, and in the engine a random 1024 net cost only 16% nps against 128,
thanks to the SIMD kernels.

Trainer (train/value):
- --hidden N (default now 1024) and --batches N for speed tests
- reads bulletformat straight from .bin.zst (src/zstd_reader.rs), so the
  108 GB of S2 never has to be unpacked to 210 GB; training needs ~40 MB/s
  of compressed input, which the HDD holding it gives easily
- also reads raw .bin files (bullet's DirectSequentialDataLoader)

Engine:
- nnue::HIDDEN = 1024, Makefile EVALFILE = networks/rigby-value-v2.bin
- the output layer now sums in blocks of 128 that fit 32 bits and adds
  them up in 64, so it stays exact for any width (the single 32-bit sum was
  only provably safe up to 128)

Checked: evalfens against the trainer's --check on the final checkpoint:
same signs and sizes, within 6 cp on quiet positions and up to 7% on large
evaluations (quantisation; e.g. 553 vs 594 cp). Bench deterministic. UCI:
uci, isready, ucinewgame, go nodes / movetime / infinite + stop.
nps on bench: 4.6M -> 3.5M.

Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-16 18:14:52 +01:00
1 parent 2d3be1982c
commit 79c866c77c
9 files changed
+251 -50

No files matched your search

+15 -11
View File
@@ -41,9 +41,10 @@ inline int feature(int perspective, int piece, int sq) {
// must fit 16 bits, so the weights are checked on load.
constexpr int MAX_L1W = 32767 / QA;
// Each half's dot product is summed in 32 bits.
static_assert(i64(HIDDEN) * QA * QA * MAX_L1W <= INT_MAX);
static_assert(HIDDEN % simd::LANES == 0);
// The output sum is taken in blocks that fit 32 bits, then added up in 64.
constexpr int BLOCK = 128;
static_assert(i64(2) * BLOCK * QA * QA * MAX_L1W <= INT_MAX);
static_assert(HIDDEN % BLOCK == 0 && BLOCK % simd::LANES == 0);
} // namespace
@@ -142,17 +143,20 @@ int evaluate(const Accumulator& acc, int stm) {
const i16* them = acc.values[stm ^ 1];
// SCReLU as v * (v * w) with v clamped to [0, QA]: exact, since v * w fits
// 16 bits and each half's sum fits 32 (checked above).
// 16 bits and a block of both halves fits 32 (checked above).
using namespace simd;
const vi16 lo = set1(0), hi = set1(QA);
vi32 sum_us = zero32(), sum_them = zero32();
for (int i = 0; i < HIDDEN; i += LANES) {
const vi16 u = clamp(load(us + i), lo, hi);
const vi16 t = clamp(load(them + i), lo, hi);
sum_us = dot(sum_us, mullo(u, load(net.l1w + i)), u);
sum_them = dot(sum_them, mullo(t, load(net.l1w + HIDDEN + i)), t);
i64 out = 0;
for (int b = 0; b < HIDDEN; b += BLOCK) {
vi32 sum_us = zero32(), sum_them = zero32();
for (int i = b; i < b + BLOCK; i += LANES) {
const vi16 u = clamp(load(us + i), lo, hi);
const vi16 t = clamp(load(them + i), lo, hi);
sum_us = dot(sum_us, mullo(u, load(net.l1w + i)), u);
sum_them = dot(sum_them, mullo(t, load(net.l1w + HIDDEN + i)), t);
}
out += reduce(add32(sum_us, sum_them));
}
i64 out = i64(reduce(sum_us)) + reduce(sum_them);
out /= QA;
out += net.l1b;