Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KGS ViT Bot #140

Merged
merged 10 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions configs/gtp-amcts.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ conservativePass = false
# subtreeValueBiasWeightExponent = 0.8
# fpuParentWeightByVisitedPolicy = false
# enablePassingHacks = false

# Our bots only trained with Tromp-Taylor rules. This setting makes GTP ignore
# commands that change the rules.
ignoreGTPRuleChanges = true
8 changes: 5 additions & 3 deletions configs/gtp-base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ logAllGTPCommunication = false
# Remove unnecessary non-determinism
numSearchThreads = 1

# For compatibility with other engines, we need to set multiStoneSuicideLegal, which
# means we also need to set the other rules instead of relying on rules = tromp-taylor
# Since Leela and ELF do not allow multi-stone suicide, when playing against
# them we need to set multiStoneSuicideLegal to false. Then we also need to set
# the other rules instead of relying on rules = tromp-taylor.
# multiStoneSuicideLegal = false
multiStoneSuicideLegal = true
koRule = POSITIONAL
scoringRule = AREA
multiStoneSuicideLegal = false

allowResignation = false
resignConsecTurns = 3
Expand Down
64 changes: 64 additions & 0 deletions configs/kgs-bot/vit-bot.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Our bots only trained with Tromp-Taylor rules. This setting makes GTP ignore
# commands that change the rules.
ignoreGTPRuleChanges = true

# 65k visits with 64 threads should be slightly weaker than 32k visits with 1 thread.
maxVisits = 65536
numSearchThreads = 64
ed1d1a8d marked this conversation as resolved.
Show resolved Hide resolved

# We're not really interested in detailed logging when running with GTP
logSearchInfo = false
logAllGTPCommunication = false

# Tromp-Taylor Rules
koRule = POSITIONAL
scoringRule = AREA
multiStoneSuicideLegal = true
taxRule = NONE
hasButton = false

# Allow resignation
allowResignation = true
resignConsecTurns = 6
resignThreshold = -0.95

# The below parameters are copied from gtp_example.cfg; we need to copy instead of @include because
# it's currently impossible to override "rules = tromp-taylor" once it's set in an included file.
lagBuffer = 1.0
maxVisitsPondering = 65536
ponderingEnabled = true

# friendliness
searchFactorAfterOnePass = 0.50
searchFactorAfterTwoPass = 0.25
searchFactorWhenWinning = 0.40
searchFactorWhenWinningThreshold = 0.95
friendlyPassOk = true

# Other configs
useGraphSearch = true
searchAlgorithm = MCTS
conservativePass = false

# GPU Settings-------------------------------------------------------------------------------
# A6000
# 2 sockets of AMD EPYC 7763 64-Core Processors = 128 physical cores
# each core has 2 threads

nnMaxBatchSize = 128
nnCacheSizePowerOfTwo = 21
nnMutexPoolSizePowerOfTwo = 17
numNNServerThreadsPerModel = 2
nnRandomize = true

deviceToUseThread0 = 0
deviceToUseThread1 = 1

# For ViTs and other TorchScript models, the setting for useFP16 or useFP16-N
# (where N is the bot index) must match whether the TorchScript model was
# exported with FP16 or not.
useFP16 = true

# Disable NHWC for ViT models
useNHWC = false
inputsUseNHWC = false
23 changes: 10 additions & 13 deletions engines/kgs-bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# To build, navigate to the *root* of this repo and first run:
# docker build . -f compose/cpp/Dockerfile -t humancompatibleai/goattack:cpp
# And then:
# docker build . -f engines/kgs-bot/Dockerfile -t humancompatibleai/goattack:cpp-kgs
# docker build . -f engines/kgs-bot/Dockerfile -t humancompatibleai/goattack:<hash>-cpp-kgs

FROM humancompatibleai/goattack:cpp

Expand All @@ -18,20 +18,17 @@ RUN wget http://files.gokgs.com/javaBin/kgsGtp-3.5.23.zip \
&& unzip -j kgsGtp-3.5.23.zip kgsGtp-3.5.23/kgsGtp.jar -d /go_attack/engines/kgs-bot/ \
&& rm kgsGtp-3.5.23.zip

# Adversary model: cyclic-adv-s545065216-d136760487.bin.gz
# From https://drive.google.com/drive/folders/1-bGX-NQOh6MuRPoXJgYHb9-jWRJvviSg
RUN mkdir /go_attack/adversary_models
# Downloading the file directly is working for now, but sometimes Google requires
# interaction to confirm a download. If this starts breaking, try using workaround at
# https://stackoverflow.com/a/50573452/14507224
RUN wget "https://docs.google.com/uc?export=download&id=1gwD0nQsuE7aD92YJ66l82qtXR97A_lt1" -O /go_attack/adversary_models/adversary_model.bin.gz

# Victim model
RUN mkdir /go_attack/victim_models
RUN wget https://media.katagotraining.org/uploaded/networks/models/kata1/kata1-b40c256-s11840935168-d2898845681.bin.gz -O /go_attack/victim_models/victim_model.bin.gz
RUN pip install gdown
RUN mkdir /go_attack/models

