train/policy is a fork of montytrain's policy trainer (the one Monty, Vine and Jackal use: bullet at a pinned revision plus two CUDA operations, SelectAffine over the legal moves' output rows and a softmax cross-entropy against the visit distribution). Rigby's version drops Monty's SEE split of the outputs (3920 rows, as in Vine), takes its arguments on the command line and checks a checkpoint with --check. The Stockfish binpacks used for the value net only keep the played move, so the data comes from Lc0's raw V6 training tars instead. lc02monty rebuilds each game from its first record and the played moves and checks every record: pieces must match, and the moves Lc0 gave a probability must be exactly the legal moves. Lc0 writes castling as king-takes-rook; Chess960 games keep their rook files. On a test91 tar all 351,454 records convert. fetch.ps1 downloads a run's hourly tars day by day, converts and deletes them, and interleave shuffles the day files into one. Defaults sized for a 20-minute run on the RTX 3070: 1024 hidden, 10 superbatches of 100M positions (~1M positions/s). The pinned cudarc does not know CUDA 13.3, so env.ps1 sets CUDARC_CUDA_VERSION=13000. Checked: a smoke run on one tar lowers the loss from 2.89 to 2.38 and gives plausible opening priors; a checkpoint reloads to identical output; interleaved data trains. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
3.1 KiB
Rust
112 lines
3.1 KiB
Rust
//! Shuffles montyformat files into one, game by game, picking each next game
|
|
//! from a file chosen in proportion to the bytes it has left.
|
|
//!
|
|
//! interleave <out.binpack> <file or directory of .binpack files>...
|
|
|
|
use std::{
|
|
fs::{self, File},
|
|
io::{BufReader, BufWriter, Write},
|
|
};
|
|
|
|
use montyformat::{FastDeserialise, MontyFormat};
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let mut args = std::env::args().skip(1);
|
|
let output = args.next().expect("usage: interleave <out> <file|dir>...");
|
|
let mut inputs: Vec<String> = Vec::new();
|
|
for arg in args {
|
|
let path = std::path::Path::new(&arg);
|
|
if path.is_dir() {
|
|
let mut files: Vec<String> = fs::read_dir(path)?
|
|
.filter_map(|e| e.ok().map(|e| e.path()))
|
|
.filter(|p| p.is_file() && p.extension().and_then(|e| e.to_str()) == Some("binpack"))
|
|
.map(|p| p.to_string_lossy().into_owned())
|
|
.collect();
|
|
files.sort();
|
|
inputs.extend(files);
|
|
} else {
|
|
inputs.push(arg);
|
|
}
|
|
}
|
|
assert!(!inputs.is_empty(), "no input files");
|
|
assert!(!inputs.contains(&output), "the output must not be one of the inputs");
|
|
|
|
println!("Writing to {output:#?}");
|
|
println!("Reading from:\n{inputs:#?}");
|
|
let mut streams = Vec::new();
|
|
let mut total = 0;
|
|
|
|
let target = File::create(&output)?;
|
|
let mut writer = BufWriter::new(target);
|
|
|
|
for path in &inputs {
|
|
let file = File::open(path)?;
|
|
|
|
let count = file.metadata()?.len();
|
|
|
|
if count > 0 {
|
|
streams.push((count, BufReader::new(file)));
|
|
total += count;
|
|
}
|
|
}
|
|
|
|
let mut remaining = total;
|
|
let mut rng = RandU64::default();
|
|
|
|
const INTERVAL: u64 = 1024 * 1024 * 256;
|
|
let mut prev = remaining / INTERVAL;
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
while remaining > 0 {
|
|
let mut spot = rng.rand() % remaining;
|
|
let mut idx = 0;
|
|
while streams[idx].0 < spot {
|
|
spot -= streams[idx].0;
|
|
idx += 1;
|
|
}
|
|
|
|
let (count, reader) = &mut streams[idx];
|
|
|
|
MontyFormat::deserialise_fast_into_buffer(reader, &mut buffer)?;
|
|
writer.write_all(&buffer)?;
|
|
|
|
let size = buffer.len() as u64;
|
|
|
|
remaining -= size;
|
|
*count -= size;
|
|
if *count == 0 {
|
|
streams.swap_remove(idx);
|
|
}
|
|
|
|
if remaining / INTERVAL < prev {
|
|
prev = remaining / INTERVAL;
|
|
let written = total - remaining;
|
|
print!("Written {written}/{total} Bytes ({:.2}%)\r", written as f64 / total as f64 * 100.0);
|
|
let _ = std::io::stdout().flush();
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
struct RandU64(u64);
|
|
|
|
impl Default for RandU64 {
|
|
fn default() -> Self {
|
|
Self(
|
|
(std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("valid").as_nanos()
|
|
& 0xFFFF_FFFF_FFFF_FFFF) as u64,
|
|
)
|
|
}
|
|
}
|
|
|
|
impl RandU64 {
|
|
fn rand(&mut self) -> u64 {
|
|
self.0 ^= self.0 << 13;
|
|
self.0 ^= self.0 >> 7;
|
|
self.0 ^= self.0 << 17;
|
|
self.0
|
|
}
|
|
}
|