【问题标题】:Jupyter Notebook GPU memory release after training model训练模型后 Jupyter Notebook GPU 内存释放
【发布时间】:2021-07-30 20:24:31
【问题描述】:
在使用 Jupyter notebook 完成深度学习模型训练后,我们如何清理 GPU 内存。问题是,无论我坚持使用什么框架(tensorflow、pytorch),存储在 GPU 中的内存都不会被释放,除非我手动终止进程或终止内核并重新启动 Jupyter。您知道我们如何通过自动化步骤来解决这个问题吗?
【问题讨论】:
标签:
python
memory-management
deep-learning
jupyter-notebook
gpu
【解决方案1】:
我发现的唯一解决方法是使用线程。使用子流程执行训练。
一个例子:
def Training(arguments):
....
....
return model
if __name__=='__main__':
Subprocess = Process(# The complete function defined above
target = Training,
# Pass the arguments defined in the complete function
# above.
# Note - The comma after the arguments : In order for
# Python
# to understand this is a tuple
args = (arguments, ))
# Starting the defined subprocess
Subprocess.start()
# Wait for the subprocess to get completed
Subprocess.join()