# Expected RAM usage for PPOTrainer (debugging memory leaks)

**URL:** <https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428>\
**Category:** RLlib\
**Created:** [March 16, 2022, 4:19pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428 "2022-03-16T16:19:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjlbach](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mjlbach/32/1294_2.png) [@mjlbach](https://discuss.ray.io/u/mjlbach)\
**Post date:** [March 16, 2022, 4:19pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/1 "2022-03-16T16:19:37Z")

</div>

I’m using the latest Ray (1.11) and noticed the PPO trainer takes a fairly huge amount of ram, roughly 4 gb per worker with some apparent memory leak (training always inevitably crashes due to OOM about 500-600k environment stpes in). Does anyone have suggestions for debugging this? My rollout buffer size is 4096, my observation sizes are an RGBD image and a 2d birds eye map with two channels (128 x 128 x 3: float32, 128 x 128 x 1: float 32, 128 x 128 x 2: float32).

---

<div class="post-metadata">

**Author:** ![avnishn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/avnishn/32/1544_2.png) [@avnishn](https://discuss.ray.io/u/avnishn)\
**Post date:** [May 17, 2022, 12:48am UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/2 "2022-05-17T00:48:34Z")

</div>

Can you share the script that you use to launch your experiment? This would be a good starting place in helping you out.

If you don’t want to share your environment, you can substituted it for the RLlib random env :

> **[random\_env.py](https://sourcegraph.com/github.com/ray-project/ray/-/blob/rllib/examples/env/random_env.py)**
>
> https://sourcegraph.com/github.com/ray-project/ray

---

<div class="post-metadata">

**Author:** ![mjlbach](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mjlbach/32/1294_2.png) [@mjlbach](https://discuss.ray.io/u/mjlbach)\
**Post date:** [May 19, 2022, 9:25pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/3 "2022-05-19T21:25:13Z")

</div>

If you are ok downloading our assets (please message me on slack if you have an issue), I made this reproduction:

> **[GitHub - StanfordVL/ig\_navigation](https://github.com/stanfordVL/ig_navigation)**
>
> Contribute to StanfordVL/ig\_navigation development by creating an account on GitHub.

I’ll try to reproduce on random env.

---

<div class="post-metadata">

**Author:** ![mjlbach](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mjlbach/32/1294_2.png) [@mjlbach](https://discuss.ray.io/u/mjlbach)\
**Post date:** [May 19, 2022, 10:12pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/4 "2022-05-19T22:12:28Z")

</div>

This takes up 18 gb roughly for me, does that sound about right?

> **[GitHub - mjlbach/ray\_memory\_repro](https://github.com/mjlbach/ray_memory_repro)**
>
> Contribute to mjlbach/ray\_memory\_repro development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![avnishn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/avnishn/32/1544_2.png) [@avnishn](https://discuss.ray.io/u/avnishn)\
**Post date:** [May 19, 2022, 10:15pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/5 "2022-05-19T22:15:28Z")

</div>

thanks for sharing I’ll take a look

---

<div class="post-metadata">

**Author:** ![mjlbach](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mjlbach/32/1294_2.png) [@mjlbach](https://discuss.ray.io/u/mjlbach)\
**Post date:** [August 12, 2022, 1:53pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/6 "2022-08-12T13:53:27Z")

</div>

Hi @avnishn! Any updates?

---

<div class="post-metadata">

**Author:** ![arturn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/arturn/32/2096_2.png) [@arturn](https://discuss.ray.io/u/arturn)\
**Post date:** [September 14, 2022, 9:00am UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/7 "2022-09-14T09:00:16Z")

</div>

Hi @mjlbach ,

Sorry this took so long.  
I’ve tried to reproduce this on Anyscale on master. I can’t reproduce with the provided script (thanks for providing a proper repro script!).  
Here’s a screenshot of the resource consumption of roughly 10 hours of training:

 ![Screenshot 2022-09-14 at 10.57.09](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/1/13fa5d043798d37c1b974964f3cfc176b29907eb.jpeg)

Can you confirm that this is error still occurs on your side on master or at least 1.13 before we I try to investigate why it would occur in your environment?

Cheers

---

<div class="post-metadata">

**Author:** ![mjlbach](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mjlbach/32/1294_2.png) [@mjlbach](https://discuss.ray.io/u/mjlbach)\
**Post date:** [September 14, 2022, 9:05pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/8 "2022-09-14T21:05:37Z")

</div>

Hi @arturn,

I still managed to reproduce this with ray 2.0 (14 gb of memory, same conda environment.yaml modified to use ray 2.0). I also tried with the latest nightly from today, same memory usage.

---

<div class="post-metadata">

**Author:** ![arturn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/arturn/32/2096_2.png) [@arturn](https://discuss.ray.io/u/arturn)\
**Post date:** [September 14, 2022, 9:35pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/9 "2022-09-14T21:35:57Z")

</div>

The 3GB of memory that you are reading are from **after** the experiment was run. During the experiment it was very close to 14GB, just as with your run.  
Can you reproduce the OOM with the nightlies?

---

<div class="post-metadata">

**Author:** ![mjlbach](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mjlbach/32/1294_2.png) [@mjlbach](https://discuss.ray.io/u/mjlbach)\
**Post date:** [September 14, 2022, 9:50pm UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/10 "2022-09-14T21:50:55Z")

</div>

There’s no OOM, just the 14gb of memory usage. Is this memory usage to be expected?

---

<div class="post-metadata">

**Author:** ![arturn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/arturn/32/2096_2.png) [@arturn](https://discuss.ray.io/u/arturn)\
**Post date:** [September 15, 2022, 8:08am UTC](https://discuss.ray.io/t/expected-ram-usage-for-ppotrainer-debugging-memory-leaks/5428/11 "2022-09-15T08:08:28Z")

</div>

14GB of memory used on a node that treats batches of roughly size 800MB does not seem too high for me.  
You post says your are OOMing and the title includes the word memory leak, so I assumed that you where facing an OOM.
