python - tensorflow : slow startup

标签 python performance tensorflow

我使用 PyCharm,我是 python 的新手。

经过 2 天弄清楚 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 内存
Python 3.8.7
Cuda v10.1
tensorflow 2.2.0
cuDNN 7.6

编辑: 我正在向 YouTube 上的“freecodchamp”学习,所以我遵循了一些开始的代码

这是我的源代码:

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 分钟 一切都运行正常,我只是想运行得更快,因为我不想每次运行这个程序都需要那么长时间。

最佳答案

用win10和tensorflow==2.3有同样的错误。可以通过切换到 tensorflow==2.4 来修复

或者,您也可以切换到 Linux。我感觉 tensorflow 对它的支持(和测试)要好得多。

关于python - tensorflow : slow startup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65554962/

相关文章:

Java 性能与代码风格 : Making multiple method calls from the same line of code

python - tensorflow 线性回归的pytorch等价物是什么?

python - 如何在 Django 中使用用户 FK 为模型指定默认值

python - 无法通过 ID 从 Google 云端硬盘下载文件

在加载 200mb 的新图像()后,Javascript 在 Safari/iPad2 中运行缓慢。为什么会这样?

performance - 在非常大的数组中找到 N 个唯一随机数的最佳算法

python - 如何从继承链中上几层的基类调用方法?

python - Python中等效的构建器模式

python - 为什么 TensorFlow Estimator API 将输入作为 lambda?

tensorflow - keras.utils.to_categorical 和 pd.get_dummies 之间有什么区别吗?