ParallaxOpen commited on
Commit
912e0dd
·
verified ·
1 Parent(s): 5032660

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +56 -50
README.md CHANGED
@@ -7,90 +7,96 @@ tags:
7
  - transformer
8
  - from-scratch
9
  - small-model
 
10
  ---
11
 
12
  # Parallax-Chess-Preview
13
 
14
- A chess move prediction engine trained from scratch on a single laptop GPU. Predicts the best move given a board position using a custom chess tokenizer and a 4.4M parameter transformer.
15
 
16
- ## How It Works
17
 
18
- Unlike traditional chess engines (Stockfish, Leela), Parallax-Chess-Preview uses **pure neural network evaluation** — no hand-crafted rules, no opening books, no endgame tables. It learned chess purely from 50,000 Lichess puzzles.
 
 
 
 
 
19
 
20
- - **Custom chess tokenizer**: Board positions encoded as 66 tokens (64 squares + side-to-move + separator), moves encoded as (from-square, to-square) pairs. Total vocab: 402 tokens.
21
- - **Architecture**: Transformer decoder (6 layers, 256 dim, 4 heads, GQA 4:2)
22
- - **Training**: 100K steps on 50K Lichess puzzles, final loss 0.088
23
-
24
- ## Benchmarks
25
 
26
  | Metric | Value |
27
  |--------|-------|
28
- | Legal move rate | 100% |
29
- | Speed | 6 moves/sec (CPU) |
30
- | Estimated ELO | ~700 |
31
- | vs Stockfish (max) | 0-1 (W), 1-0 (B, blunder) |
32
- | Training data | 50K Lichess puzzles |
33
- | Training time | ~1 hour on RTX 5060 |
 
 
34
 
35
  ## Quick Start
36
 
 
37
  ```python
 
38
  import chess
39
- from vela_chess_engine import VelaChessV2
40
 
41
- engine = VelaChessV2("model.safetensors", "chess_encoding.py")
42
  board = chess.Board()
43
- move = engine.choose_move(board)
44
- print(move.uci()) # e.g. "g1f3"
45
  ```
46
 
47
- ## Interactive Play
 
 
48
 
49
- ```bash
50
- python play.py
 
 
51
  ```
52
 
53
- Then type moves in UCI format (e.g. `e2e4`).
 
 
 
 
54
 
55
- ## Architecture Details
56
 
57
  ```
58
- SmallLMConfig(
59
- vocab_size=402, # Custom chess vocabulary
60
- d_model=256, # Embedding dimension
61
- n_heads=4, # Attention heads
62
- n_kv_heads=2, # GQA grouped query attention
63
- n_layers=6, # Transformer layers
64
- intermediate_size=1024,
65
- max_seq_len=128,
66
- norm_type='rms',
67
- rope_theta=10000.0,
68
  )
69
  ```
70
 
71
- ## Training Data
72
-
73
- 50,000 chess puzzles from the [Lichess puzzle database](https://database.lichess.org/#puzzles), filtered to ratings 800-2500 with 2-6 move solutions.
74
 
75
- ## Limitations
76
-
77
- - **~700 ELO** — plays at beginner level
78
- - No search tree — purely neural move prediction
79
- - Trained on puzzle data only (not full games)
80
- - Cannot play from arbitrary positions outside training distribution
81
 
82
  ## What This Proves
83
 
84
- Even a tiny 4.4M parameter model can:
85
- - Learn legal chess move patterns from data alone
86
- - Achieve 100% legal move rate
87
- - Make occasionally reasonable opening choices (Nf3, Nc3)
88
- - Be trained from scratch in 1 hour on a laptop GPU
89
 
90
- ## Hardware
91
 
92
- - **Training**: Single RTX 5060 Laptop GPU (8GB VRAM)
93
- - **Inference**: CPU-only, ~6 moves/sec
 
 
94
 
95
  ## License
96
 
 
7
  - transformer
8
  - from-scratch
9
  - small-model
10
+ - mcts
11
  ---
12
 
13
  # Parallax-Chess-Preview
14
 
15
+ A chess engine trained from scratch on a single laptop GPU (RTX 5060). Uses a 25.9M parameter transformer with Monte Carlo Tree Search (MCTS) for move selection.
16
 
17
+ ## What's Inside
18
 
19
+ - **25.9M param transformer** trained on 200K+ positions with Stockfish evaluations
20
+ - **Policy network**: predicts best move from board state (4352-class output covering all possible moves)
21
+ - **Value network**: evaluates positions in centipawns (trained on Stockfish depth-10 evaluations)
22
+ - **MCTS search**: looks ahead multiple moves using the neural network for evaluation
23
+ - **Custom chess tokenizer**: no external tokenizer needed — pure chess-aware encoding
24
+ - **Tkinter GUI**: interactive chess board with click-to-move interface
25
 
26
+ ## Performance
 
 
 
 
27
 
28
  | Metric | Value |
29
  |--------|-------|
30
+ | Parameters | 25.9M |
31
+ | Training data | 200K Stockfish-evaluated positions + 143K puzzles |
32
+ | Training time | ~2 hours on RTX 5060 |
33
+ | Policy loss | 8.47 → 2.50 (4352-class prediction) |
34
+ | Speed (greedy) | ~19 moves/sec |
35
+ | Speed (MCTS 200 sims) | ~2 moves/sec |
36
+ | Estimated ELO | ~800-1000 (greedy), ~1200-1500 (MCTS) |
37
+ | Opens with | e2e4, Nf3, Ruy Lopez — real chess openings |
38
 
39
  ## Quick Start
40
 
41
+ ### Greedy (fast, weaker)
42
  ```python
43
+ from train_v3 import ParallaxChessV3
44
  import chess
 
45
 
46
+ model = ParallaxChessV3.load("model.pt")
47
  board = chess.Board()
48
+ move = model.predict_move(board)
49
+ print(move.uci()) # e.g. "e2e4"
50
  ```
51
 
52
+ ### MCTS Search (slower, stronger)
53
+ ```python
54
+ from mcts_engine import ParallaxChessMCTS
55
 
56
+ engine = ParallaxChessMCTS("model.safetensors")
57
+ board = chess.Board()
58
+ move = engine.choose_move(board, n_simulations=200)
59
+ print(move.uci())
60
  ```
61
 
62
+ ### Interactive GUI
63
+ ```bash
64
+ python play_gui.py
65
+ ```
66
+ Click pieces to select, click again to move. Legal moves shown as dots.
67
 
68
+ ## Architecture
69
 
70
  ```
71
+ ParallaxChessV3(
72
+ board_encoder: Embedding(402, 512),
73
+ backbone: SmallLM(8 layers, 512 dim, 8 heads, GQA 4:2),
74
+ policy_head: Linear(512, 4352), # from_sq * 64 + to_sq
75
+ value_head: Linear(512, 256) → Linear(256, 1) → Tanh
 
 
 
 
 
76
  )
77
  ```
78
 
79
+ ## Training Details
 
 
80
 
81
+ 1. **Data**: 200K positions from Stockfish self-play (depth 10) + 143K Lichess puzzles
82
+ 2. **Policy target**: Stockfish best move as move index (from_square × 64 + to_square)
83
+ 3. **Value target**: Stockfish centipawn evaluation (scaled to [-1, 1])
84
+ 4. **Optimizer**: AdamW (lr=1e-3, weight_decay=0.01, cosine schedule)
85
+ 5. **Augmentation**: 50% horizontal board flip
 
86
 
87
  ## What This Proves
88
 
89
+ - A 25.9M param model can learn real chess openings from scratch
90
+ - Policy + value heads can be trained simultaneously on a single GPU
91
+ - MCTS search can boost a weak neural player to competitive play
92
+ - Custom chess encoding (no tokenizer dependency) works well
 
93
 
94
+ ## Limitations
95
 
96
+ - ~1000-1500 ELO (intermediate club player)
97
+ - Weak in endgames (training data biased toward openings/middlegame)
98
+ - No opening book — learns openings from training data only
99
+ - MCTS adds ~10x latency per move
100
 
101
  ## License
102