How can i use Ml-Agents training on my CPU?

Hi, I have a problem with agent training. I wrote the command mlagents-learn config / ppo / 3DBall.yaml --run-id = first3DBallRun in the console, but the training did not start and an error occurred.

Version information:
ml-agents: 0.27.0,
ml-agents-envs: 0.27.0,
Communicator API: 1.5.0,
PyTorch: 1.7.1+cu110
C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\torch\cuda\__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at ..\c10\cuda\CUDAFunctions.cpp:100.)
return torch._C._cuda_getDeviceCount() > 0
[INFO] Listening on port 5004. Start training by pressing the Play button in the Unity Editor.
Traceback (most recent call last):
File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\Scripts\mlagents-learn.exe\__main__.py", line 7, in <module>
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\learn.py", line 250, in main
run_cli(parse_command_line())
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\learn.py", line 246, in run_cli
run_training(run_seed, options)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\learn.py", line 125, in run_training
tc.start_learning(env_manager)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents_envs\timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\trainer_controller.py", line 173, in start_learning
self._reset_env(env_manager)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents_envs\timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\trainer_controller.py", line 105, in _reset_env
env_manager.reset(config=new_config)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\env_manager.py", line 68, in reset
self.first_step_infos = self._reset_env(config)
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\subprocess_env_manager.py", line 333, in _reset_env
ew.previous_step = EnvironmentStep(ew.recv().payload, ew.worker_id, {}, {})
File "C:\Users\Admin\AppData\Roaming\Python\Python39\site-packages\mlagents\trainers\subprocess_env_manager.py", line 98, in recv
raise env_exception
mlagents_envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
The environment does not need user interaction to launch
The Agents' Behavior Parameters > Behavior Type is set to "Default"
The environment and the Python interface have compatible versions.

As I understand it, I need to install the NVIDIA drivers.

But my laptop has the following GPU installed:
7332829--890911--image.PNG

Therefore, I thought that I would not be able to train agents on my GPU. But I don't know how to train them on my CPU.

Are there any options for solving this problem?

You should be able to train on CPU. I think the Unity environment isn't starting. Does a little window pop up with some agents in it?

Actually just re-read your post. You'll need to open the Unity editor and hit the play button shortly after running the python command.

I have the same problem

this is a 1.5 year old thread :smile: The versions of torch and everything are likely completely different. I feel you might consider creating a brand new thread tbh, but at a minimum share full details of your own problem, similar to the original poster, but for your own machine and environment now.

1 Like

I am new to this platform and dont know how to make a new thread

I am trying to train the 3D Ball environment in Unity but according to the guide it only trains with GPU

This is the guide im using: https://github.com/Unity-Technologies/ml-agents/blob/develop/docs/Getting-Started.md

This is the command I run: mlagents-learn config/ppo/3DBall.yaml --run-id=first3DBallRun

This is the error Im getting:

C:\Users\hussa\python-envs\sample-env\lib\site-packages\torch\cuda_init_.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at ..\c10\cuda\CUDAFunctions.cpp:100.)
return torch._C._cuda_getDeviceCount() > 0
Traceback (most recent call last):
File "C:\Users\hussa\python-envs\sample-env\lib\site-packages\mlagents\trainers\cli_utils.py", line 306, in load_config
with open(config_path) as data_file:
FileNotFoundError: [Errno 2] No such file or directory: 'config/ppo/3DBall.yaml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hussa\python-envs\sample-env\Scripts\mlagents-learn-script.py", line 33, in
sys.exit(load_entry_point('mlagents==0.30.0', 'console_scripts', 'mlagents-learn')())
File "C:\Users\hussa\python-envs\sample-env\lib\site-packages\mlagents\trainers\learn.py", line 264, in main
run_cli(parse_command_line())
File "C:\Users\hussa\python-envs\sample-env\lib\site-packages\mlagents\trainers\learn.py", line 56, in parse_command_line
return RunOptions.from_argparse(args)
File "C:\Users\hussa\python-envs\sample-env\lib\site-packages\mlagents\trainers\settings.py", line 899, in from_argparse
configured_dict.update(load_config(config_path))
File "C:\Users\hussa\python-envs\sample-env\lib\site-packages\mlagents\trainers\cli_utils.py", line 310, in load_config
raise TrainerConfigError(f"Config file could not be found at {abs_path}.")
mlagents.trainers.exception.TrainerConfigError: Config file could not be found at C:\Users\hussa\python-envs\sample-env\Scripts\config\ppo\3DBall.yaml.

If you look at the last line of the error, you can see it is not finding the config file 3DBall.yaml.

You can find that file here https://github.com/Unity-Technologies/ml-agents/tree/develop/config/ppo

I already have this file from the github repo that I cloned. Does it have to be in that location specified in the error?

This is the github repo i cloned:
git clone --branch release_19 https://github.com/Unity-Technologies/ml-agents.git

and I guess the problem is that it requires a GPU to be trained, dont you think so?

and I guess the problem is that it requires a GPU to be trained, dont you think so?

That's not what the error message says. And no, GPU is not required, to use mlagents.

I already have this file from the github repo that I cloned. Does it have to be in that location specified in the error?

Yup. Or give the correct full path to where it really is, on the commandline.

yep you were right, thanks for all the help it works now

1 Like

I try to follow a tutorial by Code Monkey. It all worked until i had to test it. I wrote "mlagents-learn --resume" in cmd and pressed play in unity... Then this error came up. Anyone who can help me?

[WARNING] Trainer has no policies, not saving anything.
Traceback (most recent call last):
File "C:\Users\Jacob\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in run_module_as_main
"
main", mod_spec)
File "C:\Users\Jacob\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\Unity\MachineLearning_1\venv\Scripts\mlagents-learn.exe__main
.py", line 7, in
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\learn.py", line 260, in main
run_cli(parse_command_line())
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\learn.py", line 256, in run_cli
run_training(run_seed, options, num_areas)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\learn.py", line 132, in run_training
tc.start_learning(env_manager)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 173, in start_learning
self._reset_env(env_manager)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 107, in _reset_env
self._register_new_behaviors(env_manager, env_manager.first_step_infos)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 268, in _register_new_behaviors
self._create_trainers_and_managers(env_manager, new_behavior_ids)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 166, in _create_trainers_and_managers
self._create_trainer_and_manager(env_manager, behavior_id)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 140, in _create_trainer_and_manager
create_graph=True,
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\trainer\rl_trainer.py", line 119, in create_policy
return self.create_torch_policy(parsed_behavior_id, behavior_spec)
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\ppo\trainer.py", line 232, in create_torch_policy
separate_critic=True, # Match network architecture with TF
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\policy\torch_policy.py", line 48, in __init
_
GlobalSteps()
File "e:\unity\machinelearning_1\venv\lib\site-packages\mlagents\trainers\torch\networks.py", line 737, in init
torch.Tensor([0]).to(torch.int64), requires_grad=False
RuntimeError: CUDA error: no kernel image is available for execution on the device