GPU Memory Usage占满而GPU-Util却为0的调试
最近使用github上的一个开源项目训练基于CNN的翻译模型,使用THEANO_FLAGS='floatX=float32,device=gpu2,lib.cnmem=1' python run_nnet.py -w data/exp1/,运行时报错,打印"The image and the kernel must have the same type. inputs(float64), kerns(float32)"的错误,然后使用THEANO_FLAGS='floatX=float64,device=gpu2,lib.cnmem=1' python run_nnet.py -w data/exp1/,运行成功。但几百个训练数据却需要十几分钟,运行十分缓慢。
使用nvidia-smi -l查看GPU情况,发现GPU memory usage 是满了,而GPU-Util却是0,top命令看CPU却是1600%(16核CPU),这与跑其他任务很不相同(GPU-Util接近100%,CPU不到100%)。看起来是CPU被打满了,而GPU空着,运算完全在CPU上进行。查找原因,Google这个问题,却没有找到什么满足需求的解答,只好回过头来阅读官方文档。
首先使用assert_no_cpu_op=raise:
THEANO_FLAGS="floatX=float64,device=gpu2,force_device=True,mode=FAST_RUN,lib.cnmem=1,assert_no_cpu_op=raise" python run_nnet.py
按照官方文档,如果设置了这个参数,有在CPU上执行的操作,是应该抛异常的。然而实际情况并没有。
仔细阅读官方文档,发现在theano的FAQ文档(refer: http://deeplearning.net/software/theano/faq.html)中说:
“It should be noted that using float32 and int{32, 64} together inside a function would provide float64 as output.
Since the GPU can’t compute this kind of output, it would be preferable not to use those dtypes together.
To help you find where float64 are created, see the warn_float64
Theano flag.”
也就是float64的话,GPU是不能计算的,所以就是CPU计算。进一步的,在使用GPU的文档中(refer: http://deeplearning.net/software/theano/tutorial/using_gpu.html):
"
- Only computations with float32 data-type can be accelerated. Better support for float64 is expected in upcoming hardware but float64 computations are still relatively slow (Jan 2010).
- Prefer constructors like
matrix
,vector
andscalar
todmatrix
,dvector
anddscalar
because the former will give you float32 variables whenfloatX=float32
. - Ensure that your output variables have a float32 dtype and not float64. The more float32 variables are in your graph, the more work the GPU can do for you."
所以原因就是代码中有float64的输入。根据文档中建议,可以使用config的warn_float64来帮助寻找float64的输入,所以执行:
THEANO_FLAGS="floatX=float64,device=gpu2,force_device=True,mode=FAST_RUN,lib.cnmem=1,warn_float64=raise" python run_nnet.py -w data/exp1/
异常栈如下:
Traceback (most recent call last):
File "run_nnet.py", line 570, in <module>
main()
File "run_nnet.py", line 208, in main
nnet_q.set_input((x_q, x_q_overlap))
File ".../nn_layers.py", line 65, in set_input
self.output = self.output_func(input)
File ".../nn_layers.py", line 89, in output_func
layer.set_input(cur_input)
这个栈信息之反映了在网络set_input的时候有float64,但是float64的变量可是在此之前早就创建好的,所以还是无法定位到问题,这是一个然并卵的参数。
由于代码中的输入几乎都是由numpy生成或者load的,查阅numpy的文档,发现numpy建立数组的操作,如果没有指定dtype,那么默认就是float64,例如numpy.ones, numpy.zero, numpy.random.RandomState.randn等,theano的config(refer: http://deeplearning.net/software/theano/library/config.html)中有一个cast_policy参数,按照文档的说法,当设定floatX=float32,同时设置cast_policy=numpy+floatX时,执行过程中会自动的把numpy产生的数组转换成float32的。于是执行:
THEANO_FLAGS="floatX=float32,device=gpu2,force_device=True,mode=FAST_RUN,lib.cnmem=1,cast_policy=numpy+floatX" python run_nnet.py -w data/exp1/
结果。。。依然报错:"NotImplementedError: The image and the kernel must have the same type.inputs(float64), kerns(float32)"
这个参数的说明:
" Note that ‘numpy+floatX’ is not currently behaving exactly as planned (it is a work-in-progress), and thus you should consider it as experimental. "
好吧,果然还是实验性质的,有些情况搞不定。
那么最后一招,仔细的检查所有numpy的调用,把所有创建数组的地方都显示的指定dtype=numpy.float32,全部改好后,执行:
THEANO_FLAGS="floatX=float32,device=gpu2,force_device=True,mode=FAST_RUN,lib.cnmem=1" python run_nnet.py -w data/exp1/
成功的把GPU-Util打满,CPU也降到了100%,训练几百条数据的时间一下降到秒杀!
经验总结:
遇到问题阅读官方文档是十分有效的方法,往往常见问题在这些文档中已经说得很明确了,可以帮你明确的了解问题所在,进而找到解决方案。
GPU Memory Usage占满而GPU-Util却为0的调试的更多相关文章
- Reducing and Profiling GPU Memory Usage in Keras with TensorFlow Backend
keras 自适应分配显存 & 清理不用的变量释放 GPU 显存 Intro Are you running out of GPU memory when using keras or ten ...
- Tensorflow默认占满全部GPU的全部资源
一台服务器上装了多块GPU,默认情况下启动一个深度学习训练任务时,这个任务会占满每一块GPU的几乎全部存储空间.这就导致一个服务器基本上只能执行一个任务,而实际上任务可能并不需要如此多的资源,这相当于 ...
- Allowing GPU memory growth
By default, TensorFlow maps nearly all of the GPU memory of all GPUs (subject to CUDA_VISIBLE_DEVICE ...
- tensorflow 运行效率 GPU memory leak 问题解决
问题描述: Tensorflow 训练时运行越来越慢,重启后又变好. 用的是Tensorflow-GPU 1.2版本,在GPU上跑,大概就是才开始训练的时候每个batch的时间很低,然后随着训练的推进 ...
- 重置GPU显存 Reset GPU memory after CUDA errors
Sometimes CUDA program crashed during execution, before memory was flushed. As a result, device memo ...
- 【JVM】jdk1.8-jetty-swap被占满问题排查
背景 线上服务收到报警,报警内容:虚拟机swap区占用比例超过80%,如图: 本文着重描述排查问题的过程,在这个过程中不断的猜测–>验证–>推翻–>再猜测–>再验证–>再 ...
- 【Android 应用开发】Android中使用ViewPager制作广告栏效果 - 解决ViewPager占满全屏页面适配问题
. 参考界面 : 携程app首页的广告栏, 使用ViewPager实现 自制页面效果图 : 源码下载地址: http://download.csdn.net/detail/han1202 ...
- Android中使用ViewPager制作广告栏效果 - 解决ViewPager占满全屏页面适配问题
. 参考界面 : 携程app首页的广告栏, 使用ViewPager实现 自制页面效果图 : 源码下载地址: http://download.csdn.net/detail/han1202 ...
- 一个服务io占满,服务器无响应
(1).服务器io占满,服务无响应, sar -q -f /var/log/sa/sa28 上图显示plist-sz 增加了一倍 plist-sz 说明:进程列表中的进程(processes)和线程 ...
随机推荐
- PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
- Redis 入门之Redis简介
Reids 是一个开源的高性能键值对数据库.它通过多种键值数据类型来适应不同场景下的存储需求,并借助许多高层级的接口使其可以胜任如缓存.队列系统等不同的角色. 1.Reids的诞生 Redis到底是在 ...
- ruby on rails validates
validates :conclusion, :presence => true, :inclusion => { :in => [0,1] } validates :email, ...
- 图解Kerberos认证工作原理
本文是我在看了这篇英文说明之后的总结 https://technet.microsoft.com/zh-cn/library/cc961976.aspx 是总结,不是翻译,所以是我看后按自己的理解写的 ...
- P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...
- Linux内核分析 03
一,构造一个简单的Linux系统MenuOS 1.Linux内核源代码简介 回顾一下前面的三大法宝和两把宝剑. arch/x86目录下的代码需要重点关注 阅读代码的时候把除了x86以外的都删掉会有利于 ...
- ArrayList扩容
jdk1.5 public ArrayList(int initialCapacity) { super(); if (initialCapacity < 0) throw new Illega ...
- 生成二维码Base64图片
这个写了,但是自己没有用,发现浏览器有的不兼容 代码: string str = System.Configuration.ConfigurationManager.AppSettings[" ...
- POJ 1142 Smith Numbers(分治法+质因数分解)
http://poj.org/problem?id=1142 题意: 给出一个数n,求大于n的最小数,它满足各位数相加等于该数分解质因数的各位相加. 思路:直接暴力. #include <ios ...
- building '_mysql' extension error: [WinError 2] 系统找不到指定的文件。
D:\4yanjiiu\APIzidong\MySQL-python-1.2.5>py running install running bdist_egg running egg_info wr ...