Need help:RuntimeError: CUDA out of memory

RuntimeError: CUDA out of memory. Tried to allocate 256.00 MiB (GPU 0; 4.00 GiB total capacity; 2.22 GiB already allocated; 94.64 MiB free; 2.30 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

The error message explains that your GPU is running out of memory and you would thus need to reduce the memory usage by e.g. lowering the batch size.

Thanks for ur reply.
enn,I wonder why would pytorch reserve 2.3GB memory?

PyTorch allocated memory to store the model parameters, the input tensors, intermediate forward activations etc. Depending on the used model, input shape etc., this reserved memory would be higher or lower.

Many thanks :grinning: for your detailed answer

Also, in case I misunderstood the question: if you are wondering about the difference between “memory allocated” and “reserved”: the latter reports the allocated and cached memory. Take a look at these docs for more information.