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)和线程 ...
随机推荐
- linux rsync安装与使用
rsync Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status} rsync默认配置文件 # default ...
- 52. N-Queens II(数个数)
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- spring整合ehcache 注解实现查询缓存,并实现实时缓存更新或删除
写在前面:上一篇博客写了spring cache和ehcache的基本介绍,个人建议先把这些最基本的知识了解了才能对今天主题有所感触.不多说了,开干! 注:引入jar <!-- 引入ehcach ...
- 微信小程序中公用内容
微信小程序中各个页面调用公用的js 在util.js文件中 // 跳转哪里 function go(where) { wx.reLaunch({ url: where, }) } // 将方法暴露出去 ...
- Makefile解析(最简单的LED)
①led_sp.bin: start.o led.o #led_sp.bin是由 start.o 和 led.o 生成 ②arm-linux-ld -Ttext 0x0 -o led_sp.elf $ ...
- 【大型web架构】一个大型web系统架构设计和技术选型的讨论摘录
1.数据库压力问题 所有的压力最终都会反映到数据库方面,一定要对数据库有一个整体的规划. 可以按照业务.区域等等特性对数据库进行配置,可以考虑分库.使用rac.分区.分表等等策略,确保数据库能正常的进 ...
- 使用javascript模拟常见数据结构(一)
数据结构和算法可算是每个程序员的必备技能,而随着前端工作的深入,对于数据结构的知识真的是越来越需要掌握了.好了,于是乎最近看了<javascript数据结构和算法>,算是对于后面的使用C语 ...
- Spark读取结构化数据
读取结构化数据 Spark可以从本地CSV,HDFS以及Hive读取结构化数据,直接解析为DataFrame,进行后续分析. 读取本地CSV 需要指定一些选项,比如留header,比如指定delimi ...
- vue双向绑定原理及实现
vue双向绑定原理及实现 一.总结 一句话总结:vue中的双向绑定主要是通过发布者-订阅者模式来实现的 发布 订阅 1.单向绑定和双向绑定的区别是什么? model view 更新 单向绑定:mode ...
- 获取文本中所有的<img>标签的位置,获取所有img标签的src
public static int[] GetImagePos(string str) { str = str.Replace("$", " "); str = ...