[Solved] How to run mlagents dedicated server?

I want to train mlagents on a headless Ubuntu server. I have an mlagents Unity front-end that works ok on my laptop. So, I run mlagents-learn, then press ‘Play’ on Unity editor, and everything works. However, if I build as ‘dedicated’ server, start mlagents-learn, then run the dedicated server, the mlagents-learn does not receive a connection.

How to get a dedicated server to connect ok with mlagents-learn? Alternatively, waht is the standard approach for training on a headless Ubuntu server?

(Note that if I build as a non-dedicated player, the scene starts, but still does not connect with the python side. If I just run from the editor, on Mac, then everything does work ok)

Also, if I remove the Heuristic method, then I get warnings in the output:

Heuristic method called but not implemented. Returning placeholder actions.

Seems like something is failing to attempt to communicate wih the python, and just switches to heuristic mode somehow? Some input manager or something?

Added the following code to my agent:

protected override void Awake() {
Debug.Log("player awake");
Debug.Log($"commreg {CommunicatorFactory.CommunicatorRegistered}");
Debug.Log($"enabled {CommunicatorFactory.Enabled}");
CommunicatorFactory.Enabled = true;
Debug.Log($"enabled {CommunicatorFactory.Enabled}");
Debug.Log($"academy init? {Academy.IsInitialized}");
Debug.Log($"academy comms? {Academy.Instance.IsCommunicatorOn}");
base.Awake();
}

Output is:

player awake
commreg False
enabled True
enabled True
academy init? False
Registered Communicator in Academy.
academy comms? False

So, this is starting to suggest that the communiator is disabled in player mode? Any way to enable it? Any way to confirm definitively that it is/isn’t available in player? (I guess I could check the source code…)

Alright, so digging through the code turns up that port is being set to -1. Digging a bit further shows that one can set that on the commandline using --mlagents-port 5004. Howevr this throws up a native library not found error, on mac silicon:

port 5004
RpcCommunicator
created communicator Unity.MLAgents.RpcCommunicator
communicator not null
Unexpected exception when trying to initialize communication: System.IO.FileNotFoundException: Error loading native library. Not found in any of the possible locations: /Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/libgrpc_csharp_ext.x64.bundle,/Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle,/Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/../../runtimes/osx/native/libgrpc_csharp_ext.x64.bundle,/Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/../../../Plugins/libgrpc_csharp_ext.x64.bundle,/Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/../Plugins/libgrpc_csharp_ext.x64.bundle,/Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/../Plugins/x86_64/libgrpc_csharp_ext.x64.bundle,/Users/hugh/git/unity-priv/FoodMLAgents/Builds/macded/Data/Managed/../Plugins/x86/libgrpc_csharp_ext.x64.bundle
  at Grpc.Core.Internal.UnmanagedLibrary.FirstValidLibraryPath (System.String[] libraryPathAlternatives) [0x00042] in <2f154ad39ec14cfea604815989d96352>:0
  at Grpc.Core.Internal.UnmanagedLibrary..ctor (System.String[] libraryPathAlternatives) [0x00006] 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

Will try on ubuntu, since that’s my target anyway.

Ah, --mlagents-port 5004 was the solution :slight_smile:

1 Like