Search Unity

Question Why ML-Agents don't use all my system resources?

Discussion in 'ML-Agents' started by kyung1, Aug 4, 2021.

  1. kyung1

    kyung1

    Joined:
    Jul 24, 2019
    Posts:
    2
    hello first of all, english is not my native language

    i use ml-agents in my AI-RobotBattle game project

    when i trained my AI, cpu usage in taskmanager too low
    and framerate also too low compared to my pc spec

    usually cpu usage when i training is about 10~20%

    i hope ml-agents is use all my system resource propely

    this trouble was happened both editor and build

    and this is my pc spec

    CPU : AMD Ryzen Threadripper 1950X 16Core
    Ram : 64gb
    VGA : RTX3090
     
  2. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    Maxing out ml-agents CPU usage is hard because there exist several bottlenecks that are not CPU related, like exchanging data between Unity and Python. We are working on tools to help maximize usage but we do not have anything to show yet. My recommendation would be to increase the number of agents in the environment and also increase the number of environments used for training. This should increase the data throughput and increase the frequency of updates in the trainer.
     
  3. kyung1

    kyung1

    Joined:
    Jul 24, 2019
    Posts:
    2
    thank you for answer!!
     
  4. Aleksander_Wit

    Aleksander_Wit

    Joined:
    Dec 13, 2020
    Posts:
    19
    I have an environment that provides so many steps that the python seems to be severely bottlenecked by only being able to use a single CPU thread. Are there any options for increasing the amount of threads it can utilize for training?
     
  5. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    Same here, I have one CPU maxed out while others hardly do any work.
     
  6. haha1227

    haha1227

    Joined:
    Apr 1, 2022
    Posts:
    1
    I found the proper solution in this link:
    ML-Agents: Multiple environments (num-envs) - Unity Forum
    They said that's because "Pytorch is only configured to use 4 Threads at once" in ml-agents.
     
    mbaske likes this.
  7. Aleksander_Wit

    Aleksander_Wit

    Joined:
    Dec 13, 2020
    Posts:
    19
    Well, I have not seen any way I can make mlagents use more threads. At least for the most important process that also takes the vast bulk of the memory and seems to manage everything.

    I do use CUDA/GPU since it has performed better or almost identically without making my system hard to use while training. It does not utilize it fully either though. Either way, I would be interested in finding a way to make that main process use more cores, if that is even possible at the moment.

    I am not remotely step/experience constrained which has usually been the argument for not having to bother with increasing threads for python/mlagents. I can get 100k expereiences in a minute though so that is not a bottleneck and I could greatly increase the scale of that.