eaplatanios / jelly-bean-world

A framework for experimenting with never-ending learning
Apache License 2.0
73 stars 17 forks source link

Potential memory leak #12

Closed finbarrtimbers closed 2 years ago

finbarrtimbers commented 2 years ago

Hey folks!

I'm running an episodic version of JBW in Python for some experiments. Basically, we create a Simulator object from api/python/src/jbw/simulator.py, run it for N frames, then delete it and create a new Simulator. When I do this, I see memory increase by ~12MiB for each call to simulator_c.new. I'm wondering if something isn't being free'd properly in simulator_c.delete.

I have two questions:

1) Have you run into this before? Do you have any idea what could be causing this? 2) Is there a better way to run this episodic experiment?

asaparov commented 2 years ago

Thanks for the report! I'll look into this and see if I can find the memory leak.

I think your current workflow is fine for episodic experiments. JBW was designed specifically for the never-ending/continual setting so we didn't do much testing for episodic use-cases.

finbarrtimbers commented 2 years ago

That makes sense. This would be difficult to find in the continual setting, as as it's only 12MiB.

asaparov commented 2 years ago

I just pushed a commit that fixes one memory leak. It was a subtle bug where we were creating a cyclic reference where C++ would reference the callback functions in the Simulator object, and the callbacks and Simulator object reference each other. So the Simulator object would never be garbage collected, even if there were no references to it from Python.

You might need to force garbage collection after each episode if you want to make sure that memory usage stays constant, otherwise it seems to garbage collect every ~10 episodes in my tests.

asaparov commented 2 years ago

Let me know if this change fixes the issue in your setup.

finbarrtimbers commented 2 years ago

Fantastic- thank you for the quick fix. I will test that out.

On Thu, Apr 7, 2022 at 5:02 PM Abulhair Saparov @.***> wrote:

Let me know if this change fixes the issue in your setup.

— Reply to this email directly, view it on GitHub https://github.com/eaplatanios/jelly-bean-world/issues/12#issuecomment-1092285416, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYN6RMA2QPHH5O6IO3ONZ3VD5SPBANCNFSM5SWYAEIQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Finbarr

sophistz commented 2 years ago

Hi, I think with the updated simulator.py and simulator.cpp, the "jbw-v1" environment is not returning correct reward value. Can you please double check this?

asaparov commented 2 years ago

Oh weird. Thanks for letting me know. I'll look into it.

asaparov commented 2 years ago

@sophistz I found an bug that I had created in fixing the memory leak. 😅 I just pushed some changes that will hopefully fix it.

sophistz commented 2 years ago

@asaparov Thanks. The code works now!

finbarrtimbers commented 2 years ago

Memory leak appears to have been fixed- thanks for the quick patch!