CAFE

바둑

미니고

작성자진세|작성시간19.03.22|조회수171 목록 댓글 0


https://github.com/tensorflow/minigo


Minigo: A minimalist Go engine modeled after AlphaGo Zero, built on MuGo

This is an implementation of a neural-network based Go AI, using TensorFlow. While inspired by DeepMind's AlphaGo algorithm, this project is not a DeepMind project nor is it affiliated with the official AlphaGo project.

This is NOT an official version of AlphaGo

Repeat, this is not the official AlphaGo program by DeepMind. This is an independent effort by Go enthusiasts to replicate the results of the AlphaGo Zero paper ("Mastering the Game of Go without Human Knowledge," Nature), with some resources generously made available by Google.

Minigo is based off of Brian Lee's "MuGo" -- a pure Python implementation of the first AlphaGo paper "Mastering the Game of Go with Deep Neural Networks and Tree Search" published in Nature. This implementation adds features and architecture changes present in the more recent AlphaGo Zero paper, "Mastering the Game of Go without Human Knowledge". More recently, this architecture was extended for Chess and Shogi in "Mastering Chess and Shogi by Self-Play with a General Reinforcement Learning Algorithm". These papers will often be abridged in Minigo documentation as AG (for AlphaGo), AGZ(for AlphaGo Zero), and AZ (for AlphaZero) respectively.

Goals of the Project

  1. Provide a clear set of learning examples using Tensorflow, Kubernetes, and Google Cloud Platform for establishing Reinforcement Learning pipelines on various hardware accelerators.

  2. Reproduce the methods of the original DeepMind AlphaGo papers as faithfully as possible, through an open-source implementation and open-source pipeline tools.

  3. Provide our data, results, and discoveries in the open to benefit the Go, machine learning, and Kubernetes communities.

An explicit non-goal of the project is to produce a competitive Go program that establishes itself as the top Go AI. Instead, we strive for a readable, understandable implementation that can benefit the community, even if that means our implementation is not as fast or efficient as possible.

While this product might produce such a strong model, we hope to focus on the process. Remember, getting there is half the fun. :)

We hope this project is an accessible way for interested developers to have access to a strong Go model with an easy-to-understand platform of python code available for extension, adaptation, etc.

If you'd like to read about our experiences training models, see RESULTS.md.

To see our guidelines for contributing, see CONTRIBUTING.md.

Getting Started

This project assumes you have the following:

  • virtualenv / virtualenvwrapper
  • Python 3.5+
  • Docker
  • Cloud SDK
  • Bazel v0.11 or greater

The Hitchhiker's guide to python has a good intro to python development and virtualenv usage. The instructions after this point haven't been tested in environments that are not using virtualenv.

pip3 install virtualenv
pip3 install virtualenvwrapper

Install TensorFlow

First set up and enter your virtualenv and then the shared requirements:

pip3 install -r requirements.txt

Then, you'll need to choose to install the GPU or CPU tensorflow requirements:

  • GPU: pip3 install "tensorflow-gpu>=1.11,<1.12".
    • Note: You must install CUDA 9.0. for Tensorflow 1.5+.
  • CPU: pip3 install "tensorflow>=1.11,<1.12".

Setting up the Environment

You may want to use a cloud project for resources. If so set:

PROJECT=foo-project

Then, running

source cluster/common.sh

will set up other environment variables defaults.

Running unit tests

./test.sh

To run individual modules

BOARD_SIZE=9 python3 tests/run_tests.py test_go
BOARD_SIZE=19 python3 tests/run_tests.py test_mcts

Automated Tests

Test Dashboard

To automatically test PRs, Minigo uses Prow, which is a test framework created by the Kubernetes team for testing changes in a hermetic environment. We use prow for running unit tests, linting our code, and launching our test Minigo Kubernetes clusters.

You can see the status of our automated tests by looking at the Prow and Testgrid UIs:

Basics

All commands are compatible with either Google Cloud Storage as a remote file system, or your local file system. The examples here use GCS, but local file paths will work just as well.

