Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / games / chess / src / main / assets / README.md

README.md3.2 KiBRenderedCodeRaw
1# `maia3-5m.maml`
2
3Maia3-5M, the chess AI. Converted from **[`UofTCSSLab/Maia3-5M`](https://huggingface.co/UofTCSSLab/Maia3-5M)**
4(`maia3-5m.pt`, 20.0 MB fp32) to 6.8 MiB of int8.
5
6Rebuild it byte for byte with:
7
8 python scripts/ml/fetch_maia.py
9
10which pins the upstream revision and the checkpoint's SHA-256, asserts the parameter inventory,
11and writes this file. Committed rather than gitignored, for the same reason `:speech`'s voice
12bundle is: a fresh checkout that silently ships a chess app with no opponent is worse than the
13history.
14
15## What it is
16
17An encoder-only transformer over 64 square tokens — width 256, 8 blocks, 8 heads, 5,230,084
18parameters. Upstream calls the architecture "Chessformer"; the code is
19[CSSLab/maia3](https://github.com/CSSLab/maia3).
20
21It **predicts human moves** rather than searching for good ones. One forward pass per move, no
22tree. Strength is a model input (`SelfElo` / `OppoElo`, 0..5000), so this one file covers all
23four difficulty levels — see `Difficulty` in
24`games/chess/src/main/java/com/vayunmathur/games/chess/util/MaiaEngine.kt`.
25
26It replaces Stockfish and its 86 MB `nn-71d6d32cb962.nnue`, which is where the APK's ~79 MB
27reduction comes from. It also removed the last personal JitPack fork from the tree; see
28`SUPPLY_CHAIN_RISKS.md`.
29
30## Precision
31
32Every `1x1` convolution is int8, quantised per output channel; the norms, the biases and the
33two elo embeddings stay fp16 and are 1% of the parameters. Worst per-tensor correlation against
34fp32 is 0.999941.
35
36That was chosen on **move agreement**, not on the cosine gate, because a cosine says nothing
37about whether the model still picks the same move:
38
39| | size | move agreement vs fp32 | disagreements wider than fp16 rounding |
40|---|---|---|---|
41| fp16 | 13.3 MiB | — | — |
42| **int8, per channel** | **6.8 MiB** | **99.0–99.5%** | **0** |
43| int4, per 16 | 4.2 MiB | 91.2% | 14 |
44| int4, per channel | 3.5 MiB | 88.0% | 29 |
45
46int4 is rejected: its disagreements are the model changing its mind, not losing a coin flip,
47and sub-row grouping gives back most of the saving without fixing it. 5.2M parameters have no
48redundancy to spare. Re-measure any of this with `python scripts/ml/maia_quant_eval.py`.
49
50## How it is checked
51
52* `scripts/ml/test/test_maia.py` — the converter's tensor order, the int8 triple, and the two
53 structural rewrites (the fused q/k/v split, the eight-fold attention-bias replication),
54 against a toy model.
55* `scripts/ml/maia_parity.py` — the real weights through the Rust interpreter against the
56 PyTorch reference, over `maia_parity_fixture.json`. Agreement on the best **legal** move as
57 well as on the numbers, because a wrong board encoding still plays legal chess.
58* `scripts/ml/maia_quant_eval.py` — what the quantisation costs, in moves, over hundreds of
59 positions at every shipping rating.
60* `MaiaEncodingTest` in `src/test/` — the board planes, the move vocabulary and perft.
61
62The forward pass is `library/ml/src/main/rust/src/nets/maia.rs`, which documents the parts that
63fail silently: the post-norm block order, the RMS norms, and why the attention bias is a grouped
64convolution.
65
66## Licence
67
68Maia3's weights are released by the University of Toronto's Computational Social Science Lab.
69See the model card at the link above for terms.