diff --git a/.yamato/training-backcompat-tests.yml b/.yamato/training-backcompat-tests.yml index b9ead7a8db..674226ce4c 100644 --- a/.yamato/training-backcompat-tests.yml +++ b/.yamato/training-backcompat-tests.yml @@ -1,19 +1,19 @@ -test_mac_backcompat_2020.1: - {% capture editor_version %}2020.1{% endcapture %} +test_mac_backcompat_2019.4: + {% capture editor_version %}2019.4{% endcapture %} {% capture csharp_backcompat_version %}1.0.0{% endcapture %} # This test has to run on mac because it requires the custom build of tensorflow without AVX # Test against 2020.1 because 2020.2 has to run against package version 1.2.0 name: Test Mac Backcompat Training {{ editor_version }} agent: type: Unity::VM::osx - image: ml-agents/ml-agents-bokken-mac:0.1.4-492264 + image: ml-agents/ml-agents-bokken-mac:0.1.5-853758 flavor: b1.small variables: UNITY_VERSION: {{ editor_version }} commands: - | - python3 -m venv venv && source venv/bin/activate + python -m venv venv && source venv/bin/activate python -m pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple python -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade unity-downloader-cli -u {{ editor_version }} -c editor --wait --fast @@ -23,9 +23,9 @@ test_mac_backcompat_2020.1: python -u -m ml-agents.tests.yamato.standalone_build_tests --build-target=mac python -u -m ml-agents.tests.yamato.training_int_tests --csharp {{ csharp_backcompat_version }} - | - python3 -m venv venv_old && source venv_old/bin/activate + python -m venv venv_old && source venv_old/bin/activate python -m pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple - python -u -m ml-agents.tests.yamato.training_int_tests --python 0.16.0 + python -u -m ml-agents.tests.yamato.training_int_tests --python 0.24.0 triggers: cancel_old_ci: true recurring: diff --git a/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle b/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle index 58390e6cba..440d2b9e33 100755 Binary files a/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle and b/com.unity.ml-agents/Plugins/ProtoBuffer/runtimes/osx/native/libgrpc_csharp_ext.x64.bundle differ diff --git a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs index 2ae635efd8..8e6e211b1a 100644 --- a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs +++ b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs @@ -2,7 +2,7 @@ #define MLA_SUPPORTED_TRAINING_PLATFORM #endif -# if MLA_SUPPORTED_TRAINING_PLATFORM +#if MLA_SUPPORTED_TRAINING_PLATFORM using Grpc.Core; #if UNITY_EDITOR using UnityEditor; @@ -50,6 +50,7 @@ internal class RpcCommunicator : ICommunicator /// The Unity to External client. UnityToExternalProto.UnityToExternalProtoClient m_Client; + Channel m_Channel; /// /// Initializes a new instance of the RPCCommunicator class. @@ -140,6 +141,7 @@ out input Debug.Log($"Unexpected exception when trying to initialize communication: {ex}"); } initParametersOut = new UnityRLInitParameters(); + NotifyQuitAndShutDownChannel(); return false; } @@ -181,6 +183,8 @@ out input UpdateEnvironmentWithInput(input.RlInput); initParametersOut = initializationInput.RlInitializationInput.ToUnityRLInitParameters(); + // Be sure to shut down the grpc channel when the application is quitting. + Application.quitting += NotifyQuitAndShutDownChannel; return true; #else initParametersOut = new UnityRLInitParameters(); @@ -217,9 +221,9 @@ void UpdateEnvironmentWithInput(UnityRLInputProto rlInput) UnityInputProto Initialize(int port, UnityOutputProto unityOutput, out UnityInputProto unityInput) { m_IsOpen = true; - var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure); + m_Channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure); - m_Client = new UnityToExternalProto.UnityToExternalProtoClient(channel); + m_Client = new UnityToExternalProto.UnityToExternalProtoClient(m_Channel); var result = m_Client.Exchange(WrapMessage(unityOutput, 200)); var inputMessage = m_Client.Exchange(WrapMessage(null, 200)); unityInput = inputMessage.UnityInput; @@ -229,11 +233,24 @@ UnityInputProto Initialize(int port, UnityOutputProto unityOutput, out UnityInpu if (result.Header.Status != 200 || inputMessage.Header.Status != 200) { m_IsOpen = false; - QuitCommandReceived?.Invoke(); + NotifyQuitAndShutDownChannel(); } return result.UnityInput; } + void NotifyQuitAndShutDownChannel() + { + QuitCommandReceived?.Invoke(); + try + { + m_Channel.ShutdownAsync().Wait(); + } + catch (Exception) + { + // do nothing + } + } + #endregion #region Destruction @@ -269,7 +286,7 @@ void SendCommandEvent(CommandProto command) { case CommandProto.Quit: { - QuitCommandReceived?.Invoke(); + NotifyQuitAndShutDownChannel(); return; } case CommandProto.Reset: @@ -456,7 +473,7 @@ UnityInputProto Exchange(UnityOutputProto unityOutput) // Not sure if the quit command is actually sent when a // non 200 message is received. Notify that we are indeed // quitting. - QuitCommandReceived?.Invoke(); + NotifyQuitAndShutDownChannel(); return message.UnityInput; } catch (Exception ex) @@ -488,7 +505,7 @@ UnityInputProto Exchange(UnityOutputProto unityOutput) } m_IsOpen = false; - QuitCommandReceived?.Invoke(); + NotifyQuitAndShutDownChannel(); return null; } } diff --git a/ml-agents/tests/yamato/training_int_tests.py b/ml-agents/tests/yamato/training_int_tests.py index 3797738182..8678c166d7 100644 --- a/ml-agents/tests/yamato/training_int_tests.py +++ b/ml-agents/tests/yamato/training_int_tests.py @@ -5,7 +5,6 @@ import sys import subprocess import time -from typing import Any from .yamato_utils import ( find_executables, @@ -14,7 +13,6 @@ run_standalone_build, init_venv, override_config_file, - override_legacy_config_file, checkout_csharp_version, undo_git_checkout, ) @@ -26,7 +24,7 @@ def run_training(python_version: str, csharp_version: str) -> bool: print( f"Running training with python={python_version or latest} and c#={csharp_version or latest}" ) - output_dir = "models" if python_version else "results" + output_dir = "results" onnx_file_expected = f"./{output_dir}/{run_id}/3DBall.onnx" if os.path.exists(onnx_file_expected): @@ -70,17 +68,11 @@ def run_training(python_version: str, csharp_version: str) -> bool: # Copy the default training config but override the max_steps parameter, # and reduce the batch_size and buffer_size enough to ensure an update step happens. yaml_out = "override.yaml" - if python_version: - overrides: Any = {"max_steps": 100, "batch_size": 10, "buffer_size": 10} - override_legacy_config_file( - python_version, "config/trainer_config.yaml", yaml_out, **overrides - ) - else: - overrides = { - "hyperparameters": {"batch_size": 10, "buffer_size": 10}, - "max_steps": 100, - } - override_config_file("config/ppo/3DBall.yaml", yaml_out, overrides) + overrides = { + "hyperparameters": {"batch_size": 10, "buffer_size": 10}, + "max_steps": 100, + } + override_config_file("config/ppo/3DBall.yaml", yaml_out, overrides) log_output_path = f"{get_base_output_path()}/training.log" env_path = os.path.join(get_base_output_path(), standalone_player_path) diff --git a/ml-agents/tests/yamato/yamato_utils.py b/ml-agents/tests/yamato/yamato_utils.py index 2302227db1..d81cdd34bb 100644 --- a/ml-agents/tests/yamato/yamato_utils.py +++ b/ml-agents/tests/yamato/yamato_utils.py @@ -134,13 +134,10 @@ def init_venv( pip_commands = ["--upgrade pip", "--upgrade setuptools"] if mlagents_python_version: # install from pypi - if platform != "darwin": - raise RuntimeError("Yamato can only run tensorflow on mac platforms!") pip_commands += [ f"mlagents=={mlagents_python_version}", f"gym-unity=={mlagents_python_version}", # TODO build these and publish to internal pypi - "~/tensorflow_pkg/tensorflow-2.0.0-cp37-cp37m-macosx_10_14_x86_64.whl", "tf2onnx==1.6.1", ] else: