Skip to content

Commit dec92b4

Browse files
authored
Fix running of synchronous_loop.sh on macOS (Metal) (#1070)
* Fix train.py to support mps (Metal Performance Shaders) * Update Compiling.md with info about `synchronous_loop.sh` on macOS
1 parent 4097a8a commit dec92b4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Compiling.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ As also mentioned in the instructions below but repeated here for visibility, if
151151
* Pre-trained neural nets are available at [the main training website](https://katagotraining.org/).
152152
* You will probably want to edit `configs/gtp_example.cfg` (see "Tuning for Performance" above).
153153
* If using OpenCL, you will want to verify that KataGo is picking up the correct device when you run it (e.g. some systems may have both an Intel CPU OpenCL and GPU OpenCL, if KataGo appears to pick the wrong one, you can correct this by specifying `openclGpuToUse` in `configs/gtp_example.cfg`).
154+
* If you want to run `synchronous_loop.sh` on macOS, do the following steps:
155+
* Install GNU coreutils `brew install coreutils` to support a `head` tool that can take negative numbers (`head -n -5` in `train.sh`)
156+
* Install GNU findutils `brew install findutils` to support a `find` tool that supports `-printf` option, that's used by `export_model_for_selfplay.sh`. After that, fix `find` with `gfind` in the script.
157+
Note: you can try to avoid fixing `export_model_for_selfplay.sh` by adjusting `PATH` with the installed findutils: `export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"` or by using the alias `alias find="gfind"`. However, it works not always.

python/train.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,15 @@ def main(rank: int, world_size: int, args, multi_gpu_device_ids, readpipes, writ
260260
atexit.register(multiprocessing_cleanup)
261261
assert torch.cuda.is_available()
262262

263-
if True or torch.cuda.is_available():
263+
if torch.cuda.is_available():
264264
my_gpu_id = multi_gpu_device_ids[rank]
265265
torch.cuda.set_device(my_gpu_id)
266266
logging.info("Using GPU device: " + torch.cuda.get_device_name())
267267
device = torch.device("cuda", my_gpu_id)
268+
elif torch.backends.mps.is_available(): # Check for Apple Metal Performance Shaders
269+
my_gpu_id = multi_gpu_device_ids[rank]
270+
logging.info("Using MPS device")
271+
device = torch.device("mps", my_gpu_id)
268272
else:
269273
logging.warning("WARNING: No GPU, using CPU")
270274
device = torch.device("cpu")

0 commit comments

Comments
 (0)