版本(重要)
按照官方指南, 花了2个多小时安装好了一堆东西并配置好一堆环境变量之后,终于在vs里边运行成功,并且测试通过,识别了GPU。还没来得及高兴一会,就发现发现Python的TensorFlow不识别GPU。
简直晴天霹雳!
上网查主要是版本问题,于是又重新参考TensorFlow的官网GPU对应版本下了几个G的文件。
我目前用的套餐:
版本 | Python 版本 | 编译器 | 构建工具 | cuDNN | CUDA |
---|---|---|---|---|---|
tensorflow_gpu-2.6.0 | 3.6-3.9 | MSVC 2019 | Bazel 3.7.2 | 8.1 | 11.2 |
再次安装后依旧不识别,凌晨三点我有点抓狂。
后来发现原来的新版本没卸载干净,旧版不识别,全部删除重装。
又发现CuDNN的目录结构跟新版不一样,之前装的也没删干净,环境变量还设置错了。(应该是添加CUDNN\v8.x\bin这个目录)
GPU
1050笔记本版, 官网没有明确列出可以, 但是桌面版的列出来了,试试发现是笔记本版1050也可以的。
代码兼容性
因为切换了各种库的版本,导致代码兼容性出问题, 又是一顿改。
+=
符号有的地方不能用, 改成了a = a + 1
这种
有个gradient的函数不能用,前边加个这个兼容性函数就可以了
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
最后
终于!!!
GPU: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
然而!!!!!!
(1) Resource exhausted: OOM when allocating tensor with shape[53200,128] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[{{node gradients/MatMul_3_grad/MatMul_1}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info. This isn't available when running in Eager mode.
0 successful operations.
0 derived errors ignored.
Process finished with exit code 1