torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.67 GiB a
时间: 2023-11-05 08:42:49 浏览: 127
vailable; 40.00 KiB already allocated; 19.94 MiB free; 4.00 MiB cached)
This error message indicates that the program tried to allocate 20.00 MiB of memory on the GPU, but there was not enough memory available. The GPU has a total capacity of 2.00 GiB, but only 1.67 GiB was available at the time. 40.00 KiB had already been allocated, leaving only 19.94 MiB free. Additionally, 4.00 MiB had been cached, which means that it was reserved for future use but not currently in use.
To resolve this issue, you can try one or more of the following:
1. Reduce the size of the input data or the size of the model being used. This will reduce the amount of memory required.
2. Increase the GPU memory capacity. If possible, add more memory to the GPU or switch to a GPU with a larger memory capacity.
3. Use a smaller batch size. This will reduce the amount of memory required for each iteration.
4. Use gradient checkpointing. This technique allows the model to compute gradients for small subsets of parameters at a time, reducing the amount of memory required.
5. Use mixed precision training. This technique allows the model to use 16-bit floating point numbers instead of 32-bit, reducing the amount of memory required.
阅读全文