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,vectorandscalartodmatrix,dvectoranddscalarbecause 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)和线程 ...
随机推荐
- svn命令行使用
1.将文件checkout到本地目录 svn checkout path(path是服务器上的目录) 例如:svn checkout svn://192.168.1.1/pro/domai ...
- 11. Container With Most Water(装最多的水 双指针)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- PR曲线 ROC曲线的 计算及绘制
在linear model中,我们对各个特征线性组合,得到linear score,然后确定一个threshold,linear score < threshold 判为负类,linear sc ...
- Educational Codeforces Round 47
A. Game Shopping 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, m, c[N ...
- KEYENCE Programming Contest 2019 Solution
A - Beginning 签到. #include <bits/stdc++.h> using namespace std; int main() { ]; while (scanf(& ...
- [one day one question] 有没有免费接收短信验证用于注册的软件或者平台?
问题描述: 想要批量注册撸羊毛,有手机短信验证码验证,这怎么破? 解决方案: 免费的肯定没有的,不过"一条短信收费一毛钱"倒是有一个,本人是亲自试用过,该平台收不到短信验证码不收费 ...
- SQL学习笔记三(补充-2)之MySQL数据类型
阅读目录 一 介绍 二 数值类型 三 日期类型 四 字符串类型 五 枚举类型与集合类型 一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 ...
- 2017-2018-1 JaWorld 团队作业--冲刺2
2017-2018-1 JaWorld 团队作业--冲刺2 (20162314) 总体架构 我们本次团队项目设定为基于Android系统Java架构下的打飞机小游戏 游戏中所有模型的原型设定是精灵,因 ...
- 斜率优化DP学习笔记
先摆上学习的文章: orzzz:斜率优化dp学习 Accept:斜率优化DP 感谢dalao们的讲解,还是十分清晰的 斜率优化$DP$的本质是,通过转移的一些性质,避免枚举地得到最优转移 经典题:HD ...
- 使用 v-cloak 防止页面加载时出现 vue.js 的变量名
知识点:使用 v-cloak 防止页面加载时出现 vue.js 的变量名 场景:在使用vue语法,实现下拉框功能时,展示数据列表之前,出现对应的 vuejs 变量名 代码: var vm = new ...