Parallel Simulation
Hi Thanks for the great toolkit! I am currently working on developing physical agents for sports games. One thing that is very crucial in this field is the ability of multi-threaded simulation since a lot of algorithms are sampling-based. Is it possible in this toolkit to have multi-threaded simulation? If not, do you have any plan on adding this feature in the future? BTW, I hear that Mujoco physics engine authors are working on developing some interface for integrating Mujoco with Unity, and it's going to be released pretty soon. Having multi-threaded simulation on top of this can be really great.
Hi @donamin,
Thanks for your question. You are right that having an efficient multithreaded solution will be necessary for the highest performance. The 2018 version of Unity will be released with a new multi-threading job system, and we plan to eventually have ML-Agents use it. Currently the options for parallelization involve having multiple instances of your environment within a single unity scene and/or launching multiple instances of the Unity binary and collecting data from all of them simultaneously.
The Mujoco integration is something we are following ourselves, and are excited to see it as part of Unity too!
@awjuliani Could I ask you to explain how to set up using multiple instances of the envirornment? I have a game I'm training where it can't have several copies in one scene, but if I could use several instances of the game that'd be helpful!
@MDReptile did you get this working?
@Lakrix Unfortunately no
Currently the options for parallelization involve having multiple instances of your environment within a single unity scene @awjuliani
What are the steps for this? Is it simply creating multiple copies of the Academy + Brain + Agent(s) in a single scene or is there more to it?
Also I'm curious if you have any tips for general performance+speed gains during training, I'm currently trying to figure out what the performance bottlenecks are for ML Agents as I'm only able to utilize 5-15% of my CPU/GPU during training
You can look at the 3DBall example in the SDK for this. You only need one instance of the Academy and Brain. Make copies of the Agents (and the other environment objects) and have them all use the same Brain.
@jo3w4rd is there a formula for determining the upper limit of the number of instances of agents that would be useful to have in the environment?
For example, how can I tell if 10, or 100, or 1000 agents is enough / too much
I'll have to let @awjuliani answer the aspect of your question on what the optimal number of agents is for the machine learning algorithms.
On the Unity side, you won't be able to get 1000 agents to work in the current code because it takes too long to spin-up that many agents -- there's a bottleneck in the initialization code that isn't hard to fix, though. After removing that bottleneck, I am able to run a training session of the Balance Ball example with 1000 agents and it utilizes about 150% of my dual-core laptop.
@jo3w4rd whats the bottleneck in the init code? I'd really like to utilize more of my PC
It seems like there's also a bottleneck between the communication speed between tensorflow code and the unity simulation during training
I asked Arthur and he said
Between 8 and 64 simultaneous agents would be recommended, You would only want to provide information that the network could actually utilize for making decisions. The 64 limit is around trading-off data throughput: data points per step of simulation vs simulation steps per second.
There is a call to FindObjectOfType() to get a reference to the Academy in the Agent.OnEnable() function. This function is kind of slow and as a result it takes about 8 seconds to enable 1000 agents. The training process times out in less than 8 seconds. I fixed it temporarily by making the Academy a singleton and adding a static GetInstance() function, but I doubt that's the best long term fix.
And the training is very slow with the default hyperparameters, I guess since the data points per simulation is so much higher with that many agents.
Hi @donamin , thank you for the discussion! We are closing this issue due to inactivity. Feel free to reopen it if you’d like to continue to discussion though.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.