Search Unity

Resolved [Solved] How to run mlagents dedicated server?

Discussion in 'ML-Agents' started by hughperkins, Dec 27, 2022.

  1. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    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?
     
  2. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    (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)
     
  3. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    Also, if I remove the `Heuristic` method, then I get warnings in the output:

    Code (csharp):
    1.  
    2. Heuristic method called but not implemented. Returning placeholder actions.
    3.  
    Seems like something is failing to attempt to communicate wih the python, and just switches to heuristic mode somehow? Some input manager or something?
     
  4. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    Added the following code to my agent:

    Code (csharp):
    1.  
    2. protected override void Awake() {
    3. Debug.Log("player awake");
    4. Debug.Log($"commreg {CommunicatorFactory.CommunicatorRegistered}");
    5. Debug.Log($"enabled {CommunicatorFactory.Enabled}");
    6. CommunicatorFactory.Enabled = true;
    7. Debug.Log($"enabled {CommunicatorFactory.Enabled}");
    8. Debug.Log($"academy init? {Academy.IsInitialized}");
    9. Debug.Log($"academy comms? {Academy.Instance.IsCommunicatorOn}");
    10. base.Awake();
    11. }
    12.  
    Output is:
    Code (csharp):
    1.  
    2. player awake
    3. commreg False
    4. enabled True
    5. enabled True
    6. academy init? False
    7. Registered Communicator in Academy.
    8. academy comms? False
    9.  
    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...)
     
  5. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    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:

    Code (csharp):
    1.  
    2. port 5004
    3. RpcCommunicator
    4. created communicator Unity.MLAgents.RpcCommunicator
    5. communicator not null
    6. 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
    7.   at Grpc.Core.Internal.UnmanagedLibrary.FirstValidLibraryPath (System.String[] libraryPathAlternatives) [0x00042] in <2f154ad39ec14cfea604815989d96352>:0
    8.   at Grpc.Core.Internal.UnmanagedLibrary..ctor (System.String[] libraryPathAlternatives) [0x00006] in <2f154ad39ec14cfea604815989d96352>:0
    9.   at Grpc.Core.Internal.NativeExtension.Load () [0x000d7] in <2f154ad39ec14cfea604815989d96352>:0
    10.   at Grpc.Core.Internal.NativeExtension..ctor () [0x00006] in <2f154ad39ec14cfea604815989d96352>:0
    11.   at Grpc.Core.Internal.NativeExtension.Get () [0x00022] in <2f154ad39ec14cfea604815989d96352>:0
    12.   at Grpc.Core.Internal.NativeMethods.Get () [0x00000] in <2f154ad39ec14cfea604815989d96352>:0
    13.   at Grpc.Core.GrpcEnvironment.GrpcNativeInit () [0x00000] in <2f154ad39ec14cfea604815989d96352>:0
    14.   at Grpc.Core.GrpcEnvironment..ctor () [0x0001e] in <2f154ad39ec14cfea604815989d96352>:0
    15.   at Grpc.Core.GrpcEnvironment.AddRef () [0x00028] in <2f154ad39ec14cfea604815989d96352>:0
    16.  
    Will try on ubuntu, since that's my target anyway.
     
  6. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    Ah, `--mlagents-port 5004` was the solution :)

    Screen Shot 2022-12-27 at 11.36.33 AM.png
     
    GamerLordMat likes this.