From 209db0f07ad54cf78a482c33d8335ef382588a4f Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Mon, 22 Mar 2021 15:37:04 -0700 Subject: [PATCH] change default barracuda behavior --- com.unity.ml-agents/CHANGELOG.md | 3 +++ com.unity.ml-agents/Runtime/Agent.cs | 2 +- com.unity.ml-agents/Runtime/Inference/ModelRunner.cs | 1 + .../Runtime/Policies/BarracudaPolicy.cs | 11 ++++++++--- .../Runtime/Policies/BehaviorParameters.cs | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index fb05f310cf..bd9531e799 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -32,6 +32,9 @@ interface was removed. (#5164) - Added ML-Agents package settings. (#5027) - Make com.unity.modules.unityanalytics an optional dependency. (#5109) - Make com.unity.modules.physics and com.unity.modules.physics2d optional dependencies. (#5112) +- The default `InferenceDevice` is now `InferenceDevice.Default`, which is equivalent to `InferenceDevice.Burst`. If you +depend on the previous behavior, you can explicitly set the Agent's `InferenceDevice` to `InferenceDevice.CPU`. (#5175) + #### ml-agents / ml-agents-envs / gym-unity (Python) ### Bug Fixes diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs index 5c7cc73488..580e1571c3 100644 --- a/com.unity.ml-agents/Runtime/Agent.cs +++ b/com.unity.ml-agents/Runtime/Agent.cs @@ -617,7 +617,7 @@ void NotifyAgentDone(DoneReason doneReason) public void SetModel( string behaviorName, NNModel model, - InferenceDevice inferenceDevice = InferenceDevice.CPU) + InferenceDevice inferenceDevice = InferenceDevice.Default) { if (behaviorName == m_PolicyFactory.BehaviorName && model == m_PolicyFactory.Model && diff --git a/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs b/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs index 12a8188c52..054ac2ac4e 100644 --- a/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs +++ b/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs @@ -83,6 +83,7 @@ public ModelRunner( case InferenceDevice.Burst: executionDevice = WorkerFactory.Type.CSharpBurst; break; + case InferenceDevice.Default: // fallthrough default: executionDevice = WorkerFactory.Type.CSharpBurst; break; diff --git a/com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs b/com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs index c9a1202af5..5e76084b20 100644 --- a/com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs +++ b/com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs @@ -13,10 +13,9 @@ namespace Unity.MLAgents.Policies public enum InferenceDevice { /// - /// CPU inference. Corresponds to in WorkerFactory.Type.CSharp Barracuda. - /// Burst is recommended instead; this is kept for legacy compatibility. + /// Default inference. This is currently the same as Burst, but may change in the future. /// - CPU = 0, + Default = 0, /// /// GPU inference. Corresponds to WorkerFactory.Type.ComputePrecompiled in Barracuda. @@ -27,6 +26,12 @@ public enum InferenceDevice /// CPU inference using Burst. Corresponds to WorkerFactory.Type.CSharpBurst in Barracuda. /// Burst = 2, + + /// + /// CPU inference. Corresponds to in WorkerFactory.Type.CSharp Barracuda. + /// Burst is recommended instead; this is kept for legacy compatibility. + /// + CPU = 3, } /// diff --git a/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs b/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs index 33a9089d75..ae05284d50 100644 --- a/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs +++ b/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs @@ -109,7 +109,7 @@ public NNModel Model } [HideInInspector, SerializeField] - InferenceDevice m_InferenceDevice = InferenceDevice.Burst; + InferenceDevice m_InferenceDevice = InferenceDevice.Default; /// /// How inference is performed for this Agent's model.