Google Compute Engine の高速な GPU を利用して、Leela Zero/Lizzie を快適に使う方法の手順書です。
- その1 Google Compute Engine 設定編
- その2 Leela Zero インストール編
- その3 Lizzie 導入編(Mac/Linux対応版) / Lizzie 導入編(Windows 10 対応版)
※ 執筆時点(2018年11月)の Leela Zero のバージョンは 0.16, Lizzie のバージョンは 0.6 です。
- 2019年4月に、Leela Zero バージョン 0.17 で同様に動作することを確認しています。
Leela Zero をインストールするための準備
仮想マシンにログインする
VM インスタンスの画面から、SSH をクリックします。

新しいウインドウが開き、しばらく待つと SSH の画面が現れます。
このページのこれより先は、SSH で接続した VM のターミナル上での作業となります。
はじめに起動すると、NVIDIA のドライバをインストールするかどうか聞かれますので、y を押してリターン。

(仮想マシンの再起動が要求されることもあるので、その場合は30秒ほどまって再接続してください。)
Leela Zero のビルド
VM 上で次のコマンドを打ち込んで、Leela Zero をビルドします。(コピペすれば OK)
うまくいくと、~/leela-zero/build/leelaz に Leela Zero のプログラムができあがります。
sudo apt -y install clinfo && clinfo && sudo apt install -y cmake g++ libboost-dev libboost-program-options-dev libboost-filesystem-dev opencl-headers ocl-icd-libopencl1 ocl-icd-opencl-dev zlib1g-dev && git clone https://github.com/gcp/leela-zero && cd leela-zero&&git submodule update --init --recursive&&mkdir build && cd build && cmake .. && cmake --build . && ./tests
↑をわかりやすく分解したもの
# OpenCL をチェック
sudo apt install clinfo && clinfo
# ビルドに必要なライブラリやソフトウェアを導入
sudo apt install -y cmake g++ libboost-dev libboost-program-options-dev libboost-filesystem-dev opencl-headers ocl-icd-libopencl1 ocl-icd-opencl-dev zlib1g-dev
# Leela Zero のソースコード github から Clone。依存するライブラリを配備。
git clone https://github.com/gcp/leela-zero
cd leela-zero
git submodule update --init --recursive
# build ディレクトリをつくって、その中でビルド
mkdir build && cd build
cmake ..
cmake --build .
./tests
末尾の ./tests コマンドの成功例
$ ./tests
Running main() from gtest_main.cc
[==========] Running 11 tests from 2 test cases.
[----------] Global test environment set-up.
BLAS Core: built-in Eigen 3.3.5 library.
Detecting residual layers...v1...8 channels...1 blocks.
Initializing OpenCL (autodetecting precision).
Detected 1 OpenCL platforms.
Platform version: OpenCL 1.2 CUDA 10.0.182
Platform profile: FULL_PROFILE
Platform name: NVIDIA CUDA
Platform vendor: NVIDIA Corporation
(途中略)
Device ID: 0
Device name: Tesla K80
Device type: GPU
Device vendor: NVIDIA Corporation
Device driver: 410.72
Device speed: 823 MHz
Device cores: 13 CU
Device score: 1112
Selected platform: NVIDIA CUDA
Selected device: Tesla K80
with OpenCL 1.2 capability.
Half precision compute support: No.
Loaded existing SGEMM tuning.
Wavefront/Warp size: 32
Max workgroup size: 1024
Max workgroup dimensions: 1024 1024 64
Setting max tree size to 4385 MiB and cache size to 487 MiB.
[----------] 7 tests from LeelaTest
[ RUN ] LeelaTest.Startup
[ OK ] LeelaTest.Startup (0 ms)
[ RUN ] LeelaTest.DefaultHash
[ OK ] LeelaTest.DefaultHash (0 ms)
[ RUN ] LeelaTest.Transposition
[ OK ] LeelaTest.Transposition (0 ms)
[ RUN ] LeelaTest.KoPntNotSame
[ OK ] LeelaTest.KoPntNotSame (0 ms)
[ RUN ] LeelaTest.MoveOnOccupiedPnt
[ OK ] LeelaTest.MoveOnOccupiedPnt (0 ms)
[ RUN ] LeelaTest.TimeControl
[ OK ] LeelaTest.TimeControl (8 ms)
[ RUN ] LeelaTest.TimeControl2
[ OK ] LeelaTest.TimeControl2 (4 ms)
[----------] 7 tests from LeelaTest (14 ms total)
[----------] 4 tests from UtilsTest
[ RUN ] UtilsTest.CeilMultiple
[ OK ] UtilsTest.CeilMultiple (0 ms)
[ RUN ] UtilsTest.RandFix
[ OK ] UtilsTest.RandFix (0 ms)
[ RUN ] UtilsTest.Randuint64_lastEightBits
[ OK ] UtilsTest.Randuint64_lastEightBits (0 ms)
[ RUN ] UtilsTest.Randuint64_max
[ OK ] UtilsTest.Randuint64_max (0 ms)
[----------] 4 tests from UtilsTest (1 ms total)
[----------] Global test environment tear-down
[==========] 11 tests from 2 test cases ran. (4154 ms total)
[ PASSED ] 11 tests.
$
Leela Zero を動かしてみる
Leela Zero が推論に利用するための、学習済みのデータをダウンロードします。
# ネットワークファイル(学習済みモデル)を ~/.local/share/leela-zero/best-network にダウンロード
curl -o ~/.local/share/leela-zero/best-network https://zero.sjeng.org/best-network
ここで ~/.local/share/leela-zero/best-network は、何も指定しない場合に、Leela Zero がネットワークファイルを探しに行く場所です。best-network は頻繁に強化され、更新されている ので、ときどき仮想マシンに SSH ログインして、このコマンドを叩いてみるとよいですね。
そして、いよいよ Leela Zero を実行してみます。
# Leela Zero を実行
~/leela-zero/build/leelaz
うまくいくと、次のような表示になります。
$ ~/leela-zero/build/leelaz
Using 1 thread(s).
RNG seed: 13987364284941660012
Leela Zero 0.16 Copyright (C) 2017-2018 Gian-Carlo Pascutto and contributors
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; see the COPYING file for details.
BLAS Core: built-in Eigen 3.3.5 library.
Detecting residual layers...v1...256 channels...40 blocks.
Initializing OpenCL (autodetecting precision).
Detected 1 OpenCL platforms.
Platform version: OpenCL 1.2 CUDA 10.0.182
Platform profile: FULL_PROFILE
Platform name: NVIDIA CUDA
Platform vendor: NVIDIA Corporation
Device ID: 0
Device name: Tesla K80
Device type: GPU
Device vendor: NVIDIA Corporation
Device driver: 410.72
Device speed: 823 MHz
Device cores: 13 CU
Device score: 1112
Selected platform: NVIDIA CUDA
Selected device: Tesla K80
with OpenCL 1.2 capability.
Half precision compute support: No.
Detected 1 OpenCL platforms.
Platform version: OpenCL 1.2 CUDA 10.0.182
Platform profile: FULL_PROFILE
Platform name: NVIDIA CUDA
Platform vendor: NVIDIA Corporation
(中略)
Selected platform: NVIDIA CUDA
Selected device: Tesla K80
with OpenCL 1.2 capability.
Half precision compute support: No.
Loaded existing SGEMM tuning.
Wavefront/Warp size: 32
Max workgroup size: 1024
Max workgroup dimensions: 1024 1024 64
Setting max tree size to 3736 MiB and cache size to 415 MiB.
Passes: 0 Black (X) Prisoners: 0
Black (X) to move White (O) Prisoners: 0
a b c d e f g h j k l m n o p q r s t
19 . . . . . . . . . . . . . . . . . . . 19
18 . . . . . . . . . . . . . . . . . . . 18
17 . . . . . . . . . . . . . . . . . . . 17
16 . . . + . . . . . + . . . . . + . . . 16
15 . . . . . . . . . . . . . . . . . . . 15
14 . . . . . . . . . . . . . . . . . . . 14
13 . . . . . . . . . . . . . . . . . . . 13
12 . . . . . . . . . . . . . . . . . . . 12
11 . . . . . . . . . . . . . . . . . . . 11
10 . . . + . . . . . + . . . . . + . . . 10
9 . . . . . . . . . . . . . . . . . . . 9
8 . . . . . . . . . . . . . . . . . . . 8
7 . . . . . . . . . . . . . . . . . . . 7
6 . . . . . . . . . . . . . . . . . . . 6
5 . . . . . . . . . . . . . . . . . . . 5
4 . . . + . . . . . + . . . . . + . . . 4
3 . . . . . . . . . . . . . . . . . . . 3
2 . . . . . . . . . . . . . . . . . . . 2
1 . . . . . . . . . . . . . . . . . . . 1
a b c d e f g h j k l m n o p q r s t
Hash: 9A930BE1616C538E Ko-Hash: A14C933E7669946D
Black time: 01:00:00
White time: 01:00:00
Leela:
ここで一応、GTP (Go Text Protocol) に準拠した、次のようなコマンドで操作できるようです。
Leela: list_commands
= protocol_version
name
version
quit
known_command
list_commands
boardsize
clear_board
komi
play
genmove
showboard
undo
final_score
final_status_list
time_settings
time_left
fixed_handicap
place_free_handicap
set_free_handicap
loadsgf
printsgf
kgs-genmove_cleanup
kgs-time_settings
kgs-game_over
heatmap
lz-analyze
lz-genmove_analyze
lz-memory_report
lz-setoption
というものの、これではさすがに無理ゲーなので、GTP に対応した GUI インターフェイスを用意したいところです。
GUI フロントエンドの選択
Leela Zero の GUI フロントエンド(操作画面)として、主流となっているのは、
の3種類。どれも、Windows, Mac, Linux で動きますが、Lizzie は "Leela Zero Interface" を謳っているだけあって、かなりいい感じで動作します。

ということで、ここでは Lizzie を選択することにします。
その3 Lizzie 導入編へ続きます。