gpt4 book ai didi

python-2.7 - 在创建带有借位= True的Theano共享变量时内存不足

转载 作者:行者123 更新时间:2023-12-04 03:50:57 25 4
gpt4 key购买 nike

我正在尝试将一个非常大的数据集(ndarray中的〜28GB RAM)分配给theano共享变量,并使用borrow = True以避免复制内存。为此,我使用以下功能:

def load_dataset(path):
# Load dataset from memory
data_f = np.load(path+'train_f.npy')
data_t = np.load(path+'train_t.npy')

# Split into training and validation
return (
(
theano.shared(data_f[:-1000, :], borrow=True),
theano.shared(data_t[:-1000, :], borrow=True)
), (
theano.shared(data_f[-1000:, :], borrow=True),
theano.shared(data_t[-1000:, :], borrow=True)
)
)

为了避免数据转换,在将数组保存到磁盘之前,我已经将它们定义为正确的格式(然后填充它们并使用np.save()将其转储到磁盘中):
data_f = np.ndarray((len(rows), 250*250*3), dtype=theano.config.floatX)
data_t = np.ndarray((len(rows), 1), dtype=theano.config.floatX)

但是,似乎theano还是想复制内存,这使我遗失了以下错误:

分配25594500000字节的设备内存(内存不足)时出错。驱动程序报告空闲3775729664字节,总计4294639616字节。

Theano配置为可在GPU(GTX 970)上运行。

最佳答案

除了使用theano.shared之外,还可以使用theano.tensor._shared强制将数据分配到CPU内存中。固定代码最终如下所示:

def load_dataset(path):
# Load dataset from memory
data_f = np.load(path+'train_f.npy')
data_t = np.load(path+'train_t.npy')

# Split into training and validation
return (
(
theano.tensor._shared(data_f[:-1000, :], borrow=True),
theano.tensor._shared(data_t[:-1000, :], borrow=True)
), (
theano.tensor._shared(data_f[-1000:, :], borrow=True),
theano.tensor._shared(data_t[-1000:, :], borrow=True)
)
)

关于python-2.7 - 在创建带有借位= True的Theano共享变量时内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29649623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com