浏览代码

[MLA-1981] Don't allow connections to newer python trainers (#5370)

/release_2_verified
GitHub 4 年前
当前提交
9c3b179a
共有 7 个文件被更改,包括 90 次插入13 次删除
  1. 4
      Project/Packages/manifest.json
  2. 2
      Project/ProjectSettings/ProjectVersion.txt
  3. 3
      com.unity.ml-agents/CHANGELOG.md
  4. 2
      com.unity.ml-agents/Documentation~/com.unity.ml-agents.md
  5. 54
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
  6. 6
      com.unity.ml-agents/Runtime/Constants.cs
  7. 32
      com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs

4
Project/Packages/manifest.json


"com.unity.analytics": "3.2.3",
"com.unity.collab-proxy": "1.2.15",
"com.unity.ml-agents": "file:../../com.unity.ml-agents",
"com.unity.package-manager-ui": "2.0.8",
"com.unity.package-manager-ui": "2.0.13",
"com.unity.purchasing": "2.0.3",
"com.unity.purchasing": "2.2.1",
"com.unity.textmeshpro": "1.4.1",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",

2
Project/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.4.17f1
m_EditorVersion: 2018.4.32f1

3
com.unity.ml-agents/CHANGELOG.md


### Bug Fixes
#### com.unity.ml-agents (C#)
- Fixed a null reference exception that occurred when loading an ONNX model file that was generated with a new
version of the Python trainer (0.26.0 or newer).
version of the Python trainer (0.26.0 or newer). (#5350)
- Added checked to prevent training with incompatible versions of the python trainer (0.26.0 or newer). (#5370)
## [1.0.7] - 2021-03-04
### Minor Changes

2
com.unity.ml-agents/Documentation~/com.unity.ml-agents.md


To install the companion Python package to enable training behaviors, follow the
[installation instructions] on our [GitHub repository]. It is strongly recommended that you
use the Python package that corresponds to this release (version 0.16.1) for the best experience;
versions between 0.16.1 and 0.20.0 are supported.
versions between 0.16.1 and 0.20.0 are supported. Versions after 0.25.1 cannot be used.
## Requirements

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.CommunicatorObjects;

internal static bool CheckPythonPackageVersionIsCompatible(string pythonLibraryVersion)
{
// Try to extract the numerical values from the pythonLibraryVersion, e.g. remove the ".dev0" suffix
var versionMatch = Regex.Match(pythonLibraryVersion, @"[0-9]+\.[0-9]+\.[0-9]");
if (versionMatch.Success)
{
pythonLibraryVersion = versionMatch.Value;
}
Version pythonVersion;
try
{

{
// Unparseable - this also catches things like "0.20.0-dev0" which we don't want to support
// Unparseable version.
// Anything like 0.42.0.dev0 should have been caught with the regex above, so anything here
// is totally bogus. For now, ignore these and let CheckPythonPackageVersionIsSupported handle it.
return true;
}
if (pythonVersion > PythonTrainerVersions.s_MaxCompatibleVersion)
{
return false;
}
return true;
}
/// <summary>
/// Check if the package is in the supported range. Note that some versions might be unsupported but
/// still compatible.
/// </summary>
/// <param name="pythonLibraryVersion"></param>
/// <returns></returns>
internal static bool CheckPythonPackageVersionIsSupported(string pythonLibraryVersion)
{
Version pythonVersion;
try
{
pythonVersion = new Version(pythonLibraryVersion);
}
catch
{
// Unparseable - this also catches things like "0.20.0.dev0" which we don't want to support
return false;
}

throw new UnityAgentsException("ICommunicator.Initialize() failed.");
}
var packageVersionSupported = CheckPythonPackageVersionIsCompatible(pythonPackageVersion);
var packageVersionCompatible = CheckPythonPackageVersionIsCompatible(pythonPackageVersion);
if (!packageVersionCompatible)
{
Debug.LogErrorFormat(
"Python package version ({0}) will produce model files that are incompatible with this " +
"version of the com.unity.ml-agents Unity package. Please downgrade to a Python package " +
"between {1} and {2}, or update to a new version of com.unity.ml-agents.",
pythonPackageVersion,
PythonTrainerVersions.s_MinSupportedVersion,
PythonTrainerVersions.s_MaxSupportedVersion
);
throw new UnityAgentsException("Incompatible trainer version.");
}
var packageVersionSupported = CheckPythonPackageVersionIsSupported(pythonPackageVersion);
if (!packageVersionSupported)
{
Debug.LogWarningFormat(

6
com.unity.ml-agents/Runtime/Constants.cs


internal static class PythonTrainerVersions
{
// The python package version must be >= s_MinSupportedVersion
// The python package version should be >= s_MinSupportedVersion
// Any version > to this is known to be incompatible and we will block training.
// Covers any patch to the release before the 2.0.0 package release.
internal static Version s_MaxCompatibleVersion = new Version("0.25.999");
}
}

32
com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs


[Test]
public void TestCheckPythonPackageVersionIsCompatible()
{
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.13.37")); // too low
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.42.0")); // too high
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.13.37")); // low is OK
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.26.0")); // too high
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.20.0"));
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.0"));
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.1"));
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.2"));
// "dev" strings should get removed before parsing
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.17.0.dev0"));
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.0.dev0"));
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.26.0.dev0"));
// otherwise unparseable - keep support for these
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("the airspeed velocity of an unladen swallow"));
}
[Test]
public void TestCheckPythonPackageVersionIsSupported()
{
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.13.37")); // too low
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.42.0")); // too high
// These are fine
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.16.1"));
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.17.17"));
Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.20.0"));
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.17.0-dev0"));
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("oh point seventeen point oh"));
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.17.0.dev0"));
Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("oh point seventeen point oh"));
}
}
}
正在加载...
取消
保存