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:
1 parent
2d3be1982c
commit
79c866c77c
9 files changed
+251
-50
No files matched your search
+46
-24
@@ -2,36 +2,41 @@
|
||||
|
||||
## Value network (`value/`)
|
||||
|
||||
A small `(768 -> 128)x2 -> 1` SCReLU network trained with
|
||||
[bullet](https://github.com/jw1912/bullet) on Lc0 self-play data.
|
||||
A `(768 -> 1024)x2 -> 1` SCReLU network trained with
|
||||
[bullet](https://github.com/jw1912/bullet) on Lc0-derived data from linrock.
|
||||
|
||||
### Run
|
||||
|
||||
How `rigby-value-v2` was trained (the 12 S2 files, see Data):
|
||||
|
||||
```
|
||||
powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\value\train.ps1
|
||||
powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\value\train.ps1 --hidden 1024 --superbatches 170 --id rigby-value-v2 --data <iter-1 file> ... --data <iter-12 file>
|
||||
```
|
||||
|
||||
Default: 40 superbatches of 100M positions, about 12 minutes on the RTX 3070
|
||||
(5.8M positions/s). Arguments are passed to the trainer:
|
||||
On the RTX 3070, 1024 hidden trains at 3-4M positions/s (bound by the GPU): about
|
||||
33 s per superbatch of 100M positions. 512 hidden runs at ~6M/s, 1536 at ~2.6M/s.
|
||||
Arguments are passed to the trainer:
|
||||
|
||||
| Argument | Default | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `--superbatches N` | 40 | Training length; the learning rate decays to the end |
|
||||
| `--hidden N` | 1024 | Hidden width; the engine's `nnue::HIDDEN` must match |
|
||||
| `--id NAME` | `rigby-value` | Checkpoint name |
|
||||
| `--data FILE` | the test80 Feb 2024 binpack | Repeatable; several files are read one after the other |
|
||||
| `--data FILE` | the test80 Feb 2024 binpack | Repeatable; files are read one after the other, round and round. All `.bin.zst`, all `.bin` or all `.binpack` |
|
||||
| `--batches N` | 6104 | Batches of 16384 per superbatch (smaller for speed tests) |
|
||||
|
||||
Output: `value/checkpoints/<id>-<superbatch>/quantised.bin` every 10 superbatches
|
||||
and at the end. That file is what the engine loads.
|
||||
|
||||
### Network format
|
||||
|
||||
`quantised.bin` (197,440 bytes for 128 hidden), little-endian `i16`:
|
||||
`quantised.bin` (1,579,072 bytes for 1024 hidden), little-endian `i16`:
|
||||
|
||||
| Part | Shape | Quantisation |
|
||||
| --- | --- | --- |
|
||||
| `l0w` | 768 x 128, feature-major (`[feature][hidden]`) | QA = 255 |
|
||||
| `l0b` | 128 | QA |
|
||||
| `l1w` | 2 x 128 (side to move first, then the other side) | QB = 64 |
|
||||
| `l0w` | 768 x H, feature-major (`[feature][hidden]`) | QA = 255 |
|
||||
| `l0b` | H | QA |
|
||||
| `l1w` | 2 x H (side to move first, then the other side) | QB = 64 |
|
||||
| `l1b` | 1 | QA * QB |
|
||||
|
||||
Inputs (bullet's `Chess768`): `64 * piece + square`, with pieces relative to the
|
||||
@@ -40,34 +45,51 @@ and squares flipped vertically for black. The side to move's accumulator comes f
|
||||
Output: `((sum screlu(acc) * w) / QA + b) * 400 / (QA * QB)` in centipawns, side to
|
||||
move. The engine maps it to Q with the same 400 scale:
|
||||
`q = 2 * sigmoid(cp / 400) - 1 = tanh(cp / 800)` (`src/nnue.cpp`, `src/eval.cpp`).
|
||||
The engine computes `screlu(v) * w` as `v * (v * w)` in 16 bits, so `|l1w|` must be
|
||||
at most 128 (bullet's AdamW clips weights to ±1.98, i.e. 127); it refuses a net
|
||||
that breaks this.
|
||||
|
||||
### Checking the engine's inference
|
||||
|
||||
```
|
||||
cargo run --release -- --check checkpoints/<id>-<superbatch>
|
||||
cargo run --release -- --check checkpoints/<id>-<superbatch> --hidden <H>
|
||||
```
|
||||
|
||||
prints bullet's own (float) evaluation of fixed positions; the engine's `evalfens`
|
||||
command prints the same positions with the quantised network. Expect agreement
|
||||
within a few centipawns (quantisation); a wrong feature mapping shows up as
|
||||
differences of hundreds.
|
||||
within a few centipawns (quantisation; v2 at superbatch 20: at most 13 cp); a
|
||||
wrong feature mapping shows up as differences of hundreds.
|
||||
|
||||
### Networks
|
||||
|
||||
| File | Data | Superbatches | Final loss |
|
||||
| --- | --- | --- | --- |
|
||||
| `networks/rigby-value-v1.bin` | test80 2024-02 | 40 (10 min) | 0.0220 |
|
||||
| File | Hidden | Data | Superbatches | Final loss |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `networks/rigby-value-v1.bin` | 128 | test80 2024-02 | 40 (10 min) | 0.0220 |
|
||||
| `networks/rigby-value-v2.bin` | 1024 | linrock S2 (6.6B positions) | 170 (TIME) | LOSS |
|
||||
|
||||
Losses are not comparable across data sets.
|
||||
|
||||
### Data
|
||||
|
||||
Lc0 self-play data converted to Stockfish binpacks by linrock
|
||||
([huggingface.co/datasets/linrock](https://huggingface.co/datasets/linrock)), here
|
||||
`test80-2024-02-feb-2tb7p.min-v2.v6.binpack` (6.9 GB zstd, 8.3 GB unpacked).
|
||||
bullet reads binpacks directly (`SfBinpackLoader`); no conversion is needed.
|
||||
The filter keeps positions from ply 16 on that are not in check, with a quiet best
|
||||
move and |score| <= 10000. Training target: `0.4 * result + 0.6 * sigmoid(score / 400)`.
|
||||
v2: the `S2` folder of
|
||||
[linrock/bullet-training-data](https://huggingface.co/datasets/linrock/bullet-training-data),
|
||||
12 files `test77nov-unfilt-test79-maraprmay-v6-dd.skip-see-ge0.wdl-pdist.iter-N.bullet.bin.zst`
|
||||
(~9 GB each, 108 GB in all; ~547M positions each, 6.6B in all, different positions
|
||||
in every file, each already filtered and shuffled). The trainer reads the `.zst`
|
||||
files directly (`value/src/zstd_reader.rs`): unpacked they would take 210 GB, and
|
||||
training only needs ~40 MB/s of compressed input, which an HDD gives easily. They
|
||||
live in `D:\rigby-data\s2\s2-1.parts\` on this machine. Hugging Face caps one connection at ~20 MB/s, so
|
||||
download several files at once.
|
||||
|
||||
Data lives in `train/data/` and is not committed.
|
||||
v1: Lc0 self-play data converted to Stockfish binpacks by linrock
|
||||
([huggingface.co/datasets/linrock](https://huggingface.co/datasets/linrock)),
|
||||
`test80-2024-02-feb-2tb7p.min-v2.v6.binpack` (6.9 GB zstd, 8.3 GB unpacked), read
|
||||
directly (`SfBinpackLoader`). The filter keeps positions from ply 16 on that are not
|
||||
in check, with a quiet best move and |score| <= 10000.
|
||||
|
||||
Training target for both: `0.4 * result + 0.6 * sigmoid(score / 400)`.
|
||||
|
||||
Data other than S2 lives in `train/data/` and is not committed.
|
||||
|
||||
### Setup on a new machine
|
||||
|
||||
@@ -75,7 +97,7 @@ Data lives in `train/data/` and is not committed.
|
||||
2. CUDA Toolkit 13.3 with `cudart`, `nvrtc`, `cublas` (bullet compiles its kernels at
|
||||
runtime with NVRTC, no nvcc needed).
|
||||
3. `git clone https://github.com/jw1912/bullet` next to this repo.
|
||||
4. `pip install zstandard` and a binpack from linrock's datasets in `train/data/`.
|
||||
4. linrock's data (see Data); `pip install zstandard` to unpack a `.binpack.zst`.
|
||||
|
||||
## Policy network (`policy/`)
|
||||
|
||||
|
||||
Reference in new issue
Block a user