Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Memory Google Colab上的GPU内存不足错误消息_Memory_Gpu_Google Colaboratory - Fatal编程技术网

Memory Google Colab上的GPU内存不足错误消息

Memory Google Colab上的GPU内存不足错误消息,memory,gpu,google-colaboratory,Memory,Gpu,Google Colaboratory,我正在使用谷歌Colab上的GPU来运行一些深入的学习代码 我已经完成了70%的培训,但现在我不断遇到以下错误: RuntimeError: CUDA out of memory. Tried to allocate 2.56 GiB (GPU 0; 15.90 GiB total capacity; 10.38 GiB already allocated; 1.83 GiB free; 2.99 GiB cached) 我正在努力理解这意味着什么。它是在谈论RAM内存吗?如果是这样的话,代码

我正在使用谷歌Colab上的GPU来运行一些深入的学习代码

我已经完成了70%的培训,但现在我不断遇到以下错误:

RuntimeError: CUDA out of memory. Tried to allocate 2.56 GiB (GPU 0; 15.90 GiB total capacity; 10.38 GiB already allocated; 1.83 GiB free; 2.99 GiB cached)
我正在努力理解这意味着什么。它是在谈论RAM内存吗?如果是这样的话,代码应该和以前一样运行,不是吗?当我尝试重新启动它时,内存消息立即出现。为什么我今天启动它时会比昨天或前一天启动时使用更多RAM

或者这是关于硬盘空间的信息?我可以理解这一点,因为代码在运行时会保存东西,因此硬盘使用量是累积的

任何帮助都将不胜感激


因此,如果只是GPU内存不足-有人能解释一下为什么错误消息说
10.38 GiB已经分配了
-当我开始运行某些东西时,怎么可能已经分配了内存。那会被其他人使用吗?我是否需要等待并稍后再试

下面是我运行代码时GPU使用情况的屏幕截图,就在代码耗尽内存之前:


我发现有些人似乎也有类似的问题。当我在该线程上运行建议的代码时,我看到:

Gen RAM Free: 12.6 GB  | Proc size: 188.8 MB
GPU RAM Free: 16280MB | Used: 0MB | Util   0% | Total 16280MB
这似乎表明有16 GB的内存可用


我很困惑。

您的GPU内存不足。如果您正在运行python代码,请尝试在您的代码之前运行此代码。它将显示您拥有的内存量。请注意,如果尝试加载大于总内存的图像,则会失败

# memory footprint support libraries/code
!ln -sf /opt/bin/nvidia-smi /usr/bin/nvidia-smi
!pip install gputil
!pip install psutil
!pip install humanize

import psutil
import humanize
import os
import GPUtil as GPU

GPUs = GPU.getGPUs()
# XXX: only one GPU on Colab and isn’t guaranteed
gpu = GPUs[0]
def printm():
    process = psutil.Process(os.getpid())
    print("Gen RAM Free: " + humanize.naturalsize(psutil.virtual_memory().available), " |     Proc size: " + humanize.naturalsize(process.memory_info().rss))
    print("GPU RAM Free: {0:.0f}MB | Used: {1:.0f}MB | Util {2:3.0f}% | Total     {3:.0f}MB".format(gpu.memoryFree, gpu.memoryUsed, gpu.memoryUtil*100, gpu.memoryTotal))
printm()

GoogleColab资源分配是动态的,基于用户过去的使用情况。假设一个用户最近使用了更多的资源,而一个新用户使用Colab的频率较低,那么他将在资源分配中获得相对更多的优先权

因此,要最大限度地利用Colab,请关闭所有Colab选项卡和所有其他活动会话,重新启动要使用的会话的运行时。您肯定会得到更好的GPU分配。


如果您正在培训NN,但仍然面临相同的问题,请尝试减少批处理大小。

尝试将批处理大小减少到8或16。这对我来说很有效

“GPU 0”应该是一个非常明显的线索——你的GPU内存已经用完了