以下两个循环将使用内存,直到我用完,但我不明白为什么。我在每次迭代结束时删除所有创建的变量,但它仍然泄漏。
!pip3 install cupy-cuda101
import cupy as cp
import numpy as np
from sklearn.preprocessing import PolynomialFeatures
xtrain = cp.asnumpy(cp.random.uniform(-1,1,size = (150000,50)))
for i in range(0,1000):
weights = cp.random.uniform(-1,1,size = (1275,1000))
for chunk in range(0,xtrain.shape[0],5000):
xchunk = xtrain[chunk:chunk+5000,:]
poly=PolynomialFeatures(interaction_only = True, include_bias = False)
xchunk = cp.array(poly.fit_transform(xchunk))
ranks = cp.matmul(xchunk,weights)
del ranks, xchunk, poly
del weights
xtrain 也只是浮点数据,介于 -1 和 1 之间。
萧十郎
相关分类