tencent-ailab / hok_env

Honor of Kings AI Open Environment of Tencent
https://aiarena.tencent.com/aiarena/en/open-gamecore
Apache License 2.0
590 stars 68 forks source link

Training Agents on Linux Server #51

Closed haopan27 closed 3 months ago

haopan27 commented 3 months ago

I would like to have some guidance on how to train agents on a Linux server.

I am aware of a similar issue #16 but the solution there pointed to this article run_windows_gamecore_on_linux where there's nothing related to training.

There's also this issue #19 but the solution pointed to a folder hok_env/tree/master/code which prompted the "404 - page not found" error message upon clicking its link.

The closest thing I found was mentioned here in issue #23 when the author followed the run_with_prebuilt_image doc. I tried it myself, and got stuck after executing this command: sh start_learner.sh

The error message reads: sed: can't read /aiarena/code/learner//config/common.conf: No such file or directory I checked and there's indeed no such folder named /aiarena/code in my docker container, which was built by following this guide run_windows_gamecore_on_linux with certain modifications I summarized here

Any help is much appreciated here to allow me to get started on training agents for 1v1 games.

hongyangqin commented 3 months ago

Please refer to cluster.md

haopan27 commented 3 months ago

Apologies for the delay.

TL; DR: I finally managed to make it work thanks largely to the cluster.md doc

However, I would like to use this space to detail some discovery I made along the way. Perhaps that'd help folks who also would like to train agents on a Linux server.

Initially I had a hard time following the cluster.md doc. But in layman's terms, we need to build two docker containers and have them talk to each other. Node1, or container1, is responsible for running both the gamecore server and the actor process. Node2, or container2, is for the learner process.

Node1

The docker image to be used here is built by following what's described in the run_windows_gamecore_on_linux.md doc, with minor tweaks mentioned here #48

One thing I would like to point out is that, a docker network needs to be established before creating the docker container. The command to use here is: docker network create my-net You can replace "my-net" with your desired network name.

When creating the docker container, you need to supply the docker network name, for example, docker run --name gamecore-actor --network my-net -e SIMULATOR_USE_WINE=1 -it final_gamecore The steps above also apply to the container of Node2. One way to check if the two containers can talk to each other is by pinging the other inside the container using ping container_name

The game server may fail to start due to missing the license file. You need to make sure that the license file resides within the /rl_framework/gamecore/core_assets folder (in the container).

Node2

I followed the cluster.md doc, and attempted to build the docker image by using the following command: docker build -t learner -f dockerfile/dockerfile.dev --target battle --build-arg=BASE_IMAGE=tencentailab/hok_env:gpu_base_v2.0.1 .

This step failed: RUN wget -q -O /usr/share/keyrings/grafana.key https://packages.grafana.com/gpg.key && \ echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://packages.grafana.com/oss/deb stable main" >> /etc/apt/sources.list.d/grafana.list && \ apt update && \ apt install -y grafana influxdb && \ rm -rf /var/lib/apt/lists/* && \ rm -rf /etc/apt/sources.list.d/grafana.list

Then I swapped the web address there with https://mirrors.tuna.tsinghua.edu.cn/grafana/apt/, and the docker image was built successfully. With my shallow understanding, this step may even be skipped as it is only about visualization. Please correct me if I am wrong though.

Miscellaneous

When checking one of those log files, I encountered No module named ‘h5py’. pip install h5py solved the issue.

When you see AttributeError: module 'numpy' has no attribute 'float'., go to aiarena/1v1/actor/custom.py, line 46, change numpy.float to float.