Skip to content

Commit

Permalink
Refactoring all Barracuda related naming to Sentis.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelalonsojr committed Oct 2, 2023
1 parent 01dd77f commit c8f46d0
Show file tree
Hide file tree
Showing 72 changed files with 315 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"references": [
"Unity.ML-Agents.Editor",
"Unity.ML-Agents",
"Unity.Barracuda",
"Unity.Sentis",
"Unity.ML-Agents.CommunicatorObjects",
"Unity.PerformanceTesting"
],
Expand Down
24 changes: 12 additions & 12 deletions DevProject/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.barracuda": {
"version": "3.0.0",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.6.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.burst": {
"version": "1.8.7",
"depth": 2,
Expand Down Expand Up @@ -66,7 +55,7 @@
"depth": 0,
"source": "local",
"dependencies": {
"com.unity.barracuda": "3.0.0",
"com.unity.sentis": "1.2.0-exp.2",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.physics": "1.0.0"
Expand Down Expand Up @@ -115,6 +104,17 @@
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.sentis": {
"version": "1.2.0-exp.2",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.8.4",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.settings-manager": {
"version": "2.0.1",
"depth": 1,
Expand Down
2 changes: 1 addition & 1 deletion DevProject/ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ EditorBuildSettings:
path: Assets/ML-Agents/Scripts/Tests/Runtime/AcademyTest/AcademyStepperTestScene.unity
guid: 9bafc50b1e55b43b2b1ae9620f1f8311
m_configObjects:
com.unity.ml-agents.settings: {fileID: 11400000, guid: b412e5eb0b23f4bca86655ada9a633d4,
com.unity.ml-agents.settings: {fileID: 11400000, guid: e4ad406c716274fdfb58baafffa12dcd,
type: 2}
4 changes: 2 additions & 2 deletions colab/Colab_UnityEnvironment_2_Train.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@
{
"cell_type": "markdown",
"source": [
"The following cell provides an example of some of the extra tensors a model needs to work for ML-Agents inference with Barracuda. The GridWorldColab scene is configured to work with this ONNX file.\n",
"The following cell provides an example of some of the extra tensors a model needs to work for ML-Agents inference with Sentis. The GridWorldColab scene is configured to work with this ONNX file.\n",
"Only policy models need to be exported for inference and they need the following additional tensors:\n",
"\n",
"* All models need version_number\n",
Expand All @@ -620,7 +620,7 @@
" ):\n",
" \"\"\"\n",
" Wraps the VisualQNetwork adding extra constants and dummy mask inputs\n",
" required by runtime inference with Barracuda.\n",
" required by runtime inference with Sentis.\n",
"\n",
" For environment continuous actions outputs would need to add them\n",
" similarly to how discrete action outputs work, both in the wrapper\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Unity.ML-Agents.Extensions.Input",
"references": [
"Unity.ML-Agents",
"Unity.Barracuda",
"Unity.Sentis",
"Unity.InputSystem"
],
"includePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void Update()
}

/// <inheritdoc/>
public void Reset() { }
public void Reset() {}

/// <inheritdoc/>
public CompressionSpec GetCompressionSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ internal IList<DisplayNode> GetDisplayNodes()

while (stack.Count != 0)
{
var (current, depth) = stack.Pop();
var(current, depth) = stack.Pop();
var obj = GetObjectAt(current);

var node = new DisplayNode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Unity.ML-Agents.Extensions",
"references": [
"Unity.Barracuda",
"Unity.Sentis",
"Unity.ML-Agents",
"Unity.ML-Agents.Extensions.Input"
]
Expand Down
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to
## [Unreleased]
### Major Changes
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
- Upgraded ML-Agents to Sentis 1.2.0-exp.2 (#)
- The minimum supported Unity version was updated to 2022.3. (#)
- Added batched raycast sensor option. (#)

Expand Down
4 changes: 2 additions & 2 deletions com.unity.ml-agents/Documentation~/com.unity.ml-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mode if training is not supported or is not currently running.
### Inference

Inference is executed via the
[Unity Inference Engine](https://docs.unity3d.com/Packages/com.unity.barracuda@latest/index.html).
[Unity Inference Engine](https://docs.unity3d.com/Packages/com.unity.sentis@latest/index.html).

**CPU**

Expand Down Expand Up @@ -152,7 +152,7 @@ Please refer to "Information that is passively collected by Unity" in the
[Unity Privacy Policy](https://unity3d.com/legal/privacy-policy).

[unity ML-Agents Toolkit]: https://github.com/Unity-Technologies/ml-agents
[unity inference engine]: https://docs.unity3d.com/Packages/com.unity.barracuda@latest/index.html
[unity inference engine]: https://docs.unity3d.com/Packages/com.unity.sentis@latest/index.html
[package manager documentation]: https://docs.unity3d.com/Manual/upm-ui-install.html
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_20_docs/docs/Installation.md
[github repository]: https://github.com/Unity-Technologies/ml-agents
Expand Down
10 changes: 5 additions & 5 deletions com.unity.ml-agents/Editor/BehaviorParametersEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Unity.MLAgents.Policies;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Sensors.Reflection;
using CheckTypeEnum = Unity.MLAgents.Inference.BarracudaModelParamLoader.FailedCheck.CheckTypeEnum;
using CheckTypeEnum = Unity.MLAgents.Inference.SentisModelParamLoader.FailedCheck.CheckTypeEnum;

namespace Unity.MLAgents.Editor
{
Expand Down Expand Up @@ -111,7 +111,7 @@ void DisplayFailedModelChecks()
}
// Display all failed checks
// D.logEnabled = false;
Model barracudaModel = null;
Model sentisModel = null;
var model = (ModelAsset)serializedObject.FindProperty(k_ModelName).objectReferenceValue;
var behaviorParameters = (BehaviorParameters)target;

Expand Down Expand Up @@ -152,12 +152,12 @@ void DisplayFailedModelChecks()
var brainParameters = behaviorParameters.BrainParameters;
if (model != null)
{
barracudaModel = ModelLoader.Load(model);
sentisModel = ModelLoader.Load(model);
}
if (brainParameters != null)
{
var failedChecks = Inference.BarracudaModelParamLoader.CheckModel(
barracudaModel, brainParameters, sensors, actuatorComponents,
var failedChecks = Inference.SentisModelParamLoader.CheckModel(
sentisModel, brainParameters, sensors, actuatorComponents,
observableAttributeSensorTotalSize, behaviorParameters.BehaviorType, behaviorParameters.DeterministicInference
);
foreach (var check in failedChecks)
Expand Down
16 changes: 8 additions & 8 deletions com.unity.ml-agents/Runtime/Academy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void EnableAutomaticStepping()
// This try-catch is because DontDestroyOnLoad cannot be used in Editor Tests
GameObject.DontDestroyOnLoad(m_StepperObject);
}
catch { }
catch {}
}

/// <summary>
Expand Down Expand Up @@ -501,13 +501,13 @@ out var unityRlInitParameters

void ResetActions()
{
DecideAction = () => { };
DestroyAction = () => { };
AgentPreStep = i => { };
AgentSendState = () => { };
AgentAct = () => { };
AgentForceReset = () => { };
OnEnvironmentReset = () => { };
DecideAction = () => {};
DestroyAction = () => {};
AgentPreStep = i => {};
AgentSendState = () => {};
AgentAct = () => {};
AgentForceReset = () => {};
OnEnvironmentReset = () => {};
}

static void OnQuitCommandReceived()
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void CheckParameters(IReadOnlyCollection<T> actionArray, int offset, int
/// </summary>
/// <param name="actionArray">The action array to use for the this segment.</param>
public ActionSegment(T[] actionArray)
: this(actionArray ?? System.Array.Empty<T>(), 0, actionArray?.Length ?? 0) { }
: this(actionArray ?? System.Array.Empty<T>(), 0, actionArray?.Length ?? 0) {}

/// <summary>
/// Construct an <see cref="ActionSegment{T}"/> with an underlying array
Expand Down
4 changes: 2 additions & 2 deletions com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static ActionBuffers FromDiscreteActions(float[] discreteActions)
/// <param name="continuousActions">The continuous actions to send to an <see cref="IActionReceiver"/>.</param>
/// <param name="discreteActions">The discrete actions to send to an <see cref="IActionReceiver"/>.</param>
public ActionBuffers(float[] continuousActions, int[] discreteActions)
: this(new ActionSegment<float>(continuousActions), new ActionSegment<int>(discreteActions)) { }
: this(new ActionSegment<float>(continuousActions), new ActionSegment<int>(discreteActions)) {}

/// <summary>
/// Construct an <see cref="ActionBuffers"/> instance with the continuous and discrete actions that will
Expand All @@ -68,7 +68,7 @@ public ActionBuffers(ActionSegment<float> continuousActions, ActionSegment<int>
public ActionBuffers(ActionSpec actionSpec)
: this(new ActionSegment<float>(new float[actionSpec.NumContinuousActions]),
new ActionSegment<int>(new int[actionSpec.NumDiscreteActions]))
{ }
{}

/// <summary>
/// Create an <see cref="ActionBuffers"/> instance with ActionSpec and all actions stored as a float array.
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal ActionBuffers ActionBuffers
public VectorActuator(IActionReceiver actionReceiver,
ActionSpec actionSpec,
string name = "VectorActuator")
: this(actionReceiver, actionReceiver as IHeuristicProvider, actionSpec, name) { }
: this(actionReceiver, actionReceiver as IHeuristicProvider, actionSpec, name) {}

/// <summary>
/// Create a VectorActuator that forwards to the provided IActionReceiver.
Expand Down
10 changes: 5 additions & 5 deletions com.unity.ml-agents/Runtime/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public AgentVectorActuator(IActionReceiver actionReceiver,
ActionSpec actionSpec,
string name = "VectorActuator"
) : base(actionReceiver, heuristicProvider, actionSpec, name)
{ }
{}

public override BuiltInActuatorType GetBuiltInActuatorType()
{
Expand Down Expand Up @@ -904,7 +904,7 @@ void ResetData()
///
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// </remarks>
public virtual void Initialize() { }
public virtual void Initialize() {}

/// <summary>
/// Implement <see cref="Heuristic"/> to choose an action for this agent using a custom heuristic.
Expand Down Expand Up @@ -1241,7 +1241,7 @@ public ReadOnlyCollection<float> GetStackedObservations()
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_20_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <seealso cref="IActionReceiver.OnActionReceived"/>
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { }
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) {}

/// <summary>
/// Implement `OnActionReceived()` to specify agent behavior at every step, based
Expand Down Expand Up @@ -1309,15 +1309,15 @@ public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { }
/// <param name="actions">
/// Struct containing the buffers of actions to be executed at this step.
/// </param>
public virtual void OnActionReceived(ActionBuffers actions) { }
public virtual void OnActionReceived(ActionBuffers actions) {}

/// <summary>
/// Implement `OnEpisodeBegin()` to set up an Agent instance at the beginning
/// of an episode.
/// </summary>
/// <seealso cref="Initialize"/>
/// <seealso cref="EndEpisode"/>
public virtual void OnEpisodeBegin() { }
public virtual void OnEpisodeBegin() {}

/// <summary>
/// Gets the most recent ActionBuffer for this agent.
Expand Down
8 changes: 4 additions & 4 deletions com.unity.ml-agents/Runtime/Analytics/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ internal struct InferenceEvent
/// Hash of the BehaviorName.
/// </summary>
public string BehaviorName;
public string BarracudaModelSource;
public long BarracudaModelVersion;
public string BarracudaModelProducer;
public string BarracudaPackageVersion;
public string SentisModelSource;
public long SentisModelVersion;
public string SentisModelProducer;
public string SentisPackageVersion;
/// <summary>
/// Whether inference is performed on CPU (0) or GPU (1).
/// </summary>
Expand Down
43 changes: 22 additions & 21 deletions com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,31 @@ internal static InferenceEvent GetEventForModel(
IList<IActuator> actuators
)
{
var barracudaModel = ModelLoader.Load(nnModel);
var sentisModel = ModelLoader.Load(nnModel);
var inferenceEvent = new InferenceEvent();

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

inferenceEvent.BarracudaModelSource = barracudaModel.IrSource;
inferenceEvent.BarracudaModelVersion = barracudaModel.IrVersion;
inferenceEvent.BarracudaModelProducer = barracudaModel.ProducerName;
inferenceEvent.MemorySize = (int)((TensorFloat)barracudaModel.GetTensorByName(TensorNames.MemorySize))[0];
inferenceEvent.SentisModelSource = sentisModel.IrSource;
inferenceEvent.SentisModelVersion = sentisModel.IrVersion;
inferenceEvent.SentisModelProducer = sentisModel.ProducerName;
inferenceEvent.MemorySize = (int)((TensorFloat)sentisModel.GetTensorByName(TensorNames.MemorySize))[0];
inferenceEvent.InferenceDevice = (int)inferenceDevice;

if (barracudaModel.ProducerName == "Script")
// TODO deprecate tensorflow conversion
if (sentisModel.ProducerName == "Script")
{
// .nn files don't have these fields set correctly. Assign some placeholder values.
inferenceEvent.BarracudaModelSource = "NN";
inferenceEvent.BarracudaModelProducer = "tensorflow_to_barracuda.py";
inferenceEvent.SentisModelSource = "NN";
inferenceEvent.SentisModelProducer = "tensorflow_to_barracuda.py";
}

#if UNITY_EDITOR
var barracudaPackageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(Tensor).Assembly);
inferenceEvent.BarracudaPackageVersion = barracudaPackageInfo.version;
var sentisPackageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(Tensor).Assembly);
inferenceEvent.SentisPackageVersion = sentisPackageInfo.version;
#else
inferenceEvent.BarracudaPackageVersion = null;
inferenceEvent.SentisPackageVersion = null;
#endif

inferenceEvent.ActionSpec = EventActionSpec.FromActionSpec(actionSpec);
Expand All @@ -191,24 +192,24 @@ IList<IActuator> actuators
inferenceEvent.ActuatorInfos.Add(EventActuatorInfo.FromActuator(actuator));
}

inferenceEvent.TotalWeightSizeBytes = GetModelWeightSize(barracudaModel);
inferenceEvent.ModelHash = GetModelHash(barracudaModel);
inferenceEvent.TotalWeightSizeBytes = GetModelWeightSize(sentisModel);
inferenceEvent.ModelHash = GetModelHash(sentisModel);
return inferenceEvent;
}

/// <summary>
/// Compute the total model weight size in bytes.
/// This corresponds to the "Total weight size" display in the Barracuda inspector,
/// This corresponds to the "Total weight size" display in the Sentis inspector,
/// and the calculations are the same.
/// </summary>
/// <param name="barracudaModel"></param>
/// <param name="sentisModel"></param>
/// <returns></returns>
static long GetModelWeightSize(Model barracudaModel)
static long GetModelWeightSize(Model sentisModel)
{
long totalWeightsSizeInBytes = 0;
for (var c = 0; c < barracudaModel.constants.Count; c++)
for (var c = 0; c < sentisModel.constants.Count; c++)
{
totalWeightsSizeInBytes += barracudaModel.constants[c].length;
totalWeightsSizeInBytes += sentisModel.constants[c].length;
}
return totalWeightsSizeInBytes;
}
Expand Down Expand Up @@ -258,16 +259,16 @@ public override string ToString()
/// A subset of the layer weights are used for performance.
/// This increases the chance of a collision, but this should still be extremely rare.
/// </summary>
/// <param name="barracudaModel"></param>
/// <param name="sentisModel"></param>
/// <returns></returns>
static string GetModelHash(Model barracudaModel)
static string GetModelHash(Model sentisModel)
{
var hash = new MLAgentsHash128();

// Limit the max number of float bytes that we hash for performance.
const int kMaxFloats = 256;

foreach (var constant in barracudaModel.constants)
foreach (var constant in sentisModel.constants)
{
hash.Append(constant.name);
var numFloatsToHash = Mathf.Min(constant.weights.Length, kMaxFloats);
Expand Down
Loading

0 comments on commit c8f46d0

Please sign in to comment.