【发布时间】:2016-03-15 18:19:34
【问题描述】:
TL;DR: 如何在不占用更多内存的情况下向 Theano 函数提供更多数据?
我遇到的问题是,使用 Theano 在 GPU 上训练我的 ML 算法会导致 GPU 最终耗尽内存。我稍微偏离了教程,因为我的数据集太大而无法完全读入内存(这也一定是视频算法的问题,对吧?),所以我没有使用索引输入和更新方案,而是通过 Theano直接运行ndarrays。
让我举一个例子来说明我的意思。在 Theano 的 Logistic Regression 教程中,它说要按照以下方式做一些事情:
train_model = theano.function(
inputs=[index],
outputs=cost,
updates=updates,
givens={
x: train_set_x[index * batch_size: (index + 1) * batch_size],
y: train_set_y[index * batch_size: (index + 1) * batch_size]
}
)
这需要将test_set_x 和test_set_y 加载到内存中,并且本教程使用SharedVariable 来存储完整 数据集。
好吧,我的数据集是巨大的(很多千兆字节),这意味着它不能一次全部加载到内存中,所以我修改了我的数据以直接获取数据,因此:
train_model = theano.function(
inputs=[input, classes],
outputs=cost,
updates=updates
)
然后我做了一些看起来有点像这样的事情:
for count, data in enumerate(extractor):
observations, labels = data
batch_cost = train_model(observations, labels)
logger.debug("Generation %d: %f cost", count, batch_cost)
我想我可能从根本上误解了如何正确地将数据传递给 GPU,而不会出现一些讨厌的 python 垃圾收集脏东西。看起来这只是在模型内部占用越来越多的内存,因为在经过(大量)批次训练后,我收到如下错误:
Error when tring to find the memory information on the GPU: initialization error
Error freeing device pointer 0x500c88000 (initialization error). Driver report 0 bytes free and 0 bytes total
CudaNdarray_uninit: error freeing self->devdata. (self=0x10cbbd170, self->devata=0x500c88000)
Exception MemoryError: 'error freeing device pointer 0x500c88000 (initialization error)' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
如何在不占用更多内存的情况下向 Theano 函数提供更多数据?
【问题讨论】:
标签: python numpy theano theano-cuda