# ViT model: vitp2b16c384-s650025472-d167043571-fp16.pt
# Link: https://drive.google.com/file/d/1D_Ifj3hFICxF37Yuoblde1JizOn5OhG7/view?usp=sharing
# Download method from https://stackoverflow.com/a/50670037/1337463.
RUN gdown 1D_Ifj3hFICxF37Yuoblde1JizOn5OhG7
RUN mv vitp2b16c384-s650025472-d167043571-fp16.pt /go_attack/models/vit-model-fp16.pt

# Run this last so we can update configs and other settings without invalidating cache
COPY ./engines/kgs-bot/ /go_attack/engines/kgs-bot
COPY ./engines/kgs-bot/config.txt /go_attack/engines/kgs-bot/config.txt

WORKDIR /go_attack/engines/kgs-bot/
ENTRYPOINT ["/usr/bin/java", "-jar", "kgsGtp.jar", "config.txt"]
6 changes: 3 additions & 3 deletions engines/kgs-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ USERNAME and PASSWORD should be replaced with the KGS login information for the

To adjust settings (you will need to rebuild the Dockerfile after editing these files, or bind them in with the `-v` flag to run):
* KGS game and matchmaking: go_attack/engines/kgs-bot/config.txt
* Bot itself: go_attack/configs/kgs-bot/adversary_bot.cfg
* Adversary/victim weight files: go_attack/engines/kgs-bot/Dockerfile and adjust the wgets at the end to the files you want. Or, obtain the weights manually and adjust go_attack/engines/kgs-bot/config.txt to point to them.
* Bot itself: go_attack/configs/kgs-bot/vit-bot.cfg
* Bot weight files: go_attack/engines/kgs-bot/Dockerfile and adjust the wgets at the end to the files you want. Or, obtain the weights manually and adjust go_attack/engines/kgs-bot/config.txt to point to them.

The default settings will run the cyclic-adversary trained for 545 million steps.
The default settings will run the vit-bot.

Please note there may be some configuration differences from the version used in reported experimental results, which could have unknown effects. We have confirmed playing games with Japanese or Chinese rules on KGS will result in very abnormal play. We advise only playing games on KGS with New Zealand rules.
4 changes: 2 additions & 2 deletions engines/kgs-bot/config.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode=custom
rules=newzealand
rules.boardSize=19
rules.time=5:00+5x0:30
engine=/engines/KataGo-custom/cpp/katago gtp -model /go_attack/adversary_models/adversary_model.bin.gz -config /go_attack/configs/kgs-bot/adversary_bot.cfg -victim-model /go_attack/victim_models/victim_model.bin.gz
rules.time=15:00+5x0:30
engine=/engines/KataGo-custom/cpp/katago gtp -model /go_attack/models/vit-model-fp16.pt -config /go_attack/configs/kgs-bot/vit-bot.cfg
36 changes: 36 additions & 0 deletions engines/kgs-bot/vit-bot-pro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# To launch run the following command from the directory containing this file:
# kubectl create -f vit-bot-pro.yaml
# Make sure to set the credentials of the bot accordingly.
# Only one copy of the bot can run at a time on one account!
# You can set the room the bot is in by manually logging in as the bot on KGS,
# and navigating to the room you want the bot to be in. When the bot reconnects
# it will join the room you were in.
apiVersion: batch/v1
kind: Job
metadata:
name: vit-kgs-bot-pro
labels:
kueue.x-k8s.io/queue-name: farai
spec:
suspend: true # The job must start suspended kueue will start it when it is admitted
template:
spec:
priorityClassName: high-batch
restartPolicy: OnFailure
containers:
- name: gtp
image: humancompatibleai/goattack:b2fb839-cpp-kgs
args: [
"name=???",
"password=???",
"gameNotes=:)",
"rules.time=90:00+5x0:30",
"opponent=???"
]
resources:
limits:
memory: 80Gi
nvidia.com/gpu: "2"
requests:
cpu: 32
nvidia.com/gpu: "2"
36 changes: 36 additions & 0 deletions engines/kgs-bot/vit-bot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# To launch run the following command from the directory containing this file:
# kubectl create -f vit-bot.yaml
# Make sure to set the credentials of the bot accordingly.
# Only one copy of the bot can run at a time on one account!
# You can set the room the bot is in by manually logging in as the bot on KGS,
# and navigating to the room you want the bot to be in. When the bot reconnects
# it will join the room you were in.
apiVersion: batch/v1
kind: Job
metadata:
name: vit-kgs-bot
labels:
kueue.x-k8s.io/queue-name: farai
spec:
suspend: true # The job must start suspended kueue will start it when it is admitted
backoffLimit: 9001
template:
spec:
priorityClassName: normal-batch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this high-batch as well? Then it's unlikely to get pre-empted

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I purposely made the non-pro bot normal-batch so that it could get pre-empted by more important paper experiments, since a few extra games (we have 1000 games now) won't make too much of a difference to our NeurIPS submission.

restartPolicy: OnFailure
containers:
- name: gtp
image: humancompatibleai/goattack:b2fb839-cpp-kgs
args: [
"name=ViTKata001",
"password=???",
"gameNotes=Barely superhuman Vision Transformer bot.",
"rules.time=15:00+5x0:30",
]
resources:
limits:
memory: 80Gi
nvidia.com/gpu: "2"
requests:
cpu: 32
nvidia.com/gpu: "2"