To use GCS, set the BUCKET_NAME variable and authenticate via gcloud login. Otherwise, all commands fetching files from GCS will hang.

For instance, this would set a bucket, authenticate, and then look for the most recent model.

# When you first start we recommend using our minigo-pub bucket.
# Later you can setup your own bucket and store data there.
export BUCKET_NAME=minigo-pub/v9-19x19
gcloud auth application-default login
gsutil ls gs://$BUCKET_NAME/models | tail -4

Which might look like:

gs://$BUCKET_NAME/models/000737-fury.data-00000-of-00001
gs://$BUCKET_NAME/models/000737-fury.index
gs://$BUCKET_NAME/models/000737-fury.meta
gs://$BUCKET_NAME/models/000737-fury.pb

These four files comprise the model. Commands that take a model as an argument usually need the path to the model basename, e.g. gs://$BUCKET_NAME/models/000737-fury

You'll need to copy them to your local disk. This fragment copies the files associated with $MODEL_NAME to the directory specified by MINIGO_MODELS:

MODEL_NAME=000737-fury
MINIGO_MODELS=$HOME/minigo-models
mkdir -p $MINIGO_MODELS/models
gsutil ls gs://$BUCKET_NAME/models/$MODEL_NAME.* | \
       gsutil cp -I $MINIGO_MODELS/models

Selfplay

To watch Minigo play a game, you need to specify a model. Here's an example to play using the latest model in your bucket

python3 selfplay.py \
  --verbose=2 \
  --num_readouts=400 \
  --load_file=$MINIGO_MODELS/models/$MODEL_NAME

where READOUTS is how many searches to make per move. Timing information and statistics will be printed at each move. Setting verbosity to 3 or higher will print a board at each move.

Playing Against Minigo

Minigo uses the GTP Protocol, and you can use any gtp-compliant program with it.

