Unity ML-Agents's Python library gets stuck at creating gRPC server
Describe the bug
This issue occurs while training on a headless HPC cluster (which uses the Slurm scheduler). For context, both mlagents-learn and using the Python API directly (with gym wrapper) works well on a local machine, but when both of these training methods were used on a HPC cluster, the code gets stuck at the point when a gRPC server is created. This behaviour was consistent across both methods of interacting with the environment.
For convenience, the program gets stuck at self.server = grpc.server(ThreadPoolExecutor(max_workers=10)) in mlagents_envs > rpc_communicator.py. The full stack trace can be found below.
To Reproduce Steps to reproduce the behavior:
- Build (any) environment as a Linux executable, and push it to the HPC cluster.
- On the cluster, install all required dependencies (e.g., ML-Agents Python packages).
chmod +x <executable>on the cluster.- Submit job. This issue is reproducible regardless of how we choose to train the RL agent (either through
mlagents-learnor the Python API + gym wrapper). - When job gets executed, it gets stuck at the point where the gRPC server is created (refer to stack trace below). No exceptions are raised.
Console logs / stack traces
The following stack trace was obtained through the use of mlagents-learn to initiate the training process, followed by the py-spy dump --pid <pid> command to print out the stack trace.
Thread 36885 (active): "MainThread"
__init__ (grpc/_server.py:958)
create_server (grpc/_server.py:1003)
server (grpc/__init__.py:2064)
create_server (mlagents_envs/rpc_communicator.py:61)
__init__ (mlagents_envs/rpc_communicator.py:51)
_get_communicator (mlagents_envs/environment.py:252)
__init__ (mlagents_envs/environment.py:187)
create_unity_environment (mlagents/trainers/learn.py:175)
worker (mlagents/trainers/subprocess_env_manager.py:160)
run (multiprocessing/process.py:108)
_bootstrap (multiprocessing/process.py:315)
_launch (multiprocessing/popen_fork.py:75)
__init__ (multiprocessing/popen_fork.py:19)
_Popen (multiprocessing/context.py:277)
_Popen (multiprocessing/context.py:224)
start (multiprocessing/process.py:121)
create_worker (mlagents/trainers/subprocess_env_manager.py:285)
__init__ (mlagents/trainers/subprocess_env_manager.py:256)
run_training (mlagents/trainers/learn.py:98)
run_cli (mlagents/trainers/learn.py:246)
main (mlagents/trainers/learn.py:250)
<module> (mlagents-learn:8)
Environment (please complete the following information):
- Unity Version: Unity 2020.3.7f1
- OS + version: CentOS Linux 7 (Core)
- ML-Agents version: Release 18, v0.27.0 for both
mlagentsandmlagents-env - Torch version: 1.8.1
- Environment: Any
NOTE: We are unable to help reproduce bugs with custom environments. Please attempt to reproduce your issue with one of the example environments, or provide a minimal patch to one of the environments needed to reproduce the issue.
Given that your log shows it as hanging in grpc's server method, it seems unlikely that this would be ML-Agents related. Looking though grpc's init method called there, it's probably trying to call the C grpc library: https://github.com/grpc/grpc/blob/master/src/python/grpcio/grpc/_server.py#L955
I can suggest from personal experience trying to take a look at your networking -- specifically a look at your hostname and DNS and ensuring that you're able to resolve it/it exists in your /etc/hosts. That's not guaranteed to resolve your issue but you can at least rule it out. Ensure your IPv6 address is in /etc/hosts too.
edit:
A colleague pointed me at this issue which bares some similarities -- you might find the debugging advice in it more helpful: https://github.com/grpc/grpc/issues/24018
Thanks for the reply, and for the pointers! Since this problem is unrelated to ML-Agents, I shall close this issue.
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.