TensorFlow:启动缓慢

3

我使用 PyCharm,是 Python 的新手。

在花了两天时间弄清楚 TensorFlow 的工作原理之后我取得了成功,但启动时间很慢。在这句话之前一切都很好:“Adding visible gpu device : 0”,它需要大约 7/8 分钟的时间。

我搜索并尝试了像“export CUDA_CACHE_MAXSIZE”和“CUDA_FORCE_PTX_JIT=1”这样的方法,但都不起作用。我是 Python 特别是 TensorFlow 的初学者,因此如果有比较明确的解决方案当然会很感激。

所以,如果有人有解决方案,请让我知道,我将非常感激。

祝您拥有愉快的一天,对我的英语表示抱歉。

系统信息:
Windows 10 x64,Gtx 1060,i5,16Go RAM
Python 3.8.7
Cuda v10.1
Tensorflow 2.2.0
cuDNN 7.6

编辑:
我正在从“freecodchamp”的 YouTube 视频中学习,所以我稍微遵循了一下开头的代码。

以下是我的源代码:

import tensorflow as tf
import numpy
import tensorflow_datasets
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

tensor1 = tf.ones([2, 3])  # shape 2x3 
print('shape tensor 1 = ', tf.shape(tensor1))  # Doing some test for learning
tensor2 = tf.reshape(tensor1, [1, 2, 3])
print('shape tensor 2 = ', tf.shape(tensor2))
tensor1 = tf.reshape(tensor1, [1, 1, 1, 1, 1, 6])
print('shape tensor 1 reshaped = ', tf.shape(tensor1))

输出:

2021-01-04 10:04:31.355144: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-01-04 10:04:43.401510: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2021-01-04 10:04:43.498316: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1060 computeCapability: 6.1
coreClock: 1.6705GHz coreCount: 10 deviceMemorySize: 3.00GiB deviceMemoryBandwidth: 178.99GiB/s
2021-01-04 10:04:43.499195: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-01-04 10:04:43.548183: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-01-04 10:04:43.583967: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-01-04 10:04:43.595863: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-01-04 10:04:43.637187: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-01-04 10:04:43.668089: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-01-04 10:04:43.773909: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-01-04 10:04:43.774488: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-01-04 10:04:43.779002: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-01-04 10:04:43.820840: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x16676079d90 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-01-04 10:04:43.821794: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-01-04 10:04:43.824342: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1060 computeCapability: 6.1
coreClock: 1.6705GHz coreCount: 10 deviceMemorySize: 3.00GiB deviceMemoryBandwidth: 178.99GiB/s
2021-01-04 10:04:43.825340: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-01-04 10:04:43.825837: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-01-04 10:04:43.826331: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-01-04 10:04:43.826816: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-01-04 10:04:43.827303: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-01-04 10:04:43.827801: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-01-04 10:04:43.828297: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-01-04 10:04:43.828914: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-01-04 10:16:39.045025: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-01-04 10:16:39.045537: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2021-01-04 10:16:39.045836: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2021-01-04 10:16:39.047684: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2095 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
2021-01-04 10:16:39.056201: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1661e481430 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-01-04 10:16:39.056798: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1060, Compute Capability 6.1
shape tensor 1 =  tf.Tensor([2 3], shape=(2,), dtype=int32)
shape tensor 2 =  tf.Tensor([1 2 3], shape=(3,), dtype=int32)
shape tensor 1 reshaped =  tf.Tensor([1 1 1 1 1 6], shape=(6,), dtype=int32)

Process finished with exit code 0

从“Adding visible gpu devices:0”这一行到下一行之间,可以看出它花费了12分钟时间。 一切都正常运行,只是我想让它运行得更快,因为每次运行程序等那么长时间我无法忍受。


Fabien,首先欢迎来到TensorFlow,其次,你的英语非常好!我们都说不同的语言,只要我们能相互理解,那就是最重要的。提供详细的问题信息非常重要,包括源代码、输出等等,否则几乎不可能得到StackOverflow社区中任何人的帮助。请更新你的帖子。 - CrazyBrazilian
1个回答

1

我在Win10和tensorflow==2.3上遇到了相同的错误。通过切换到tensorflow==2.4可以解决该问题。

或者,您可能可以考虑切换到Linux。我感觉它被tensorflow支持(并测试)得更好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接