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.59k stars 4.09k forks source link

Potential Memory leak when using model #6109

Closed noki00003 closed 1 week ago

noki00003 commented 1 month ago

I am experiencing a bug, that when I have finished training my model and I want to use it then, I put the model into the Model Field in Unity. I do this for 16 Agents in a single environment. The first run there are no problems. Then I stop the run and change all models except for one to "Inference only" (the first run was "Default") and the one remaining agent to "Heuristic only", as I want to play myself against the other agents. Then I get the warning:

"Found unreferenced, but undisposed BurstTensorData that potentially participates in an unfinished job and might lead to hazardous memory overwrites UnityEngine.Debug:LogWarning (object) Unity.Sentis.D:LogWarning (object) (at ./Library/PackageCache/com.unity.sentis@1.2.0-exp.2/Runtime/Core/Internals/Debug.cs:72) Unity.Sentis.BurstTensorData:Finalize () (at ./Library/PackageCache/com.unity.sentis@1.2.0-exp.2/Runtime/Core/Backends/CPU/BurstTensorData.cs:145)".

When I then change all the agents back to "Default" as in the first run, the warning still occurs. I have looked for solutions for a long time on the Internet, but there is only one solution, where I do not understand where in the code I need to change something ( https://github.com/AlexRibard/Barracuda-U-2-NetTest/issues/3 ).

To reproduce this error you need to follow these simple steps:

  1. open up the default PushBlock environment provided by mlagents
  2. hit run once and then everything should run as desired with the provided model asset
  3. stop running and change only the agent of the first environment to "heuristic only"
  4. hit run again and then there should be the warning in the console

Edit: You can simply hit run then stop and then run again, I just found out Edit2: It does only happen in release 21 (3.0.0) and not in release 20 (2.3.0)

I am not really sure, whether I tested this excact scenario with Torch-CPU before, but right now I am using Torch-CUDA 12.1 with torch version 2.3.0. My other specs:

memoryLeakIssueUnity

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 week ago

This issue was closed because it has been inactive for 14 days since being marked as stale. Please open a new issue for related bugs.