# Latest model should look like: /path/to/models/000123-something
LATEST_MODEL=$(ls -d $MINIGO_MODELS/* | tail -1 | cut -f 1 -d '.')
python3 gtp.py --load_file=$LATEST_MODEL --num_readouts=$READOUTS --verbose=3

After some loading messages, it will display GTP engine ready, at which point it can receive commands. GTP cheatsheet:

genmove [color]             # Asks the engine to generate a move for a side
play [color] [coordinate]   # Tells the engine that a move should be played for `color` at `coordinate`
showboard                   # Asks the engine to print the board.

One way to play via GTP is to use gogui-display (which implements a UI that speaks GTP.) You can download the gogui set of tools at http://gogui.sourceforge.net/. See also documentation on interesting ways to use GTP.

gogui-twogtp -black 'python3 gtp.py --load_file=$LATEST_MODEL' -white 'gogui-display' -size 19 -komi 7.5 -verbose -auto

Another way to play via GTP is to watch it play against GnuGo, while spectating the games:

BLACK="gnugo --mode gtp"
WHITE="python3 gtp.py --load_file=$LATEST_MODEL"
TWOGTP="gogui-twogtp -black \"$BLACK\" -white \"$WHITE\" -games 10 \
  -size 19 -alternate -sgffile gnugo"
gogui -size 19 -program "$TWOGTP" -computer-both -auto

Training Minigo

Overview

The following sequence of commands will allow you to do one iteration of reinforcement learning on 9x9. These are the basic commands used to produce the models and games referenced above.

The commands are

  • bootstrap: initializes a random model
  • selfplay: plays games with the latest model, producing data used for training
  • train: trains a new model with the selfplay results from the most recent N generations.

Training works via tf.Estimator; a working directory manages checkpoints and training logs, and the latest checkpoint is periodically exported to GCS, where it gets picked up by selfplay workers.

Configuration for things like "where do debug SGFs get written", "where does training data get written", "where do the latest models get published" are managed by the helper scripts in the rl_loop directory. Those helper scripts execute the same commands as demonstrated below. Configuration for things like "what size network is being used?" or "how many readouts during selfplay" can be passed in as flags. The mask_flags.py utility helps ensure all parts of the pipeline are using the same network configuration.

All local paths in the examples can be replaced with gs:// GCS paths, and the Kubernetes-orchestrated version of the reinforcement learning loop uses GCS.

Bootstrap

This command initializes your working directory for the trainer and a random model. This random model is also exported to --model-save-path so that selfplay can immediately start playing with this random model.

If these directories don't exist, bootstrap will create them for you.

export MODEL_NAME=000000-bootstrap
python3 bootstrap.py \
  --work_dir=estimator_working_dir \
  --export_path=outputs/models/$MODEL_NAME

Self-play

This command starts self-playing, outputting its raw game data as tf.Examples as well as in SGF form in the directories.

python3 selfplay.py \
  --load_file=outputs/models/$MODEL_NAME \
  --num_readouts 10 \
  --verbose 3 \
  --selfplay_dir=outputs/data/selfplay \
  --holdout_dir=outputs/data/holdout \
  --sgf_dir=outputs/sgf

Training

This command takes a directory of tf.Example files from selfplay and trains a new model, starting from the latest model weights in the estimator_working_dir parameter.

Run the training job:

python3 train.py \
  outputs/data/selfplay/* \
  --work_dir=estimator_working_dir \
  --export_path=outputs/models/000001-first_generation

At the end of training, the latest checkpoint will be exported to. Additionally, you can follow along with the training progress with TensorBoard. If you point TensorBoard at the estimator working directory, it will find the training log files and display them.

tensorboard --logdir=estimator_working_dir

Validation

It can be useful to set aside some games to use as a 'validation set' for tracking the model overfitting. One way to do this is with the validate command.

Validating on holdout data

By default, Minigo will hold out 5% of selfplay games for validation. This can be changed by adjusting the holdout_pct flag on the selfplay command.

With this setup, rl_loop/train_and_validate.py will validate on the same window of games that were used to train, writing TensorBoard logs to the estimator working directory.

Validating on a different set of data

This might be useful if you have some known set of 'good data' to test your network against, e.g., a set of pro games. Assuming you've got a set of .sgfs with the proper komi & boardsizes, you'll want to preprocess them into the .tfrecord files, by running something similar to

import preprocessing
filenames = [generate a list of filenames here]
for f in filenames:
    try:
        preprocessing.make_dataset_from_sgf(f, f.replace(".sgf", ".tfrecord.zz"))
    except:
        print(f)

Once you've collected all the files in a directory, producing validation is as easy as

python3 validate.py \
  validation_files/ \
  --work_dir=estimator_working_dir \
  --validation_name=pro_dataset

The validate.py will glob all the .tfrecord.zz files under the directories given as positional arguments and compute the validation error for the positions from those files.

Running Minigo on a Kubernetes Cluster

See more at cluster/README.md



========================================


1. 개요2. 상세3. 버전별 정보
3.1. v153.2. v163.3. v173.4. v18
4. 설치

1. 개요[편집]

GitHub
Stats
Discord[1]
가중치 파일 전체

구글의 Andrew Jackson에 의한, 알파고 제로/알파제로의 재구현을 목표로 하는 오픈 소스 바둑 인공지능 프로젝트. 따라서 알파고 제로 혹은 알파제로의 다른 재구현 프로젝트들인 릴라 제로엘프고 등과 매우 비슷한 내부구조를 갖는 버전들이 많다.[2] 이 사례에 해당하는 v15와 v16의 가중치들은 간단한 변환과정만 거치면 릴라 제로 엔진을 가지고도 사용할 수 있는데, 아래의 버전별 정보에 링크된 파일들이 바로 릴라 제로 엔진에서 사용되도록 변환된 파일들이다. 그러나 프로젝트로서는 엄연히 알파고와 독립으로, 미니고는 알파고가 아니며, 딥마인드와도 직접적인 연관은 없다고 밝히고 있다.

2. 상세[편집]

텐서플로우를 기반으로 개발되었다. 강화학습에 TPU를 활용하고 있어 굉장히 빠른 진행을 보이고 있는 것이 특징이다. "played on X00 TPU"라 밝히고 있으므로 수백 개가 쓰이고 있다는 것까지는 알 수 있지만 정확히 몇백 개인지는 알 수 없다. 학습을 위한 자가대국은 800 playouts의 설정에서 이루어지는데, 빠를 때는 하루에 백만 판이 넘게 진행된다. 가중치들 간의 기력 비교를 위한 평가대국에서는 TPU가 사용되지 않는다고 하며, 이 때문인지 하루에 진행되는 대국 수가 학습을 위한 대국보다는 훨씬 적다. 버전의 숫자가 올라갈 때마다 기술적으로 새로운 시도를 끼워넣으며 맨바닥에서부터 다시 학습하기 때문에, 공개되는 것들이 굉장히 의미있는 데이터라고 할 수 있다.

이전에는 구글이 바둑을 또 손댄다는 점에서 주목을 받았는데, v15에 들어서면서부터 릴라 제로엘프고와 더불어 오픈 소스 바둑 인공지능의 강자로 부상하였다. 삼대장 체제의 도래 게다가 빠른 발전속도를 감안하면 앞으로가 상당히 기대되는 상황. 떠오른 시기가 인공지능 바둑이 한창 주목받던 시기와 가깝지 않고, 엘프고가 등장할 때 당시의 릴라 제로를 압도하며 오픈 소스 최강자라는 인식을 선점해버린 바가 있기 때문에 여러 바둑 커뮤니티나 유튜브 등지에서 미니고가 언급되는 경우는 비교적 적었다. 그러다가 2019년 3월 들어서 v17을 일반 사용자들도 이용할 수 있게 되었는데, 이것의 기력이 강하다는 것이 알려지기 시작하면서 커뮤니티에서도 주목을 받게 되었다.

OGS(Online Go Service)에서는 현재 LZ 엔진과 v15 000939-heron[3] 가중치를 이용하여 RoyalMinigo라는 아이디로 활동하고 있으니, 전적이나 레이팅을 참고해볼 것.

3. 버전별 정보[편집]

3.1. v15[편집]

v15 - LZ 엔진용 변환 가중치 파일

자체적인 평가에 의하면, v15에서 가장 강한 버전인 000990-cormorant는 릴라 제로와 엘프고에 견줄 만큼 강하다고 한다.[4]

v15는 학습과정에서 2560만 판에 달하는 막대한 양의 자가대국을 치른 점, 미니고가 이전에도 20블록의 학습을 여러 번 수행한 경험을 가진 점, 그리고 페이스북이 제법 시간을 들여 개발한 20블록 AI인 엘프고와 호각의 기력을 지닌 점 등을 볼 때, 20블록이 가진 잠재력을 충분히 발휘하여 알파제로[5]가 도달했던 수준, 혹은 그 이상에 이르렀을 것으로 조심스럽게 추측할 수 있다.

3.2. v16[편집]

v16 - LZ 엔진용 변환 가중치 파일

미니고 내에서 40블록의 학습을 처음으로 시도한 v16도 진행이 완료되었다. 흑으로 첫 수를 3·3에다 두는 것이 특징이다.[6]

v15와 비교했을 때 동일 visits 수 하에서 더 강한 기력이 나오는 것 같지 않으며, 이에 따라 동일한 시간 설정 하에서의 성능은 더 나쁘다고 평가되었다. 역시 40블록을 잘 학습시키는 것은 아주 어려운 작업이다.따라서 40블록짜리 미니고를 기대한다면 차기 버전을 기약해야 하는 상황이나, 미니고가 40블록의 학습을 다시 시도할 계획을 가지고 있는지는 불명.[7]

3.3. v17[편집]

v17에서는 다시 20블록 크기로 돌아왔다. 기존의 순수 ResNet과는 다르게 Squeeze and Excitation이라는 네트워크[8]를 새로 적용했기 때문에, v17은 이전 버전들과는 달리 단순한 변환작업을 거치는 것만으로는 릴라 제로 엔진에서 구동하도록 만들 수가 없다고 한다. 링크

세븐틴 님의 인공지능 바둑 통합설치팩에 미니고 v17을 구동할 수 있는 엔진이 포함되어 있다. 블로그 바로가기

자체 테스트 결과[9]에 의하면, v17의 기력은 이전 버전들보다 강하다. 사용자들에 의한 테스트 결과들도 여러 커뮤니티를 통해 올라오고 있는데, 릴라 제로와 엘프고를 상대로도 상당히 선전한다는 보고가 다수. 새로운 시도를 통해 강한 기력을 얻어내는 데에 성공한 듯. 대세로 떠오르는 SENet?

v17의 학습이 001003-leviathan을 마지막으로 종료될 것인지, 아니면 다시 재개될 것인지가 아직 정해지지 않은 듯하다.

3.4. v18[편집]

미니고 디스코드에서 v18에 대한 구상을 밝혔다. 이 곳에 적어둔 아이디어들을 적용해 볼 계획이라고 한다.

4. 설치[편집]

위에서도 언급했듯이 미니고 v15나 v16는 주로 릴라 제로용으로 개발된 툴들을 이용하여 구동한다. 해당 문서의 대국 방법 부분을 참고.


[1] 그럭저럭 활발한 커뮤니티. 개발자들의 토의를 볼 수 있어서 좋다. 들어가서 궁금한 거 물어보면 답변도 해준다.[2] 그러므로 구체적인 작동 원리가 궁금한 경우 알파고 제로를 비롯한 다른 제로 계열 인공지능에 관한 자료들을 참고할 수도 있을 것이다.[3] v15 내에서는 두 번째로 강한 걸로 평가된 가중치 파일이다.[4] 그러나 제3자에 의한 여러 실험 결과들에서는 미니고가 약간 더 약한 것으로 나오는 경우가 많다. v15의 학습이 끝나고 해당 코멘트가 있은 후로도 시간이 지나면서 릴라 제로는 버전 업데이트를 여러 번 거쳤고, 엘프고 또한 v2를 공개하였기 때문이기도 하다.[5] 알파제로도 20블록이었다.[6] 미니고 개발자도 v16이 3·3을 두게 된 것에 어떤 의미가 있는지 궁금하다고 디스코드에서 여러 번 말했다. 똑같은 40블록인 알파고 제로도 남기고 간 기보를 보면 안 그랬고, 릴라 제로도 현재 안 그러고 있으니...[7] 개발자 입장에서 볼 때 과연 40블록이 20블록에 비해 얼마나 매력이 있을지를 한 번 생각해 보자. 확실히, 20블록으로  버그나 사활 버그를 해결하는 것은 아직까지 무리이고, 40블록에는 이런 측면에 있어 훨씬 나은 잠재력을 가진다는 큰 장점이 있다. 그러나 개발자들에게 있어서 바둑 AI의 개발은, 강한 바둑 실력을 성취하는 과정으로서보다는 딥러닝 기법을 시현하는 과정으로서의 의미가 훨씬 더 크다. 구글이나 페이스북 같은 대기업은 당연히 모종의 성과를 기대하고서 계산자원을 투입해가며 프로젝트를 벌이는 것일 텐데, 그 원하는 성과라는 것이 바둑 기력 따위일 리는 없잖은가? 새 기술이 나오는 속도는 빠르고 테스트해 보아야 할 것은 산적해 있는 상황에서, 굳이 20블록보다 학습이 훨씬 오래 걸리는 40블록을 택하여 한 가지 모델에 계속 매달려 있게 되는 것이 좋은 생각일 때는 그렇게 많지 않을 것이다.[8] 줄여서 SENet이라고도 한다.[9] 여기에 링크된 페이지를 볼 때 유의해야 할 점은, 여기서 평가된 미니고의 ELO 레이팅은 프로기사들의 세계랭킹을 매기는 goratings에 기록된 점수와 통일된 스케일을 사용하는 것이 아니라는 점이다. 따라서 수치를 직접 비교해서는 안 된다.


다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