Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor. #6163

Open
HeyThisWasRandomlyMade opened this issue Oct 16, 2024 · 2 comments
Assignees
Labels
bug Issue describes a potential bug in ml-agents.

Comments

@HeyThisWasRandomlyMade
Copy link

Describe the bug
When setting the inference device to "Compute Shader" in Unity ML-Agents, this error occurs:

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor.

Burst works fine, this is probably related to me using unity 6 preview.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Behavior Parameters in any agent and set inference device to Compute Shader.
  2. Press play and you'll get this error.

Console logs / stack traces

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor.
Unity.Sentis.Tensor.GetItem[T] (System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/Tensor.cs:257)
Unity.Sentis.Tensor`1[T].get_Item (System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/TensorGeneric.cs:256)
Unity.Sentis.Tensor`1[T].get_Item (System.Int32 d1, System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/TensorGeneric.cs:246)
Unity.MLAgents.Inference.ContinuousActionOutputApplier.Apply (Unity.MLAgents.Inference.TensorProxy tensorProxy, System.Collections.Generic.IList`1[T] actionIds, System.Collections.Generic.Dictionary`2[TKey,TValue] lastActions) (at ./Packages/com.unity.ml-agents/Runtime/Inference/ApplierImpl.cs:47)
Unity.MLAgents.Inference.TensorApplier.ApplyTensors (System.Collections.Generic.IReadOnlyList`1[T] tensors, System.Collections.Generic.IList`1[T] actionIds, System.Collections.Generic.Dictionary`2[TKey,TValue] lastActions) (at ./Packages/com.unity.ml-agents/Runtime/Inference/TensorApplier.cs:108)
Unity.MLAgents.Inference.ModelRunner.DecideBatch () (at ./Packages/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs:242)
Unity.MLAgents.Policies.SentisPolicy.DecideAction () (at ./Packages/com.unity.ml-agents/Runtime/Policies/SentisPolicy.cs:134)
Unity.MLAgents.Agent.DecideAction () (at ./Packages/com.unity.ml-agents/Runtime/Agent.cs:1411)
Unity.MLAgents.Academy.EnvironmentStep () (at ./Packages/com.unity.ml-agents/Runtime/Academy.cs:590)
Unity.MLAgents.AcademyFixedUpdateStepper.FixedUpdate () (at ./Packages/com.unity.ml-agents/Runtime/Academy.cs:43)

Environment (please complete the following information):

  • Unity Version: Unity 6 Preview, 6000.0.22f1
  • OS + version: Kubuntu 24.04
  • ML-Agents version: Latest development
  • Torch version: 2.4.1+rocm6.1
@HeyThisWasRandomlyMade HeyThisWasRandomlyMade added the bug Issue describes a potential bug in ml-agents. label Oct 16, 2024
@paulo101977
Copy link

Describe the bug When setting the inference device to "Compute Shader" in Unity ML-Agents, this error occurs:

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor.

Burst works fine, this is probably related to me using unity 6 preview.

To Reproduce Steps to reproduce the behavior:

  1. Go to Behavior Parameters in any agent and set inference device to Compute Shader.
  2. Press play and you'll get this error.

Console logs / stack traces

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor.
Unity.Sentis.Tensor.GetItem[T] (System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/Tensor.cs:257)
Unity.Sentis.Tensor`1[T].get_Item (System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/TensorGeneric.cs:256)
Unity.Sentis.Tensor`1[T].get_Item (System.Int32 d1, System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/TensorGeneric.cs:246)
Unity.MLAgents.Inference.ContinuousActionOutputApplier.Apply (Unity.MLAgents.Inference.TensorProxy tensorProxy, System.Collections.Generic.IList`1[T] actionIds, System.Collections.Generic.Dictionary`2[TKey,TValue] lastActions) (at ./Packages/com.unity.ml-agents/Runtime/Inference/ApplierImpl.cs:47)
Unity.MLAgents.Inference.TensorApplier.ApplyTensors (System.Collections.Generic.IReadOnlyList`1[T] tensors, System.Collections.Generic.IList`1[T] actionIds, System.Collections.Generic.Dictionary`2[TKey,TValue] lastActions) (at ./Packages/com.unity.ml-agents/Runtime/Inference/TensorApplier.cs:108)
Unity.MLAgents.Inference.ModelRunner.DecideBatch () (at ./Packages/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs:242)
Unity.MLAgents.Policies.SentisPolicy.DecideAction () (at ./Packages/com.unity.ml-agents/Runtime/Policies/SentisPolicy.cs:134)
Unity.MLAgents.Agent.DecideAction () (at ./Packages/com.unity.ml-agents/Runtime/Agent.cs:1411)
Unity.MLAgents.Academy.EnvironmentStep () (at ./Packages/com.unity.ml-agents/Runtime/Academy.cs:590)
Unity.MLAgents.AcademyFixedUpdateStepper.FixedUpdate () (at ./Packages/com.unity.ml-agents/Runtime/Academy.cs:43)

