YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Garry MoE - Mixture of Experts Chess Engine
A chess prediction model using Mixture of Experts (MoE) architecture with domain-specialized experts trained for different Elo ranges.
Features
- 4 Expert Models: Specialized for casual, club, strong, and elite play
- Smart Routing: Perceptron router selects experts based on Elo, material, turn, time control
- 3 Inference Modes: Hard selection, soft blending, or top-K combination
- Constrained Sampling: Projects predictions onto legal chess moves
Architecture
Expert Models
- Casual Expert: Beginner to intermediate (Elo ~1000-1400)
- Club Expert: Club-level games (Elo ~1400-1800)
- Strong Expert: Tournament-level (Elo ~1800-2200)
- Elite Expert: Master-level (Elo ~2200+)
Input Format
5-channel tensor representation [8, 8, 5]:
- Piece type (0-6)
- Color (0=black, 1=white)
- Occupancy (0-1)
- Winner information
- Normalized turn number
Installation
pip install -r requirements.txt
Quick Start
from GarryMoE import ChessPredictionEngine
# Configure expert paths
expert_paths = {
'casual': 'models/casual_expert_balanced_best.pt',
'club': 'models/club_expert_balanced_best.pt',
'strong': 'models/strong_expert_balanced_best.pt',
'elite': 'models/elite_expert_balanced_best.pt'
}
router_path = 'models/router.pt'
# Initialize engine
engine = ChessPredictionEngine(
expert_paths=expert_paths,
router_path=router_path,
inference_mode='hard' # or 'soft', 'top-k'
)
# Predict next move
fen_sequence = [
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"
]
move, info = engine.predict_next_move(
fen_sequence,
elo_estimate=1500,
time_control="5+3"
)
if move:
print(f"Predicted move: {move.uci()}")
Inference Modes
- hard: Select single best expert (fastest)
- soft: Blend all 4 experts weighted by router (most accurate)
- top-k: Blend top K experts (balanced)
Model Files
Required files in models/ directory:
casual_expert_balanced_best.ptclub_expert_balanced_best.ptstrong_expert_balanced_best.ptelite_expert_balanced_best.ptrouter.pt
API Reference
ChessPredictionEngine
Main interface for predictions.
engine = ChessPredictionEngine(
expert_paths: Dict[str, str],
router_path: str,
device: Optional[torch.device] = None,
model_config: str = 'large',
inference_mode: str = 'hard',
top_k: int = 2
)
# Predict next board state
predicted_fen, info = engine.predict_next_board(
fen_sequence: List[str],
elo_estimate: Optional[float] = None,
time_control: str = ''
)
# Predict next move
move, info = engine.predict_next_move(
fen_sequence: List[str],
elo_estimate: Optional[float] = None,
time_control: str = '',
use_constrained_sampling: bool = True,
sampling_temperature: float = 1.0,
max_sampling_attempts: int = 50
)
License
MIT License
8-move CPU comparison
Garry played White on CPU at Elo 1500. Both selectors used the same forward pass.
| Move | Greedy board | Rejection sampling | Logit scoring |
|---|---|---|---|
| 1 | no legal match | Nf3 after 7 tries | Nf3 (67.8%) |
| 2 | no legal match | d4 after 11 tries | d4 (82.8%) |
| 3 | no legal match | failed after 50 tries | e4 (41.6%) |
| 4 | no legal match | Nc3 after 22 tries | Nc3 (39.0%) |
| 5 | no legal match | failed after 50 tries | Be2 (54.2%) |
| 6 | no legal match | failed after 50 tries | Be3 (46.0%) |
| 7 | no legal match | failed after 50 tries | Rf1 (74.9%) |
| 8 | no legal match | Qd2 after 29 tries | Qd2 (88.2%) |
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐ Ask for provider support