Skip to content

Implement self-play training data generation - #327

Merged
kirillbobyrev merged 1 commit into
mainfrom
claude/codebase-review-0hfehw
Jul 21, 2026
Merged

Implement self-play training data generation#327
kirillbobyrev merged 1 commit into
mainfrom
claude/codebase-review-0hfehw

Conversation

@kirillbobyrev

Copy link
Copy Markdown
Owner

Summary

Third in the sequence (after #325, #326). Turns the empty datagen stub into a working self-play data generator built on the unified Game — the data source a future policy/value network will train on.

Changes

  • Self-play driven by MCTS. Each game is played by the search; at every move the search's visit distribution over the legal moves is recorded as the policy target, and the game's eventual outcome (from the side-to-move's perspective) is the value target. Opening plies are sampled proportionally to the visit counts for variety; later moves are greedy.
  • Parallel + reproducible. Games are independent and generated in parallel with rayon; each game is seeded from seed ^ index, so a run is deterministic regardless of scheduling. An optional Syzygy tablebase adjudicates endgames.
  • Output. Samples are written as <fen> | <value> | <uci>:<visits> .... The datagen binary exposes --games / --nodes / --exploration-plies / --max-plies / --seed / --tablebase / --output via clap.
  • Search plumbing. Exposed the root visit distribution from the search as mcts::policy — the policy target — reusing the existing SearchResult.

Testing

  • 73 lib tests (3 new datagen tests: well-formed output, reproducibility, and value-target orientation — a mate-in-one self-play game yields +1 for the winning side); full suite (137 total) green.
  • Manual: cargo run --bin datagen -- --games 4 --nodes 80 --output … produces 240 well-formed samples.
  • cargo clippy --all-targets --all-features zero warnings; cargo +nightly fmt --check clean.

Next in the sequence

UCI-completeness pass, then the transmute safety cleanup. (The network itself — consuming this data — remains the larger future effort.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk


Generated by Claude Code

datagen was an empty stub. Build it on the unified Game:

- Self-play games are played by the MCTS search: at each move the search's
  visit distribution over the legal moves is recorded as the policy target,
  and the game's eventual outcome (from the side-to-move's perspective)
  becomes the value target. Opening plies are sampled proportionally to the
  visits for variety; later moves are greedy.
- Games are independent and generated in parallel with rayon; each game is
  seeded from seed ^ index, so a run is fully reproducible regardless of
  scheduling. An optional Syzygy tablebase adjudicates endgames.
- Samples are written as '<fen> | <value> | <uci>:<visits> ...'. The
  datagen binary exposes games / nodes / exploration / seed / tablebase /
  output via clap.
- Expose the root visit distribution from the search (mcts::policy) as the
  policy target.

Tests: well-formed output, reproducibility, and value-target orientation
(a mate-in-one self-play game yields a +1 value for the winning side).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk
@kirillbobyrev
kirillbobyrev marked this pull request as ready for review July 21, 2026 03:42
@kirillbobyrev
kirillbobyrev merged commit e249d11 into main Jul 21, 2026
13 checks passed
@kirillbobyrev
kirillbobyrev deleted the claude/codebase-review-0hfehw branch July 21, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants