在 python tensorflow 工作簿执行后取消分配内存
De-allocating memory after python tensorflow workbook execution
为了限制内存使用,我阅读了 并尝试了这段代码:
# Assume that you have 12GB of GPU memory and want to allocate ~4GB:
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
这些命令确实释放了内存,但是在代码完成后内存并没有被释放。本期描述:
https://github.com/tensorflow/tensorflow/issues/3701 建议的解决方法是更新驱动程序
“将 GPU 驱动程序从 352.79 升级到 367.35(最新的)后,问题消失了。 “
不幸的是,我无法更新到最新版本的驱动程序。这个问题有没有解决。
我还考虑过将可用内存限制为 docker 容器。
阅读 https://devblogs.nvidia.com/parallelforall/nvidia-docker-gpu-server-application-deployment-made-easy/ 指出“容器可以被限制在系统上的一组有限资源(例如一个 CPU 核心和 1GB 内存)”但是内核目前不支持这个,我在这里尝试添加 1GB新 docker 实例的内存:
nvidia-docker run -m 1024m -d -it -p 8889:8889 -v /users/user1234/jupyter:/notebooks --name tensorflow-gpu-1GB tensorflow/tensorflow:latest-cpu
但这似乎不可能收到警告:
警告:您的内核不支持交换限制功能,没有交换的内存限制。
是否有在 tensorflow python 工作簿完成后释放内存的命令?
Update
终止/重启笔记本后,内存被取消分配。但是如何在笔记本内完成后释放内存。
Ipython 和 jupyter notebooks 不会释放内存,除非你在对象上使用 del
或 xdel
:
https://ipython.org/ipython-doc/3/interactive/magics.html
%xdel:
Delete a variable, trying to clear it from anywhere that IPython’s machinery has references to it. By default, this uses the identity of the named object in the user namespace to remove references held under other names. The object is also removed from the output history.
为了限制内存使用,我阅读了
# Assume that you have 12GB of GPU memory and want to allocate ~4GB:
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
这些命令确实释放了内存,但是在代码完成后内存并没有被释放。本期描述: https://github.com/tensorflow/tensorflow/issues/3701 建议的解决方法是更新驱动程序 “将 GPU 驱动程序从 352.79 升级到 367.35(最新的)后,问题消失了。 “ 不幸的是,我无法更新到最新版本的驱动程序。这个问题有没有解决。
我还考虑过将可用内存限制为 docker 容器。 阅读 https://devblogs.nvidia.com/parallelforall/nvidia-docker-gpu-server-application-deployment-made-easy/ 指出“容器可以被限制在系统上的一组有限资源(例如一个 CPU 核心和 1GB 内存)”但是内核目前不支持这个,我在这里尝试添加 1GB新 docker 实例的内存:
nvidia-docker run -m 1024m -d -it -p 8889:8889 -v /users/user1234/jupyter:/notebooks --name tensorflow-gpu-1GB tensorflow/tensorflow:latest-cpu
但这似乎不可能收到警告: 警告:您的内核不支持交换限制功能,没有交换的内存限制。
是否有在 tensorflow python 工作簿完成后释放内存的命令?
Update
终止/重启笔记本后,内存被取消分配。但是如何在笔记本内完成后释放内存。
Ipython 和 jupyter notebooks 不会释放内存,除非你在对象上使用 del
或 xdel
:
https://ipython.org/ipython-doc/3/interactive/magics.html
%xdel: Delete a variable, trying to clear it from anywhere that IPython’s machinery has references to it. By default, this uses the identity of the named object in the user namespace to remove references held under other names. The object is also removed from the output history.