Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
16.93k stars 4.14k forks source link

Use Cpu to Inference the Model trained by GPU #4595

Closed MillionBones closed 3 years ago

MillionBones commented 3 years ago

Describe the bug Use Cpu to Inference the Model trained by GPU get the error below Fixed by switch Inf device to GPU

Console logs / stack traces

AssertionException: Assertion failure. Value was False
Expected: True
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <aa41805fa91a490cb490f3285f41592b>:0)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at <aa41805fa91a490cb490f3285f41592b>:0)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) (at <aa41805fa91a490cb490f3285f41592b>:0)
Unity.Barracuda.ArrayTensorData.Upload (System.Single[] data, Unity.Barracuda.TensorShape shape, System.Int32 managedBufferStartIndex) (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/BarracudaReferenceCPU.cs:47)
Unity.Barracuda.Tensor.UploadIfDirty () (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Tensor.cs:1046)
Unity.Barracuda.Tensor.UploadAndInvalidateCache () (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Tensor.cs:1052)
Unity.Barracuda.Tensor.FlushCache () (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Tensor.cs:1092)
Unity.Barracuda.UnsafeArrayCPUOps.Pin (Unity.Barracuda.Tensor X) (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/BarracudaUnsafeArrayCPU.cs:129)
Unity.Barracuda.UnsafeArrayCPUOps.ApplyElementwiseWithBroadcast (Unity.Barracuda.Tensor[] tensors, System.Func`3[T1,T2,TResult] opRemainder, System.Action`1[T] opInnerLoop, System.Action`1[T] opInnerLoopNoBroadcast) (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/BarracudaUnsafeArrayCPU.cs:1029)
Unity.Barracuda.UnsafeArrayCPUOps.Mul (Unity.Barracuda.Tensor[] tensors) (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/BarracudaUnsafeArrayCPU.cs:1071)
Unity.Barracuda.StatsOps.Unity.Barracuda.IOps.Mul (Unity.Barracuda.Tensor[] tensors) (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/StatsOps.cs:419)
Unity.Barracuda.GenericWorker+<StartManualSchedule>d__29.MoveNext () (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/GenericWorker.cs:470)
Unity.Barracuda.GenericWorker.Execute () (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/GenericWorker.cs:118)
Unity.Barracuda.GenericWorker.Execute (System.Collections.Generic.IDictionary`2[TKey,TValue] inputs) (at Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/GenericWorker.cs:106)
Unity.MLAgents.Inference.ModelRunner.DecideBatch () (at F:/FastWork/MillionBonesProj/Unity-MLAgentsExmple/ml-agents/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs:174)
Unity.MLAgents.Policies.BarracudaPolicy.DecideAction () (at F:/FastWork/MillionBonesProj/Unity-MLAgentsExmple/ml-agents/com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs:66)
Unity.MLAgents.Agent.DecideAction () (at F:/FastWork/MillionBonesProj/Unity-MLAgentsExmple/ml-agents/com.unity.ml-agents/Runtime/Agent.cs:1291)
Unity.MLAgents.Academy.EnvironmentStep () (at F:/FastWork/MillionBonesProj/Unity-MLAgentsExmple/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:573)
Unity.MLAgents.AcademyFixedUpdateStepper.FixedUpdate () (at F:/FastWork/MillionBonesProj/Unity-MLAgentsExmple/ml-agents/com.unity.ml-agents/Runtime/Academy.cs:43)

Environment :

chriselion commented 3 years ago

Can you either attach your model file, or reproduce this behavior with a model from one of the example scenes? The actual weights of the model shouldn't matter, so you can just run training for a few steps.

Can you also confirm that you're using "Release 8" (Unity package 1.5.0-preview, python package 0.21.0)? Since you're using com.unity.barracuda@1.1.1-preview I assume it's the one you're using - v0.8 is actually much older.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had activity in the last 14 days. It will be closed in the next 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

This issue has been automatically closed because it has not had activity in the last 28 days. If this issue is still valid, please ping a maintainer. Thank you for your contributions.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.