Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xlla opened this issue Jun 24, 2022 · 5 comments
Closed

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

xlla opened this issue Jun 24, 2022 · 5 comments
Assignees
Labels
bug Issue describes a potential bug in ml-agents.

Comments

@xlla
Copy link

xlla commented Jun 24, 2022

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):

  • Unity Version: 2021.1.28f1
  • OS + version: macos high sierra, 10.13.6
  • ML-Agents version: latest 71b121c main branch from source)
  • Torch version: Version: 1.11.0a0+git967238d
  • Environment:
@xlla xlla added the bug Issue describes a potential bug in ml-agents. label Jun 24, 2022
@xlla
Copy link
Author

xlla commented Jun 24, 2022

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
Copy link

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

@AKemendo AKemendo self-assigned this Jun 24, 2022
@xlla
Copy link
Author

xlla commented Jun 25, 2022

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
Copy link
Author

xlla commented Jul 3, 2022

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.

@xlla xlla closed this as completed Jul 3, 2022
@github-actions
Copy link

github-actions bot commented Aug 2, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue describes a potential bug in ml-agents.
Projects
None yet
Development

No branches or pull requests

2 participants