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>
69 lines
2.2 KiB
Plaintext
69 lines
2.2 KiB
Plaintext
#ifndef STUFF
|
|
#define THREADS 512
|
|
#define IN_SIZE 1024
|
|
#endif
|
|
|
|
constexpr int threads = THREADS;
|
|
constexpr int in_size = IN_SIZE;
|
|
|
|
extern "C" __global__ void kernel(
|
|
const float* weights,
|
|
const float* biases,
|
|
const float* input,
|
|
const int* moves,
|
|
float* output
|
|
) {
|
|
extern __shared__ float sdata[];
|
|
|
|
const int batch_size = gridDim.y;
|
|
const int loc_in_batch = blockIdx.y;
|
|
const int loc_in_moves = blockIdx.x;
|
|
const int tid = threadIdx.x;
|
|
const int locmb = loc_in_batch * 64 + loc_in_moves;
|
|
const int move = moves[locmb];
|
|
|
|
const float4* tW = reinterpret_cast<const float4*>(weights + in_size * move);
|
|
const float4* tI = reinterpret_cast<const float4*>(input + in_size * loc_in_batch);
|
|
|
|
if (move != -1)
|
|
{
|
|
float local = 0.0F;
|
|
|
|
#pragma unroll
|
|
for (int idx = tid; idx < in_size / 4; idx += threads)
|
|
{
|
|
const float4 tw = tW[idx];
|
|
const float4 ti = tI[idx];
|
|
local += tw.x * ti.x + tw.y * ti.y + tw.z * ti.z + tw.w * ti.w;
|
|
}
|
|
|
|
sdata[tid] = local;
|
|
__syncthreads();
|
|
|
|
if constexpr (threads >= 1024) { if (tid < 512) sdata[tid] += sdata[tid + 512]; __syncthreads(); }
|
|
if constexpr (threads >= 512) { if (tid < 256) sdata[tid] += sdata[tid + 256]; __syncthreads(); }
|
|
if constexpr (threads >= 256) { if (tid < 128) sdata[tid] += sdata[tid + 128]; __syncthreads(); }
|
|
if constexpr (threads >= 128) { if (tid < 64) sdata[tid] += sdata[tid + 64]; __syncthreads(); }
|
|
|
|
if (tid < 32)
|
|
{
|
|
float partial = sdata[tid];
|
|
if constexpr (threads >= 64) { partial += sdata[tid + 32]; }
|
|
partial += __shfl_down_sync(0xffffffff, partial, 16);
|
|
partial += __shfl_down_sync(0xffffffff, partial, 8);
|
|
partial += __shfl_down_sync(0xffffffff, partial, 4);
|
|
partial += __shfl_down_sync(0xffffffff, partial, 2);
|
|
partial += __shfl_down_sync(0xffffffff, partial, 1);
|
|
|
|
if (tid == 0)
|
|
{
|
|
output[locmb] = partial + biases[move];
|
|
}
|
|
}
|
|
}
|
|
else if (tid == 0)
|
|
{
|
|
output[locmb] = -10000.0F;
|
|
}
|
|
}
|