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
17.12k stars 4.15k forks source link

Unity couldn't connect to trainer on port 5004 on macOS 10.13 #5759

Closed xlla closed 2 years ago

xlla commented 2 years ago

Describe the bug I want to train hummingbird using ml-agents, I have launched trainer.

2022-06-25 01:33:49 INFO [environment.py:222] Listening on port 5004. Start training by pressing the Play button in the Unity Editor.

but Unity pop up a message on status bar, said "Couldn't connect to trainer on port 5004 using API version 1.5.0. ". I can telnet into localhost 5004, so the server is ready.

To Reproduce Steps to reproduce the behavior:

  1. Go to this hummingbird tutorial
  2. follow the course, execute

mlagents-learn config/trainer_config.yaml --run-id hb_01

  1. activate Unity project, click start button.
  2. See error

Console logs / stack traces

In Unity Console, the detail messages is:

Unexpected exception when trying to initialize communication: System.IO.IOException: Error loading native library "/Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle"
  at Grpc.Core.Internal.UnmanagedLibrary..ctor (System.String[] libraryPathAlternatives) [0x00063] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.Internal.NativeExtension.Load () [0x000d7] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.Internal.NativeExtension..ctor () [0x00006] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.Internal.NativeExtension.Get () [0x00022] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.Internal.NativeMethods.Get () [0x00000] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.GrpcEnvironment.GrpcNativeInit () [0x00000] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.GrpcEnvironment..ctor () [0x0001e] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.GrpcEnvironment.AddRef () [0x00028] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.Channel..ctor (System.String target, Grpc.Core.ChannelCredentials credentials, System.Collections.Generic.IEnumerable`1[T] options) [0x00051] in <2f154ad39ec14cfea604815989d96352>:0 
  at Grpc.Core.Channel..ctor (System.String target, Grpc.Core.ChannelCredentials credentials) [0x00000] in <2f154ad39ec14cfea604815989d96352>:0 
  at Unity.MLAgents.RpcCommunicator.Initialize (System.Int32 port, Unity.MLAgents.CommunicatorObjects.UnityOutputProto unityOutput, Unity.MLAgents.CommunicatorObjects.UnityInputProto& unityInput) [0x00007] in /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs:224 
  at Unity.MLAgents.RpcCommunicator.Initialize (Unity.MLAgents.CommunicatorInitParameters initParameters, Unity.MLAgents.UnityRLInitParameters& initParametersOut) [0x0003b] in /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs:112 
UnityEngine.Debug:Log (object)
Unity.MLAgents.RpcCommunicator:Initialize (Unity.MLAgents.CommunicatorInitParameters,Unity.MLAgents.UnityRLInitParameters&) (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs:141)
Unity.MLAgents.Academy:InitializeEnvironment () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:452)
Unity.MLAgents.Academy:LazyInitialize () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:286)
Unity.MLAgents.Academy:.ctor () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:255)
Unity.MLAgents.Academy/<>c:<.cctor>b__86_0 () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:117)
System.Lazy`1<Unity.MLAgents.Academy>:get_Value ()
Unity.MLAgents.Academy:get_Instance () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:132)
Unity.MLAgents.Agent:LazyInitialize () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Agent.cs:456)
Unity.MLAgents.Agent:OnEnable () (at /Users/xlla/git/ml-agents/com.unity.ml-agents/Runtime/Agent.cs:370)

I have check the libgrpc_csharp_ext.x64.bundle, it's a fat binary format with arm64. Can I build it for my current macOS version? or how to debug it to find the failure reason? thanks for any hint.

file /Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle
/Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64]
/Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle (for architecture x86_64):  Mach-O 64-bit dynamically linked shared library x86_64
/Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle (for architecture arm64):   Mach-O 64-bit dynamically linked shared library arm64

Screenshots

Environment (please complete the following information):

xlla commented 2 years ago

I found the reason that libgrpc_csharp_ext.dylib can't be load, it reference to a non-exist lib.

otool -L /Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle
/Users/xlla/git/ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle:
    /Users/christophergoy/code/ml-agents-grpc/cmake/build/libgrpc_csharp_ext.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)
    /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)

So, where can I found this lib "/Users/christophergoy/code/ml-agents-grpc/cmake/build/libgrpc_csharp_ext.dylib", or how can I build it for use?

AKemendo commented 2 years ago

Do you happen to have an M1?

If so you may be able to install libgrpc_csharp_ext.dylib manually with this: https://github.com/einari/Grpc.Core.M1

If not we'll have to look at different solutions

xlla commented 2 years ago

hi @AKemendo , I am using x86_64 arch apple. I'd like to build that lib from source, but I don't where the source code based on and which version it depend on.

xlla commented 2 years ago

I'v manage to built the libgrpc_csharp_ext.dylib for x86_64 arch and rename it to

ml-agents/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle

it works now.

github-actions[bot] commented 2 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.