[英]What is the right way to manage memory in Theano for training sets that cannot fit in RAM?
TL; DR:如何在不占用更多內存的情況下為Theano功能提供更多數據?
我遇到的問題是,使用Theano在GPU上訓練我的ML算法會導致GPU最終用盡內存。 我稍微偏離了教程,因為我的數據集太大而無法完全讀入內存(這對於視頻算法來說也是一個問題,對吧?),所以我只是通過Theano而不是使用索引輸入和更新方案。直接運行ndarrays。
讓我舉一個例子說明我的意思。 在Theano的Logistic回歸教程中,它說要做的事情是:
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函數提供更多數據?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.