fetch_var 从GPU拷贝parameter到CPU的np.array,内存泄漏
Created by: LihangLiu
fetch_var 从GPU拷贝parameter到CPU的np.array,内存泄漏。 示例代码如下:
import paddle
import paddle.fluid as fluid
from paddle.fluid import layers
import numpy as np
def fetch_var(program, scope):
for param in program.global_block().all_parameters():
var = scope.find_var(param.name)
t = var.get_tensor()
array = np.array(t) # TODO: This line will cause memory leak
def net():
x = layers.data(name='x', shape=[-1, 1000], dtype='float32')
h = layers.fc(x, size=1000)
y = layers.reduce_mean(h)
return y
def train():
place = fluid.CUDAPlace(0)
scope = fluid.Scope()
program = fluid.Program()
start_up = fluid.Program()
with fluid.scope_guard(scope):
with fluid.program_guard(program, start_up):
with fluid.unique_name.guard():
out = net()
exe = fluid.Executor(place)
exe.run(start_up)
print('start showing memory leak')
while True:
fetch_var(program, scope)
if __name__ == "__main__":
train()
How to run:
CUDA_VISIBLE_DEVICES=0 python fetch_var.py
系统信息:
- centos
- fluid 1.3
- CUDA9 CUDNN7