mac-alpha-zero
AlphaZero-style self-play training that runs end to end on your Mac.
mac-alpha-zero is a game-agnostic library for batched Monte Carlo Tree Search and Gumbel AlphaZero–style training, built on MLX for Apple Silicon.
After two hours of self-play on an M5, the agent (black) beat Edax level 1 36–28 in this game. After six random opening moves, the agent used 32 search simulations per move. Game record · 100-game results
The released agent is a separate run with the same settings, trained for one night (8 hours). Play it in your terminal on an Apple Silicon Mac with uv:
uvx mac-alpha-zero play othello
Status: alpha. Self-play training runs end to end for Connect4 and Othello, and the Othello agent is measured against Edax as it trains. v0.1.2 includes the Othello weights from one night of training. Play the agent in your terminal. The API is still evolving. Milestones and every measurement so far are in ROADMAP.md.
Install the Python library
On an Apple Silicon Mac, install mac-alpha-zero from PyPI in your project's Python environment.
python -m pip install mac-alpha-zero
With uv, run uv add mac-alpha-zero. Import the package as mac_alpha_zero:
from mac_alpha_zero import games
game = games.Othello()
Quickstart
On an Apple Silicon Mac with uv:
git clone https://github.com/natsu0529/mac-alpha-zero.git
cd mac-alpha-zero
uv run python examples/train_connect4.py --minutes 10
This trains a Connect4 agent from scratch and prints, every few iterations, how it fares against a random player and against rollout MCTS, with and without search.
For Othello, build Edax once so the agent is scored against it while training:
scripts/build_edax.sh
uv run python examples/train_othello.py --minutes 60
uv run python examples/train_othello.py --minutes 60 --resume # continue the same run
Weights, the replay buffer and a score log go to checkpoints/.
Play the pretrained Othello agent
To play the released agent on an Apple Silicon Mac, run:
uvx mac-alpha-zero play othello
On first use, this downloads the 1.25 MB v0.1.2 weights to ~/.cache/mac-alpha-zero/ and checks their SHA-256. They come from the 8-hour run. Version 0.1.1 played the two-hour weights from the game above, which stay on the v0.1.0 release. After pip install mac-alpha-zero, the same command is mac-alpha-zero play othello.
You play black (X). Enter a listed square such as d3, or q to quit. Pass --color white to let the agent open and --simulations to change its search budget. To play your own trained agent, pass its checkpoint path, for example mac-alpha-zero play othello checkpoints/othello.safetensors. Both the play and benchmark commands accept --channels and --blocks for custom network shapes.
To reproduce the published matches against Edax 4.6 levels 4 and 5, download and check the weights from the cloned repository, build Edax and run:
mkdir -p checkpoints/v0.1.2
curl -fL https://github.com/natsu0529/mac-alpha-zero/releases/download/v0.1.2/othello.safetensors -o checkpoints/v0.1.2/othello.safetensors &&
echo '490a771beb54fc5f3e7aa832ce61a78863721e3b6baa00ef6434a680a37ef993 checkpoints/v0.1.2/othello.safetensors' | shasum -a 256 -c -
scripts/build_edax.sh
uv run python benchmarks/edax_match.py --checkpoint checkpoints/v0.1.2/othello.safetensors --search-only --levels 4 5 --games 100 --seed 0 --opening-plies 6 --simulations 512
With 50 openings played once per color and 512 simulations per move, the agent scored 0.735 against level 4 (72 wins, three draws, 25 losses) and 0.555 against level 5 (55-1-44). It uses a 4-block, 64-channel network and PUCT below the Gumbel root. The two-hour v0.1.0 weights scored 0.905 against level 1 at 32 simulations (--levels 1 --simulations 32).
Results so far
Apple M5, 24 GB, MLX 0.32.4. One run per configuration; details and caveats in ROADMAP.md.
Search speed with a network (Connect4, random 64-channel 4-block ResNet at every leaf, 64 simulations, measured 2026-11-27), simulations per second:
| Batch |
mac-alpha-zero, Metal kernels (GPU) |
mac-alpha-zero, pure MLX (GPU) |
mctx, JAX 0.12.1 (CPU) |
mctx, jax-metal 0.1.1 (GPU) |
| 1 |
1,532 |
602 |
8,258 |
838 |
| 64 |
54,096 |
29,187 |
23,749 |
14,870 |
| 256 |
74,855 |
57,436 |
26,367 |
17,435 |
| 1,024 |
79,804 |
73,366 |
25,018 |
18,273 |
| 4,096 |
61,374 |
59,699 |
24,487 |
Did not finish |
- GPU against CPU: from batch 64 up, the Metal kernels are 2.3–3.2× faster than mctx on the CPU. At batch 1 they are 5.4× slower.
- GPU against GPU: at batches 64–1,024 they are 3.6–4.4× faster than mctx on the Mac GPU. Experimental jax-metal requires JAX 0.4.34 and mctx 0.0.5, and it stopped responding at batch 4,096.
- Kernels against pure MLX: on the same GPU, with the same visit counts, the fused kernels are 1.85× faster at batch 64 and 1.03× faster at 4,096. At large batches, network inference takes almost all of the time.
Othello after two hours of training from scratch. With board-symmetry augmentation and 32 search simulations per move, the agent won 90 games, drew one and lost nine against Edax 4.6 level 1. Each cell below is the score over 100 games from 50 six-ply openings played once per color. A draw counts as half a point.
| Agent |
Edax level 1 |
Edax level 2 |
| Random |
0.020 |
0.000 |
| Network, policy only |
0.715 |
0.270 |
| Network + Gumbel search, 32 sims |
0.905 |
0.605 |
| Network + Gumbel search, 128 sims |
0.990 |
0.820 |
| Network + Gumbel search, 512 sims |
1.000 |
0.960 |
The curve uses 64 games per opponent and 32 simulations per move at each evaluation. Elo is fitted to those results with Edax level 1 fixed at zero. The horizontal axis counts self-play and optimization. Including evaluation and checkpoint writes, training took 2 h 29 min. The training process peaked at 1.692 GiB on the 24 GB M5.
After building Edax as shown in the quickstart, reproduce the training run and final matches with:
uv run python examples/train_othello.py --minutes 120 --symmetries --seed 0 --save-eval-weights --checkpoint checkpoints/sym.safetensors
uv run python benchmarks/edax_match.py --checkpoint checkpoints/sym.safetensors --games 100 --seed 0 --opening-plies 6 --levels 1 2 --simulations 32 128 512
Regenerate the figure from the evaluation log:
uv run python benchmarks/checkpoint_elo.py benchmarks/data/othello/sym-2h.log.jsonl > /tmp/othello-elo.jsonl
uv run --group media python benchmarks/plot_strength.py benchmarks/data/othello/sym-2h.log.jsonl docs/othello-sym-strength.png --ratings /tmp/othello-elo.jsonl
The full comparison includes the first run without symmetry augmentation and a second symmetry-augmented run with a decaying learning rate. It also includes a rerun without augmentation on an awake Mac and a second seed with symmetries. The second seed scored 0.910 against level 1 and 0.765 against level 2 at 32 simulations.
One night of training. The same settings trained for 8 hours (313,084 self-play games, 1.708 GiB peak). Against Edax 4.6, 100 games per cell on the same openings:
| Agent |
Level 3 |
Level 4 |
Level 5 |
| 2 hours, search, 512 sims |
0.870 |
0.625 |
0.480 |
| 8 hours, search, 32 sims |
0.570 |
0.300 |
0.140 |
| 8 hours, search, 512 sims |
0.880 |
0.735 |
0.555 |
On a second set of openings the 8-hour agent scored 0.900 / 0.735 / 0.590 at 512 simulations. Strength stopped improving after about five hours. The strength curve, all budgets and the reproduction commands are in ROADMAP.md.
Why
- There is no MCTS / AlphaZero library for MLX. mctx is excellent but built on JAX, whose Mac GPU support is experimental. PyTorch-based frameworks aren't tuned for Apple Silicon.
- Unified memory changes the trade-offs. On a Mac, game rules, tree search, and network inference share one memory pool. Work that suits the CPU (like chess move generation) can feed the GPU without copies.
- Compute efficiency is the interesting question. We don't try to out-muscle Lc0 or KataGo. We measure how much playing strength each GPU-hour on a single Mac buys, and push that number up.
Features
Working now:
- Batched MCTS with fixed-shape tree arrays: thousands of games searched in parallel.
- PUCT and Gumbel root selection (strong policy improvement at low simulation counts).
- Fused Metal kernels for tree descent and backup.
- Self-play, replay buffer, training loop with resume, and arena matches against fixed opponents (random, rollout MCTS, Edax).
- Anchored Elo ratings from Othello evaluation logs and optional matches between saved checkpoints.
- A small environment interface: bring your own game by supplying batched rules and an observation encoding.
Planned:
Games
The core is game-agnostic. Each game has its own rules, network config, and trained weights.
| Game |
Approach |
Status |
| Connect4 |
Internal test environment, checked against a solver |
Trains end to end |
| Othello |
Trained from scratch, evaluated against Edax |
Scored 0.905 against Edax level 1 at 32 simulations per move |
| Chess |
Pretrained on public data, fine-tuned by self-play |
v0.2 |
| 9×9 Go |
Trained by self-play, evaluated against GNU Go / KataGo |
v0.3 |
Requirements
- Apple Silicon Mac (developed on an M5 with 24 GB)
- macOS with Python 3.10+ and MLX 0.32.4+ (
uv installs both)
Both 10-minute quickstarts completed and saved weights on the M5 with 24 GB (macOS 26.6.2, MLX 0.32.4, Metal kernels enabled, Edax installed). Elapsed time includes evaluation and saving. Self-play throughput counts time generating samples. Peak memory is the Python process footprint reported by macOS over the full command.
| Quickstart |
Elapsed (min:sec) |
Self-play games/s |
Peak memory footprint |
| Connect4 |
37:28 |
59.51 |
1,379,435,552 bytes (1.285 GiB) |
| Othello |
14:55 |
17.52 |
1,813,103,552 bytes (1.689 GiB) |
The minimum supported memory is still unverified. Help document support for other Macs by reporting a quickstart result.
Contributing
See CONTRIBUTING.md for setup, tests, and benchmarks. Issues and discussion about the API and the roadmap are welcome.
License
MIT — do whatever you want, just keep the notice.