Upload README.md with huggingface_hub
Browse files
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
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 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 |
-
|
|
| 29 |
-
|
|
| 30 |
-
|
|
| 31 |
-
|
|
| 32 |
-
|
|
| 33 |
-
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
## Quick Start
|
| 36 |
|
|
|
|
| 37 |
```python
|
|
|
|
| 38 |
import chess
|
| 39 |
-
from vela_chess_engine import VelaChessV2
|
| 40 |
|
| 41 |
-
|
| 42 |
board = chess.Board()
|
| 43 |
-
move =
|
| 44 |
-
print(move.uci()) # e.g. "
|
| 45 |
```
|
| 46 |
|
| 47 |
-
##
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
```
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
## Architecture
|
| 56 |
|
| 57 |
```
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 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
|
| 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 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
- Cannot play from arbitrary positions outside training distribution
|
| 81 |
|
| 82 |
## What This Proves
|
| 83 |
|
| 84 |
-
|
| 85 |
-
-
|
| 86 |
-
-
|
| 87 |
-
-
|
| 88 |
-
- Be trained from scratch in 1 hour on a laptop GPU
|
| 89 |
|
| 90 |
-
##
|
| 91 |
|
| 92 |
-
-
|
| 93 |
-
-
|
|
|
|
|
|
|
| 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 |
|