CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.04 GiB already allocated; 0 bytes free; 1.08 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
时间: 2023-09-26 20:09:04 浏览: 62
这个错误表明你的GPU内存不足,PyTorch试图分配20.00 MiB的内存却失败了。已经有1.04 GiB的内存被分配了,没有剩余内存可用。你可以尝试使用 max_split_size_mb 参数设置最大拆分大小以避免内存碎片化。PYTORCH_CUDA_ALLOC_CONF提供了内存管理方面的文档,你可以参考它来解决这个问题。此外,你也可以尝试减小模型的批次大小或者使用更小的模型来减少内存占用。
相关问题
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.31 GiB already allocated; 0 bytes free; 1.34 GiB reserved in total by PyTorch)
这个错误表示在尝试分配20.00 MiB的内存时,CUDA GPU的内存已经用完了。这可能是因为你的模型或数据集太大,超出了GPU的容量限制。解决这个问题的一种方法是减少模型大小或使用更小的数据集。你还可以尝试以下方法来解决这个问题:
1. 减少批次大小(batch size):减少每次训练中的样本数量,这将减少对GPU内存的需求。
2. 使用更小的模型:如果可能的话,可以尝试使用更小的模型或者减少模型的层数和参数量。
3. 使用更高性能的GPU:如果你使用的是较旧或较低性能的GPU,可能会遇到内存不足的问题。考虑升级到具有更大内存容量的GPU。
4. 清理GPU内存:在每个训练迭代之后调用`torch.cuda.empty_cache()`来清理GPU内存。
如果上述方法都无法解决问题,那可能需要考虑使用分布式训练或者在云平台上使用更强大的GPU来处理大型模型和数据集。
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.67 GiB a
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.
阅读全文