# Running into out of memory issues

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-into-out-of-memory-issues%2F35613%3E%5C
**Category:** 🧨 Diffusers\
**Created:** [April 5, 2023, 5:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-into-out-of-memory-issues%2F35613 "2023-04-05T05:52:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kvs-moudgalya](https://avatars.discourse-cdn.com/v4/letter/k/ecccb3/32.png) [@kvs-moudgalya](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkvs-moudgalya)%5C
**Post date:** [April 5, 2023, 5:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-into-out-of-memory-issues%2F35613%2F1 "2023-04-05T05:52:57Z")

</div>

Hi,

- I’m currently trying to train huggingface Diffusers for 2D image generation task with images as input.
- Training on AWS G5 instances i.e., A10G GPU’s with 24GB GPU memory.
- I’m running into out of memory issues when I go beyond image size of 256x256 and batch size of 8.
- Results with Image size = 256 and batch size = 8 is unacceptable
- I did use gradient accumulation and mixed precision training.
- Using 1 attention block only.

Trying to understand is it a genuine memory issue or can it be solved by some other approaches?  
Is diffusion models so heavy that even a 24GB memory GPU is insufficient?  
What’s the typical memory requirement for running image to image diffusion models, for generating images resolution higher than 512x512

Thanks and regards  
KVS Moudgalya

---

<div class="post-metadata">

**Author:** ![sayakpaul](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sayakpaul/32/23772_2.png) [@sayakpaul](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsayakpaul)%5C
**Post date:** [April 6, 2023, 3:13am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-into-out-of-memory-issues%2F35613%2F2 "2023-04-06T03:13:27Z")

</div>

Hey, sorry that you’re running into the issues.

The first thing I would try doing is to use `xFormers`: [diffusers/examples/text\_to\_image at main · huggingface/diffusers · GitHub](https://github.com/huggingface/diffusers/tree/main/examples/text_to_image#training-with-xformers)

---

<div class="post-metadata">

**Author:** ![kvs-moudgalya](https://avatars.discourse-cdn.com/v4/letter/k/ecccb3/32.png) [@kvs-moudgalya](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkvs-moudgalya)%5C
**Post date:** [April 24, 2023, 11:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-into-out-of-memory-issues%2F35613%2F3 "2023-04-24T11:30:50Z")

</div>

Thanks @sayakpaul for your response.

I did enable xFormers in the huggingface diffusers, there is slight a bit of improvement in computational speed, but couldn’t not much in terms of memory, can’t increase image size above 256 and batch size above 8, getting out of memory issues if I go beyond these dimensions.
