close

[Solved] RuntimeError: CUDA out of memory. Tried to allocate

Hello Guys, How are you all? Hope You all Are Fine. Today I am just facing following error RuntimeError: CUDA out of memory. Tried to allocate in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How RuntimeError: CUDA out of memory. Tried to allocate Error Occurs ?

I am just facing following error.

RuntimeError: CUDA out of memory. Tried to allocate 😊 MiB (GPU 😊; 😊 GiB total capacity; 😊 GiB already allocated; 😊 MiB free; 😊 cached)

I am just trying to empty_cache in loop but I am facing error.

How To Solve RuntimeError: CUDA out of memory. Tried to allocate Error ?

  1. How To Solve RuntimeError: CUDA out of memory. Tried to allocate Error ?

    To Solve RuntimeError: CUDA out of memory. Tried to allocate Error Just reduce the batch size In my case I was on batch size of 32 So that I just changed it to 15 And My error was solved. Just use This torch.cuda.memory_summary(device=None, abbreviated=False). It is because of mini-batch of data does not fit on to GPU memory. Just decrease the batch size. When I set batch size = 256 for cifar10 dataset I got the same error; Then I set the batch size = 128, it is solved.

  2. RuntimeError: CUDA out of memory. Tried to allocate

    To Solve RuntimeError: CUDA out of memory. Tried to allocate Error Just reduce the batch size In my case I was on batch size of 32 So that I just changed it to 15 And My error was solved. Just use This torch.cuda.memory_summary(device=None, abbreviated=False). It is because of mini-batch of data does not fit on to GPU memory. Just decrease the batch size. When I set batch size = 256 for cifar10 dataset I got the same error; Then I set the batch size = 128, it is solved.

Solution 1: reduce the batch size

Just reduce the batch size In my case I was on batch size of 32 So that I just changed it to 15 And My error was solved.

Solution 2: Use this

Just use This.

torch.cuda.memory_summary(device=None, abbreviated=False)

Solution 3: Follow this

It is because of mini-batch of data does not fit on to GPU memory. Just decrease the batch size. When I set batch size = 256 for cifar10 dataset I got the same error; Then I set the batch size = 128, it is solved.

Solution 4: Open terminal and a python prompt

Open terminal and a python prompt

import torch
torch.cuda.empty_cache()

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment