# 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\-.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)\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) }