Show HN:我训练了一个国际象棋引擎,让它像人类一样下棋

3作者: hazard2 个月前
我开发了 1e4.ai - 一个国际象棋网络应用,你可以在这里与经过训练的神经网络对战,这些神经网络模仿了特定 Elo 等级的人类 Lichess 玩家。每个 100 分的等级区间(从约 800 到 2200+)都有一个单独的模型,这些机器人不仅会选择类似人类的走法,还会消耗时间,在时间压力下表现更差,并且会像人类一样犯错。<p>在线演示:<a href="https:&#x2F;&#x2F;1e4.ai" rel="nofollow">https:&#x2F;&#x2F;1e4.ai</a> 代码:<a href="https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai</a><p>一些可能有趣的事情:<p>- 基于近一年的 Lichess 快棋游戏训练,总共约 10 亿局游戏<p>- 架构是一个小型(约 900 万个参数)基于 Transformer 的网络,它将棋盘、最近的走棋历史、玩家的等级和剩余时间作为输入。每个等级区间有三个单独的模型:走棋、时间使用和胜率。时间模型使机器人在时间压力下感觉更像人类,而不是瞬间做出反应。由于走棋模型将时间作为输入参数之一,因此它也学会了像人类一样在时间压力下犯错。<p>- 由于网络非常小,推理不需要 GPU - 它可以轻松地在本地 CPU 上运行<p>- 小型网络的缺点是,当你的等级超过 1700 左右时,它会变得有点弱。它可以发现短期的战术,但不能发现长期的多步组合。<p>- 最初在租用的 8xH100 集群上进行训练,然后在我的本地 GPU 上针对不同的等级范围进行微调<p>- 灵感来自 Maia-2 和 DeepMind 的“无需搜索的大师级国际象棋”。在 Lichess 快棋基准测试中,它在最佳走棋预测(56.7% vs 52.7%)和胜率校准(Brier 0.176 vs 0.272)方面明显优于 Maia-2 快棋。数字和代码在 <a href="https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai&#x2F;tree&#x2F;master&#x2F;experiments&#x2F;maia2_benchmark" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai&#x2F;tree&#x2F;master&#x2F;experiments&#x2F;...</a><p>- 数据管道是 C++ 通过 nanobind,然后用 Pytorch 进行训练。实际上,我在这方面花费了最多的时间。预先打乱数据集,然后在训练时能够顺序读取打乱后的数据集,保持了 GPU 的高利用率。如果没有这样做,它会花费大量时间在 I/O 上,而 GPU 却闲置着。<p>很乐意回答关于等级条件、时间模型或数据管道的问题。
查看原文
I built 1e4.ai - a chess web app where you play against neural networks trained to mimic human Lichess players at specific Elo ranges. There&#x27;s a separate model for each 100-point rating bucket from ~800 to 2200+, and the bots not only choose human-like moves but also burn clock time, play worse under time pressure, and blunder in human-like ways.<p>Live demo: <a href="https:&#x2F;&#x2F;1e4.ai" rel="nofollow">https:&#x2F;&#x2F;1e4.ai</a> Code: <a href="https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai</a><p>A few things that might be interesting:<p>- Trained on almost a full year of Lichess blitz games, around 1B total games<p>- Architecture is an a small (~9MM parameters) transformer-based network that takes the board, recent move history, the player&#x27;s rating, and remaining clock time as input. Three separate models per rating bucket: move, clock-usage, and win probability. The clock model is what makes the bots feel humanish under time pressure rather than instant. Because the move model takes the clock as one input parameter, it also learns to blunder under time pressure like a human might.<p>- Because the network is so tiny, no GPU is needed for inference - it runs easily on a local CPU<p>- Downside of the tiny network is that it&#x27;s a bit weak as you turn up the rating past around 1700. It can spot short tactics but not long multi-move combinations.<p>- Initial training on a rented 8xH100 cluster, then fine-tunes on my local GPU for different rating ranges<p>- Inspired by Maia-2 and DeepMind&#x27;s &quot;Grandmaster-Level Chess Without Search&quot;. On a held-out Lichess blitz benchmark, the it beats Maia-2 blitz on top-1 move prediction (56.7% vs 52.7%) and pretty substantially on win-probability calibration (Brier 0.176 vs 0.272). Numbers and code in <a href="https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai&#x2F;tree&#x2F;master&#x2F;experiments&#x2F;maia2_benchmark" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thomasj02&#x2F;1e4_ai&#x2F;tree&#x2F;master&#x2F;experiments&#x2F;...</a><p>- The data pipeline is C++ via nanobind, then training with Pytorch. Getting this right was actually the thing I spent the most time on. Pre-shuffling the dataset and then being able to read the shuffled dataset sequentially at training time kept the GPU utilization high. Without this it spent a huge percentage of time on I&#x2F;O while the GPU sat idle.<p>Happy to answer questions about the rating-conditioning, the clock model, or the data pipeline.