ML-Agents Use Docker to run ML-Agents

Original link: https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Using-Docker.md

ML-Agents use Docker to run ML-Agents

We currently have solutions for Windows and Mac users who wish to use Docker for training or inference. This option may be attractive to those who want to avoid installing Python and TensorFlow themselves. The current configuration forces TensorFlow and Unity to rely solely on the CPU for computation. Therefore, our Docker simulation does not use the GPU and uses Xvfb for visual rendering. Xvfb is a utility that enables ML-Agent (or any other application) to render virtually, i.e. it does not assume that the machine running ML-Agents has an attached GPU or display. This means that camera-based visual observation may be slower if an agent is involved in the environment.

 

Require

  • Unity Linux Build Support Component
  • Docker

configure

  • Download the Unity installer and add the Linux Build Support component
  •  If you don't have it installed on your machine, download and install Docker
  • Since Docker runs containers in an environment isolated from the host, a directory on the host is required for shared data, such as Unity executables, training files, and TensorFlow graphs. For convenience, we created an empty unity-volumn directory at the root of the repository for this purpose, but feel free to use any other directory. The rest of this guide assumes that the unity-volume directory is the one used.

usage

 Running ML-Agents with Docker involves three steps: building the Unity environment with specific flags, building the Docker container, and finally running the container. If you're new to building Unity environments for ML-Agents, start by reading our Getting Started with our 3D Balance Ball Example Guide.

build environment

Since Docker typically runs containers that share the (linux) kernel with the host, the Unity environment build must point to the Linux platform. When building your Unity environment, select the following options from the Build Settings window:

  • Set Target Platform to Linux
  • Set Architecture to x86_64
  • If the environment does not contain visual observations, the headless option can be selected here .

Then click Build, choose an environment name (eg 3DBall) and set the output directory to unity-volume . Once the build is complete, make sure to create the file <environment-name>.x86_64 and the subdirectory <environment-name>_Data/ under unity-volume .

 

Build the Docker container

 First, make sure the Docker engine is running on your machine. Then build the Docker container by calling the following command at the top level of the repository:

docker build -t <image-name> .

 Replace <image-name> with the name of the Docker image, such as balance.ball.v0.1.

 

Run Docker containers

 Run the Docker container by calling the following command at the top level of the repository:

docker run --name <container-name> \
           --mount type=bind,source="$(pwd)"/unity-volume,target=/unity-volume \
           <image-name>:latest <environment-name> \
           --docker-target-name=unity-volume \
           --train \
           --run-id=<run-id>

 Comments on parameter values:

  • <container-name> is used to identify the container (to facilitate interruption and termination of the container). This is optional, if not set, Docker will generate a random name. Note that this must be unique for each run of the Docker image.

  • <image-name> and <environment-name>: refer to the image and environment name respectively.

  • source: Refers to the path in your host OS where the Unity executable is stored.

  • target: Instructs Docker to mount the source path as a disk with this name.

  • docker-target-name: Tells the ML-Agents Python package the name of the disk on which it can read the Unity executable and store the graph. So this should be the same as target .

  • train, run-id: ML-Agents parameters passed to learn.py. train training algorithm, run-id is a unique identifier used to mark each training.

For a 3DBall environment, for example this would be:

docker run --name 3DBallContainer.first.trial \
           --mount type=bind,source="$(pwd)"/unity-volume,target=/unity-volume \
           balance.ball.v0.1:latest 3DBall \
           --docker-target-name=unity-volume \
           --train \
           --run-id=3dball_first_trial

 For more details on Docker installation, check out these documents in Docker.

 

Stop container and save state

 If you are satisfied with the training progress, you can stop the Docker container while saving the state with Ctrl+C or ⌘+C (Mac) or with:

docker kill --signal=SIGINT <container-name>

 <container-name> is the name of the container specified in the previous docker run command. If you don't specify it, you can find the randomly generated identifier by running docker container ls.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325021772&siteId=291194637