Skip to content

Commit 30be112

Browse files
maryamhonarijmercado1985vincentpierreRuo-Ping Dongjrupert-unity
authored
2.0.1 verified patch (#5605)
* update package version from 2.0.0 to 2.0.1 * Update README.md with new survey link(#5500) (#5585) Co-authored-by: jmercado1985 <[email protected]> * [Cherry-pick for 2.0.1 verified patch] default analytics channel (#5511) (#5584) * update changelog from #5511 * set gym=0.20.0 #5540, update changelog * Cap cattrs version for now(#5397) * clean up Co-authored-by: Vincent-Pierre BERGES <[email protected]> Co-authored-by: Ruo-Ping Dong <[email protected]> * Cherry picking #5283 and #5519 into 2.0.1-verified-patch to fix gRPC for mac m1 (MLA 2259) (#5602) * Only update the native library and the c# calls that need to be made to clean up channels. (#5283) * Fix Mac backcompat test (#5519) Co-authored-by: Chris Goy <[email protected]> * [Cherry-pick for 2.0.1 verified patch]Harden user PII in analytics (#5512) harden analytics (#5604) * Harden user PII protection logic and extend TrainingAnalytics to expose detailed configuration parameters. (#5512) * Hash128 is not a cryptographic hash, replace with HMAC-SHA256. * Extend TrainingAnalytics side channel to expose configuration details * Change member function scopes and hash demo_paths * Extract tbiEvent hashing method and add test coverage * Fixing the analytics side-channel for curriculum learning. (#5586) * Fixing the analytics side-channel for curriculum learning. * Made a more robust test. * Update the changelog. * Update com.unity.ml-agents/CHANGELOG.md Co-authored-by: Maryam Honari <[email protected]> Co-authored-by: Maryam Honari <[email protected]> * update CHANGELOG Co-authored-by: Jason Bowman <[email protected]> Co-authored-by: jmercado1985 <[email protected]> Co-authored-by: Vincent-Pierre BERGES <[email protected]> Co-authored-by: Ruo-Ping Dong <[email protected]> Co-authored-by: Jason Rupert <[email protected]> Co-authored-by: Chris Goy <[email protected]> Co-authored-by: Jason Bowman <[email protected]>
1 parent 3d77eed commit 30be112

File tree

31 files changed

+527
-170
lines changed

31 files changed

+527
-170
lines changed

.yamato/training-backcompat-tests.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

2-
test_mac_backcompat_2020.1:
3-
{% capture editor_version %}2020.1{% endcapture %}
2+
test_mac_backcompat_2019.4:
3+
{% capture editor_version %}2019.4{% endcapture %}
44
{% capture csharp_backcompat_version %}1.0.0{% endcapture %}
55
# This test has to run on mac because it requires the custom build of tensorflow without AVX
66
# Test against 2020.1 because 2020.2 has to run against package version 1.2.0
77
name: Test Mac Backcompat Training {{ editor_version }}
88
agent:
99
type: Unity::VM::osx
10-
image: ml-agents/ml-agents-bokken-mac:0.1.4-492264
10+
image: ml-agents/ml-agents-bokken-mac:0.1.5-853758
1111
flavor: b1.small
1212
variables:
1313
UNITY_VERSION: {{ editor_version }}
1414
commands:
1515
- |
16-
python3 -m venv venv && source venv/bin/activate
16+
python -m venv venv && source venv/bin/activate
1717
python -m pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
1818
python -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade
1919
unity-downloader-cli -u {{ editor_version }} -c editor --wait --fast
@@ -23,9 +23,9 @@ test_mac_backcompat_2020.1:
2323
python -u -m ml-agents.tests.yamato.standalone_build_tests --build-target=mac
2424
python -u -m ml-agents.tests.yamato.training_int_tests --csharp {{ csharp_backcompat_version }}
2525
- |
26-
python3 -m venv venv_old && source venv_old/bin/activate
26+
python -m venv venv_old && source venv_old/bin/activate
2727
python -m pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
28-
python -u -m ml-agents.tests.yamato.training_int_tests --python 0.16.0
28+
python -u -m ml-agents.tests.yamato.training_int_tests --python 0.24.0
2929
triggers:
3030
cancel_old_ci: true
3131
recurring:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ package by replying to
174174
Your opinion matters a great deal to us. Only by hearing your thoughts on the
175175
Unity ML-Agents Toolkit can we continue to improve and grow. Please take a few
176176
minutes to
177-
[let us know about it](https://github.com/Unity-Technologies/ml-agents/issues/1454).
177+
[let us know about it](https://unitysoftware.co1.qualtrics.com/jfe/form/SV_55pQKCZ578t0kbc).
178178

179179
For any other questions or feedback, connect directly with the ML-Agents team at
180180

com.unity.ml-agents.extensions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"unity": "2019.4",
66
"description": "A source-only package for new features based on ML-Agents",
77
"dependencies": {
8-
"com.unity.ml-agents": "2.0.0",
8+
"com.unity.ml-agents": "2.0.1",
99
"com.unity.modules.physics": "1.0.0"
1010
}
1111
}

com.unity.ml-agents/CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this package will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
8+
## [2.0.1] - 2021-10-13
9+
### Minor Changes
10+
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
11+
- Upgrade to 2.0.1
12+
- Update gRPC native lib to universal for arm64 and x86_64. This change should enable ml-agents usage on mac M1 (#5283, #5519)
13+
#### ml-agents / ml-agents-envs / gym-unity (Python)
14+
- Set gym version in gym-unity to gym release 0.20.0(#5540)
15+
- Harden user PII protection logic and extend TrainingAnalytics to expose detailed configuration parameters. (#5512)
16+
- Added minimal analytics collection to LL-API (#5511)
17+
18+
### Bug Fixes
19+
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
20+
- Fixed the bug where curriculum learning would crash because of the incorrect run_options parsing. (#5586)
21+
#### ml-agents / ml-agents-envs / gym-unity (Python)
822

923
## [2.0.0] - 2021-09-01
1024
### Minor Changes

com.unity.ml-agents/Runtime/Academy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class Academy : IDisposable
107107
/// Unity package version of com.unity.ml-agents.
108108
/// This must match the version string in package.json and is checked in a unit test.
109109
/// </summary>
110-
internal const string k_PackageVersion = "2.0.0";
110+
internal const string k_PackageVersion = "2.0.1";
111111

112112
const int k_EditorTrainingPort = 5004;
113113

com.unity.ml-agents/Runtime/Analytics/AnalyticsUtils.cs

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
using System;
2+
using System.Text;
3+
using System.Security.Cryptography;
24
using UnityEngine;
35

46
namespace Unity.MLAgents.Analytics
57
{
8+
69
internal static class AnalyticsUtils
710
{
11+
/// <summary>
12+
/// Conversion function from byte array to hex string
13+
/// </summary>
14+
/// <param name="array"></param>
15+
/// <returns>A byte array to be hex encoded.</returns>
16+
private static string ToHexString(byte[] array)
17+
{
18+
StringBuilder hex = new StringBuilder(array.Length * 2);
19+
foreach (byte b in array)
20+
{
21+
hex.AppendFormat("{0:x2}", b);
22+
}
23+
return hex.ToString();
24+
}
25+
826
/// <summary>
927
/// Hash a string to remove PII or secret info before sending to analytics
1028
/// </summary>
11-
/// <param name="s"></param>
12-
/// <returns>A string containing the Hash128 of the input string.</returns>
13-
public static string Hash(string s)
29+
/// <param name="key"></param>
30+
/// <returns>A string containing the key to be used for HMAC encoding.</returns>
31+
/// <param name="value"></param>
32+
/// <returns>A string containing the value to be encoded.</returns>
33+
public static string Hash(string key, string value)
1434
{
15-
var behaviorNameHash = Hash128.Compute(s);
16-
return behaviorNameHash.ToString();
35+
string hash;
36+
UTF8Encoding encoder = new UTF8Encoding();
37+
using (HMACSHA256 hmac = new HMACSHA256(encoder.GetBytes(key)))
38+
{
39+
Byte[] hmBytes = hmac.ComputeHash(encoder.GetBytes(value));
40+
hash = ToHexString(hmBytes);
41+
}
42+
return hash;
1743
}
1844

1945
internal static bool s_SendEditorAnalytics = true;

com.unity.ml-agents/Runtime/Analytics/Events.cs

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ internal struct TrainingEnvironmentInitializedEvent
156156
public string TorchDeviceType;
157157
public int NumEnvironments;
158158
public int NumEnvironmentParameters;
159+
public string RunOptions;
159160
}
160161

161162
[Flags]
@@ -188,5 +189,6 @@ internal struct TrainingBehaviorInitializedEvent
188189
public string VisualEncoder;
189190
public int NumNetworkLayers;
190191
public int NumNetworkHiddenUnits;
192+
public string Config;
191193
}
192194
}

com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ IList<IActuator> actuators
156156
var inferenceEvent = new InferenceEvent();
157157

158158
// Hash the behavior name so that there's no concern about PII or "secret" data being leaked.
159-
inferenceEvent.BehaviorName = AnalyticsUtils.Hash(behaviorName);
159+
inferenceEvent.BehaviorName = AnalyticsUtils.Hash(k_VendorKey, behaviorName);
160160

161161
inferenceEvent.BarracudaModelSource = barracudaModel.IrSource;
162162
inferenceEvent.BarracudaModelVersion = barracudaModel.IrVersion;

com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,21 @@ internal static string ParseBehaviorName(string fullyQualifiedBehaviorName)
192192
return fullyQualifiedBehaviorName.Substring(0, lastQuestionIndex);
193193
}
194194

195+
internal static TrainingBehaviorInitializedEvent SanitizeTrainingBehaviorInitializedEvent(TrainingBehaviorInitializedEvent tbiEvent)
196+
{
197+
// Hash the behavior name if the message version is from an older version of ml-agents that doesn't do trainer-side hashing.
198+
// We'll also, for extra safety, verify that the BehaviorName is the size of the expected SHA256 hash.
199+
// Context: The config field was added at the same time as trainer side hashing, so messages including it should already be hashed.
200+
if (tbiEvent.Config.Length == 0 || tbiEvent.BehaviorName.Length != 64)
201+
{
202+
tbiEvent.BehaviorName = AnalyticsUtils.Hash(k_VendorKey, tbiEvent.BehaviorName);
203+
}
204+
205+
return tbiEvent;
206+
}
207+
195208
[Conditional("MLA_UNITY_ANALYTICS_MODULE")]
196-
public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent tbiEvent)
209+
public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent rawTbiEvent)
197210
{
198211
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
199212
if (!IsAnalyticsEnabled())
@@ -202,6 +215,7 @@ public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent
202215
if (!EnableAnalytics())
203216
return;
204217

218+
var tbiEvent = SanitizeTrainingBehaviorInitializedEvent(rawTbiEvent);
205219
var behaviorName = tbiEvent.BehaviorName;
206220
var added = s_SentTrainingBehaviorInitialized.Add(behaviorName);
207221

@@ -211,9 +225,7 @@ public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent
211225
return;
212226
}
213227

214-
// Hash the behavior name so that there's no concern about PII or "secret" data being leaked.
215228
tbiEvent.TrainingSessionGuid = s_TrainingSessionGuid.ToString();
216-
tbiEvent.BehaviorName = AnalyticsUtils.Hash(tbiEvent.BehaviorName);
217229

218230
// Note - to debug, use JsonUtility.ToJson on the event.
219231
// Debug.Log(
@@ -236,7 +248,7 @@ IList<IActuator> actuators
236248
var remotePolicyEvent = new RemotePolicyInitializedEvent();
237249

238250
// Hash the behavior name so that there's no concern about PII or "secret" data being leaked.
239-
remotePolicyEvent.BehaviorName = AnalyticsUtils.Hash(behaviorName);
251+
remotePolicyEvent.BehaviorName = AnalyticsUtils.Hash(k_VendorKey, behaviorName);
240252

241253
remotePolicyEvent.TrainingSessionGuid = s_TrainingSessionGuid.ToString();
242254
remotePolicyEvent.ActionSpec = EventActionSpec.FromActionSpec(actionSpec);

com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ internal static TrainingEnvironmentInitializedEvent ToTrainingEnvironmentInitial
501501
TorchDeviceType = inputProto.TorchDeviceType,
502502
NumEnvironments = inputProto.NumEnvs,
503503
NumEnvironmentParameters = inputProto.NumEnvironmentParameters,
504+
RunOptions = inputProto.RunOptions,
504505
};
505506
}
506507

@@ -530,6 +531,7 @@ internal static TrainingBehaviorInitializedEvent ToTrainingBehaviorInitializedEv
530531
VisualEncoder = inputProto.VisualEncoder,
531532
NumNetworkLayers = inputProto.NumNetworkLayers,
532533
NumNetworkHiddenUnits = inputProto.NumNetworkHiddenUnits,
534+
Config = inputProto.Config,
533535
};
534536
}
535537

