Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
16.93k stars 4.14k forks source link

Flag to force training with CPU #2751

Closed caioc2 closed 4 years ago

caioc2 commented 4 years ago

Hi,

When using visual observations and big batch size GPU's make a lot of sense and improve the training speed considerably, in the other hand, when using vector observations with small batch size (ie 32 and alike) using GPU can make it a lot slower than CPU.

Currently, as far as I know, you cant select which device (CPU/GPU) you want to use for training, either you have to install the tensorflow with/out GPU, disable your GPU to use CPU only or create multiple environments each one with the desired configuration.

It could be made easier by adding for example a flag "--cpu" to the ml-agents for using CPU only.

So far I've been using my hackish solution on the "learn.py" file like the following:

parser.add_argument( "--cpu", default=False, action="store_true", help="Run with CPU only", )

if options.cpu: os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

It get the job done without needing seriously changes to code, if it can be useful for other people I would like to see something like this in the ml-agents.

Thanks.

chriselion commented 4 years ago

Hi @caioc2, Thanks for the feedback. I'll log it as a feature request, but if you want to submit a pull request with the change, I can try to get it merged in.

As a side note, does running with CUDA_VISIBLE_DEVICES=-1 mlagents-learn ... work too?

caioc2 commented 4 years ago

I could not run with CUDA_VISIBLE_DEVICES=-1 mlagents-learn but probably one can set in another way, the only drawback is this variable may not be known by many people (I didn't know about it until now), while the flag is easier and would be in the documentation about training.

Anyway, I made the pull request.

github-actions[bot] commented 3 years ago

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.