stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
12.87k stars 4.11k forks source link

Memory hog problem in `22_deep_reinforcement_learning`/`04_q_learning_for_trading.ipynb` #269

Closed DavidHJong closed 1 year ago

DavidHJong commented 1 year ago

Describe the bug

What I did to find this

  1. In 04_q_learning_for_trading.ipynb, I added a cell monitor RAM usage with 2 functions to monitor the process memory usage and call these functions multiple times in the Train Agent cell.
  2. I recorded the process memory changes and save it into a .csv file and visualize it in a .xlsx file.

Steps to reproduce the behavior:

  1. To see in which steps the major memory changes occurred, open the memory_change_record.xlsx file
  2. To reproduce this record, run 04_q_learning_for_trading.ipynb.

Questions

Why it matters

stefan-jansen commented 1 year ago

I'm sorry, but I don't have time to investigate. Data leak would be caused by an underlying library, so please take a look at the issues in the relevant libraries. Memory usage could of course increase by keeping certain data around; if that's a problem you could periodically write to disk and reinit the data structures.