Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to run ml-agents on server?

Discussion in 'ML-Agents' started by ValBis, Oct 26, 2020.

  1. ValBis

    ValBis

    Joined:
    Jul 9, 2017
    Posts:
    50
    Hello. I have been stuck with this for a while, and I need someone's help.

    I manage to run a unity environment from my local (windows) machine. It's time now to move everything on the server to do proper ultra-fast computation. I build my scene using BuildTarget.StandaloneLinux64, and move it on the server. I am ssh'ing into a linux ubuntu server, and entering a docker container, using a Xming server, forwarding X11 on my machine. This works for demo apps (such as xclock or xeyes) but not with the unity environment:
    Code (CSharp):
    1. python code/examples/UnityMetaLearningTask.py
    2. 2020-10-26 12:51:29 DEBUG [env_utils.py:30] The true file name is scene
    3. 2020-10-26 12:51:29 DEBUG [env_utils.py:99] This is the launch string /work/./code/Unity-ML-Agents-Computer-Vision/Builds/Builds/MetaLearning_linux/N2_K4_Q2_sc64_dDatasetSupport/scene.x86_64
    4. Found path: /work/./code/Unity-ML-Agents-Computer-Vision/Builds/Builds/MetaLearning_linux/N2_K4_Q2_sc64_dDatasetSupport/scene.x86_64
    5. [[ AND AFTER SOME TIME... ]]
    6.  "The Unity environment took too long to respond. Make sure that :\n"
    7. mlagents_envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
    8.          The environment does not need user interaction to launch
    9.          The Agents' Behavior Parameters > Behavior Type is set to "Default"
    10.         The environment and the Python interface have compatible versions.
    11.  
    I have found this guide https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Training-on-Amazon-Web-Service.md but I am afraid it's outdated and it won't lead me anywhere. So my question is: is there a better place to look for some guidance on that?
    Thanks
     
  2. celion_unity

    celion_unity

    Unity Technologies

    Joined:
    Jun 12, 2019
    Posts:
    289
    If you need graphics (for example, if you're using a CameraSensor for observations), you'll need to set up xvfb to handle the rendering. There's an example of setting this up in a Colab notebook that we put together here.

    If you don't need graphics, you can pass the --no-graphics option to mlagents-learn, or if you're using
    UnityEnvironment, set the no_graphics argument in the initializer. Both of these correspond to adding "-nographics -batchmode" to the Unity executable's commandline.
     
  3. ValBis

    ValBis

    Joined:
    Jul 9, 2017
    Posts:
    50
    Thanks! I have solved it few days ago thanks to that very Colab notebook. The important bit is to use the right xvfb version, as the one I had installed wasn't working properly. I am now able to run ml-agents *with visual observations* on a docker container in linux! :)
    I have still trouble building a unity scene within a docker container, but that's a problem for another day..
     
    Last edited: Oct 30, 2020
  4. ervteng_unity

    ervteng_unity

    Unity Technologies

    Joined:
    Dec 6, 2018
    Posts:
    150
    Hi ValBis, great you were able to get it to work! Just for our future reference, which version of xvfb worked (and which one didn't)? We'll add it to the documentation. Thanks!
     
  5. ValBis

    ValBis

    Joined:
    Jul 9, 2017
    Posts:
    50
    Sure! Xvfb that worked: xvfb_1.18.4.
    Not sure what was installed by default in my docker image (xvfb doesn't have a way to return the version :/

    Anyway I have setup this repo to setup the Docker container with ML-Agents with visual observations, hopefully it can be useful
    https://github.com/ValerioB88/ml-agents-visual-observations-docker
     
    ervteng_unity likes this.
  6. ValBis

    ValBis

    Joined:
    Jul 9, 2017
    Posts:
    50
    @ervteng_unity I managed to run a ml-agent scene on ubuntu on a docker container, on a server, with Visual Observations, with also exploiting the GPU for rendering the Unity scene itself. This is useful in case the scene involves a lot of graphic computation. Rendering stuff on the CPU may slow down training massively, as the network would constantly be waiting for new frames to arrive. In fact, my GPU was only active at 5% on average as couldn't get new frame fast enough.
    In this way, my GPU is active at around 20%. Not great, but better. The network may still be waiting for new frames to arrive, and this may be due to socket speed or non-GPU related Unity stuff (as in my own script in the scene).

    The Docker Image and relative instructions are here:
    ValerioB88/ml-agents-visual-observations-docker-GPU: A sample Docker image for using ML-Agents with GPU support for Unity. (github.com)
     
    Last edited: Nov 26, 2020
    mbaske likes this.
  7. maxkcy

    maxkcy

    Joined:
    Oct 11, 2021
    Posts:
    47
    I dont have Google access to this, can you please post a guide again onhow to set up training on a dedocated server?