运行环境
- Anaconda 4.12.0
- Python 3.6.13
- Pytorch 1.10.2
- Ray 1.10.0
- mlagents 0.28.0
- mpi4py 3.0.3
问题描述
在运行多进程并行训练时,Unity会有如下报错,此时程序卡死
"The Unity environment took too long to respond. Make sure that :\n"
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.
If you're running on a headless server without graphics support, turn off display by either passing --no-graphics option or build your Unity executable as server build.
怀疑有可能是没有关闭图形造成的.
解决方案
修改unity3d_env.py
文件,目录在:anaconda3/envs/<env_name>/lib/python3.6/site-packages/ray/rllib/env/wrappers/unity3d_env.py
.
def __init__(self,
file_name: str = None,
port: Optional[int] = None,
seed: int = 0,
no_graphics: bool = True,
timeout_wait: int = 500,
episode_horizon: int = 1000):
- 修改
no_graphics
为no_graphics: bool = True
,关闭图形输出 - 修改
timeout_wait
,适当增加超时等待时间 - 检查端口号是否被占用!!!