Environment (please complete the following information):

  • Unity Version: Unity 6 Preview, 6000.0.22f1
  • OS + version: Kubuntu 24.04
  • ML-Agents version: Latest development
  • Torch version: 2.4.1+rocm6.1

Probably Tensorflow version incompatibility. I was opening an old project here and had the same error.

@paulo101977
Copy link

Describe the bug When setting the inference device to "Compute Shader" in Unity ML-Agents, this error occurs:

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor.

Burst works fine, this is probably related to me using unity 6 preview.

To Reproduce Steps to reproduce the behavior:

  1. Go to Behavior Parameters in any agent and set inference device to Compute Shader.
  2. Press play and you'll get this error.

Console logs / stack traces

InvalidOperationException: Tensor data cannot be read from, use .ReadbackAndClone() to allow reading from tensor.
Unity.Sentis.Tensor.GetItem[T] (System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/Tensor.cs:257)
Unity.Sentis.Tensor`1[T].get_Item (System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/TensorGeneric.cs:256)
Unity.Sentis.Tensor`1[T].get_Item (System.Int32 d1, System.Int32 d0) (at ./Library/PackageCache/com.unity.sentis@a9353f8ec25d/Runtime/Core/TensorGeneric.cs:246)
Unity.MLAgents.Inference.ContinuousActionOutputApplier.Apply (Unity.MLAgents.Inference.TensorProxy tensorProxy, System.Collections.Generic.IList`1[T] actionIds, System.Collections.Generic.Dictionary`2[TKey,TValue] lastActions) (at ./Packages/com.unity.ml-agents/Runtime/Inference/ApplierImpl.cs:47)
Unity.MLAgents.Inference.TensorApplier.ApplyTensors (System.Collections.Generic.IReadOnlyList`1[T] tensors, System.Collections.Generic.IList`1[T] actionIds, System.Collections.Generic.Dictionary`2[TKey,TValue] lastActions) (at ./Packages/com.unity.ml-agents/Runtime/Inference/TensorApplier.cs:108)
Unity.MLAgents.Inference.ModelRunner.DecideBatch () (at ./Packages/com.unity.ml-agents/Runtime/Inference/ModelRunner.cs:242)
Unity.MLAgents.Policies.SentisPolicy.DecideAction () (at ./Packages/com.unity.ml-agents/Runtime/Policies/SentisPolicy.cs:134)
Unity.MLAgents.Agent.DecideAction () (at ./Packages/com.unity.ml-agents/Runtime/Agent.cs:1411)
Unity.MLAgents.Academy.EnvironmentStep () (at ./Packages/com.unity.ml-agents/Runtime/Academy.cs:590)
Unity.MLAgents.AcademyFixedUpdateStepper.FixedUpdate () (at ./Packages/com.unity.ml-agents/Runtime/Academy.cs:43)

Environment (please complete the following information):

  • Unity Version: Unity 6 Preview, 6000.0.22f1
  • OS + version: Kubuntu 24.04
  • ML-Agents version: Latest development
  • Torch version: 2.4.1+rocm6.1

I think I discovered where the problem is: for me, the error only occurs when I choose the 'Pixel Shader' as the inference device. Both Computer Shader and Pixel Shader use the GPU. Switching to CPU the problem disappears.

@miguelalonsojr miguelalonsojr self-assigned this Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue describes a potential bug in ml-agents.
Projects
None yet
Development

No branches or pull requests

3 participants