# Sweeps using more RAM memory

**URL:** <https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040>\
**Category:** W&B Help\
**Tags:** sweeps\
**Created:** [September 11, 2023, 7:51am UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040 "2023-09-11T07:51:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jymsungmi](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jymsungmi](https://community.wandb.ai/u/jymsungmi)\
**Post date:** [September 11, 2023, 7:51am UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/1 "2023-09-11T07:51:32Z")

</div>

Hi!

I’m using Sweeps to optimize hyperparameters while training a PyTorch Lightning model.  
Currently I’m using parallel agents and each runs more than 10 jobs in a container, and all runs on kubernetes. (not the server itself. only job container is run on kubernetes)

Actually there is no big problem, but each container uses three times more cpu ram memory than a normal pytorchJob pod container.

At first, I thought anyway Sweeps using kind of training loop, and that’s why memory is increased. But I realized that it didn’t increased, it just use high memory from the first run.

Also, I’m using w&b as an experiment tracking purpose with the same model, but it didn’t use that much resources.  
so I think Sweeps using some more resources, but I’m not sure and I don’t know how to decrease that.

I searched a lot, but I couldn’t find any related issues.  
so If someone knows or experiences this kind of issue, let me know!

Thank you.

---

<div class="post-metadata">

**Author:** ![nathank](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nathank](https://community.wandb.ai/u/nathank)\
**Post date:** [September 13, 2023, 7:55pm UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/2 "2023-09-13T19:55:32Z")

</div>

Hi @jymsungmi, are you creating the sweep through Python or by defining a sweep.yaml and using the CLI to start the sweep?

I ask because the Python implementation uses threading rather than multi-processesing so the memory might not be being getting released at the end of each run.

Thank you,  
Nate

---

<div class="post-metadata">

**Author:** ![jymsungmi](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jymsungmi](https://community.wandb.ai/u/jymsungmi)\
**Post date:** [September 14, 2023, 4:39am UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/3 "2023-09-14T04:39:40Z")

</div>

Hi @nathank ,

yes i’m creating the sweep through Python…  
okay, then I need to check threading memory usage part.

but W&B using multiprocessing inside library code and it already define thread.join to finish the thread.  
Why is my process not automatically release the memory?

Thank you!

---

<div class="post-metadata">

**Author:** ![nathank](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nathank](https://community.wandb.ai/u/nathank)\
**Post date:** [September 19, 2023, 7:27pm UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/4 "2023-09-19T19:27:24Z")

</div>

Hi @jymsungmi, I don’t know the exact cause of the memory not getting released when the thread ends but it seems to typically be resolved by using the CLI implementation of sweeps so that wandb uses multiprocessing.

I’ve seen this happen with Numpy arrays for example where in certain circumstances they don’t release RAM when the thread completes.

Would it be an option to refactor to defining the sweep with a yaml and using CLI to test that this does indeed solve the memory issue?

---

<div class="post-metadata">

**Author:** ![nathank](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nathank](https://community.wandb.ai/u/nathank)\
**Post date:** [September 22, 2023, 4:47pm UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/5 "2023-09-22T16:47:23Z")

</div>

Hi @jymsungmi, I just wanted to follow up and see if you had a chance to try this?

---

<div class="post-metadata">

**Author:** ![jymsungmi](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jymsungmi](https://community.wandb.ai/u/jymsungmi)\
**Post date:** [September 25, 2023, 4:04am UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/6 "2023-09-25T04:04:27Z")

</div>

Hi @nathank ,  
thanks for your replying to help me.

I didn’t tried to deploy with CLI. I tried other things and now it seems fixed, so I’ve moved on.  
I added gc.collect() to my training code, and then the process’s memory usage had not being increased.  
also I changed deploy method.  
before I deployed as just a pod, but now I deployed training as a PytorchJob in k8s.

Thank you once again!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [November 24, 2023, 4:05am UTC](https://community.wandb.ai/t/sweeps-using-more-ram-memory/5040/7 "2023-11-24T04:05:11Z")

</div>

Closed on November 24, 2023, 4:05am UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