com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs

+24-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define MLA_SUPPORTED_TRAINING_PLATFORM
33
#endif
44

5-
# if MLA_SUPPORTED_TRAINING_PLATFORM
5+
#if MLA_SUPPORTED_TRAINING_PLATFORM
66
using Grpc.Core;
77
#if UNITY_EDITOR
88
using UnityEditor;
@@ -50,6 +50,7 @@ internal class RpcCommunicator : ICommunicator
5050

5151
/// The Unity to External client.
5252
UnityToExternalProto.UnityToExternalProtoClient m_Client;
53+
Channel m_Channel;
5354

5455
/// <summary>
5556
/// Initializes a new instance of the RPCCommunicator class.
@@ -140,6 +141,7 @@ out input
140141
Debug.Log($"Unexpected exception when trying to initialize communication: {ex}");
141142
}
142143
initParametersOut = new UnityRLInitParameters();
144+
NotifyQuitAndShutDownChannel();
143145
return false;
144146
}
145147

@@ -181,6 +183,8 @@ out input
181183

182184
UpdateEnvironmentWithInput(input.RlInput);
183185
initParametersOut = initializationInput.RlInitializationInput.ToUnityRLInitParameters();
186+
// Be sure to shut down the grpc channel when the application is quitting.
187+
Application.quitting += NotifyQuitAndShutDownChannel;
184188
return true;
185189
#else
186190
initParametersOut = new UnityRLInitParameters();
@@ -217,9 +221,9 @@ void UpdateEnvironmentWithInput(UnityRLInputProto rlInput)
217221
UnityInputProto Initialize(int port, UnityOutputProto unityOutput, out UnityInputProto unityInput)
218222
{
219223
m_IsOpen = true;
220-
var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
224+
m_Channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
221225

222-
m_Client = new UnityToExternalProto.UnityToExternalProtoClient(channel);
226+
m_Client = new UnityToExternalProto.UnityToExternalProtoClient(m_Channel);
223227
var result = m_Client.Exchange(WrapMessage(unityOutput, 200));
224228
var inputMessage = m_Client.Exchange(WrapMessage(null, 200));
225229
unityInput = inputMessage.UnityInput;
@@ -229,11 +233,24 @@ UnityInputProto Initialize(int port, UnityOutputProto unityOutput, out UnityInpu
229233
if (result.Header.Status != 200 || inputMessage.Header.Status != 200)
230234
{
231235
m_IsOpen = false;
232-
QuitCommandReceived?.Invoke();
236+
NotifyQuitAndShutDownChannel();
233237
}
234238
return result.UnityInput;
235239
}
236240

241+
void NotifyQuitAndShutDownChannel()
242+
{
243+
QuitCommandReceived?.Invoke();
244+
try
245+
{
246+
m_Channel.ShutdownAsync().Wait();
247+
}
248+
catch (Exception)
249+
{
250+
// do nothing
251+
}
252+
}
253+
237254
#endregion
238255

239256
#region Destruction
@@ -269,7 +286,7 @@ void SendCommandEvent(CommandProto command)
269286
{
270287
case CommandProto.Quit:
271288
{
272-
QuitCommandReceived?.Invoke();
289+
NotifyQuitAndShutDownChannel();
273290
return;
274291
}
275292
case CommandProto.Reset:
@@ -456,7 +473,7 @@ UnityInputProto Exchange(UnityOutputProto unityOutput)
456473
// Not sure if the quit command is actually sent when a
457474
// non 200 message is received. Notify that we are indeed
458475
// quitting.
459-
QuitCommandReceived?.Invoke();
476+
NotifyQuitAndShutDownChannel();
460477
return message.UnityInput;
461478
}
462479
catch (Exception ex)
@@ -488,7 +505,7 @@ UnityInputProto Exchange(UnityOutputProto unityOutput)
488505
}
489506

490507
m_IsOpen = false;
491-
QuitCommandReceived?.Invoke();
508+
NotifyQuitAndShutDownChannel();
492509
return null;
493510
}
494511
}

0 commit comments

Comments
 (0)