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>
73 lines
3.5 KiB
PowerShell
73 lines
3.5 KiB
PowerShell
# Downloads Lc0 self-play data and converts it to montyformat for the policy trainer.
|
|
# powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\policy\fetch.ps1
|
|
# ... fetch.ps1 -From 20261025 -To 20261115 -Run test91 -Parallel 12
|
|
# Default: the last three weeks of test91 (about 40 GB of tars, 190M positions).
|
|
#
|
|
# Works one day at a time: that day's hourly tars go to data\lc0\staging, are
|
|
# converted into data\lc0\monty\<run>-<day>.binpack and deleted, so the disk
|
|
# only ever holds one day of tars. Days already converted are skipped, so an
|
|
# interrupted run can simply be started again. At the end every day file is
|
|
# shuffled into data\lc0\policy.binpack, which is what train.ps1 reads.
|
|
param(
|
|
[string] $From = (Get-Date).AddDays(-21).ToString('yyyyMMdd'),
|
|
[string] $To = (Get-Date -Format 'yyyyMMdd'),
|
|
[string] $Run = 'test91',
|
|
[int] $Parallel = 8,
|
|
[switch] $NoInterleave
|
|
)
|
|
|
|
# Native tools report through exit codes; 'Stop' would turn cargo's progress
|
|
# output on stderr into errors under Windows PowerShell.
|
|
$ErrorActionPreference = 'Continue'
|
|
Set-Location $PSScriptRoot
|
|
|
|
. .\env.ps1
|
|
cargo build --release --bins
|
|
if ($LASTEXITCODE -ne 0) { throw 'build failed' }
|
|
|
|
$base = "https://storage.lczero.org/files/training_data/$Run/"
|
|
$data = (Resolve-Path '..\data').Path
|
|
$monty = Join-Path $data 'lc0\monty'
|
|
$staging = Join-Path $data 'lc0\staging'
|
|
New-Item -ItemType Directory -Force $monty, $staging | Out-Null
|
|
|
|
# The directory listing: name, date and size of every hourly tar. Empty tars
|
|
# (10240 bytes) are hours without games.
|
|
Write-Host "Listing $base ..."
|
|
$html = (Invoke-WebRequest -UseBasicParsing $base).Content
|
|
$tars = [regex]::Matches($html, '>(training-[^<]+-(\d{8})-\d{4}\.tar)</a>\s+\S+\s+\S+\s+(\d+)') |
|
|
ForEach-Object { [pscustomobject]@{ Name = $_.Groups[1].Value; Day = $_.Groups[2].Value; Size = [long]$_.Groups[3].Value } } |
|
|
Where-Object { $_.Day -ge $From -and $_.Day -le $To -and $_.Size -gt 10240 }
|
|
$days = $tars | Group-Object Day | Sort-Object Name
|
|
$totalGb = ($tars | Measure-Object Size -Sum).Sum / 1e9
|
|
Write-Host ("{0} tars over {1} days, {2:N1} GB to download" -f $tars.Count, $days.Count, $totalGb)
|
|
|
|
foreach ($day in $days) {
|
|
$out = Join-Path $monty "$Run-$($day.Name).binpack"
|
|
if (Test-Path $out) { continue }
|
|
|
|
Get-ChildItem $staging | Remove-Item -Force
|
|
$config = Join-Path $staging 'curl.txt'
|
|
# Forward slashes: curl reads backslashes in a config file as escapes.
|
|
$day.Group | ForEach-Object { "url = `"$base$($_.Name)`"`noutput = `"$((Join-Path $staging $_.Name) -replace '\\', '/')`"" } |
|
|
Set-Content -Encoding ascii $config
|
|
$gb = ($day.Group | Measure-Object Size -Sum).Sum / 1e9
|
|
Write-Host ("{0}: downloading {1} tars ({2:N2} GB)" -f $day.Name, $day.Group.Count, $gb)
|
|
curl.exe -sSf --retry 5 -Z --parallel-max $Parallel -K $config
|
|
if ($LASTEXITCODE -ne 0) { throw "download failed for $($day.Name)" }
|
|
|
|
Remove-Item $config
|
|
& .\target\release\lc02monty.exe "$out.part" $staging --delete | Select-Object -Last 9
|
|
if ($LASTEXITCODE -ne 0) { throw "conversion failed for $($day.Name)" }
|
|
Move-Item "$out.part" $out
|
|
}
|
|
|
|
if (-not $NoInterleave) {
|
|
$policy = Join-Path $data 'lc0\policy.binpack'
|
|
Write-Host "Shuffling the day files into $policy ..."
|
|
& .\target\release\interleave.exe "$policy.part" $monty
|
|
if ($LASTEXITCODE -ne 0) { throw 'interleave failed' }
|
|
Move-Item -Force "$policy.part" $policy
|
|
Write-Host ("Done: {0:N1} GB in {1}" -f ((Get-Item $policy).Length / 1e9), $policy)
|
|
}
|