为什么 TensorFlow 多次打印初始化消息?

问题描述

我注意到当我执行脚本时,TensorFlow 会多次打印初始化消息。

例如,它“成功打开动态库 libcublas.so.11”3 次。为什么?

这是一个示例输出

(tf24) [thiago@gpu4 tests]$ python benchmark_resnet50.py
2021-02-03 23:40:01.127238: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-02-03 23:40:03.624472: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2021-02-03 23:40:04.231490: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:02:00.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2021-02-03 23:40:04.231676: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-02-03 23:40:04.238008: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-02-03 23:40:04.238133: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-02-03 23:40:04.241047: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-02-03 23:40:04.241760: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-02-03 23:40:04.247997: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-02-03 23:40:04.249514: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-02-03 23:40:04.250023: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-02-03 23:40:04.253693: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-02-03 23:40:04.254240: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (onednN) to use the following cpu instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations,rebuild TensorFlow with the appropriate compiler flags.
2021-02-03 23:40:04.298021: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] cpu Frequency: 2200095000 Hz
2021-02-03 23:40:04.324765: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fa06bda4ad0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-02-03 23:40:04.324867: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host,Default Version
2021-02-03 23:40:04.468197: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fa06be1c840 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-02-03 23:40:04.468254: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla P100-PCIE-16GB,Compute Capability 6.0
2021-02-03 23:40:04.471448: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:02:00.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2021-02-03 23:40:04.471546: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-02-03 23:40:04.471594: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-02-03 23:40:04.471619: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-02-03 23:40:04.471643: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-02-03 23:40:04.471666: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-02-03 23:40:04.471690: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-02-03 23:40:04.471712: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-02-03 23:40:04.471736: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-02-03 23:40:04.474391: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-02-03 23:40:04.474455: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-02-03 23:40:05.005707: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-02-03 23:40:05.005753: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267]      0
2021-02-03 23:40:05.005763: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0:   N
2021-02-03 23:40:05.008042: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14957 MB memory) -> physical GPU (device: 0,name: Tesla P100-PCIE-16GB,pci bus id: 0000:02:00.0,compute capability: 6.0)
Found 9469 images belonging to 10 classes.
Found 3925 images belonging to 10 classes.
2021-02-03 23:40:08.066661: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
Epoch 1/5
2021-02-03 23:40:13.328180: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-02-03 23:40:13.637467: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-02-03 23:40:13.658296: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-02-03 23:40:14.980839: W tensorflow/stream_executor/gpu/asm_compiler.cc:63] Running ptxas --version returned 256
2021-02-03 23:40:15.105237: W tensorflow/stream_executor/gpu/redzone_allocator.cc:314] Internal: ptxas exited with non-zero error code 256,output:
Relying on driver to perform ptx compilation.
Modify $PATH to customize ptxas location.
This message will be only logged once.

以下是 benchmark_resnet50.py 的代码

如您所见,没有多处理/多线程/奇怪的事情发生。

import pathlib

import tensorflow.keras as keras
import tensorflow.keras.layers as layers
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator


def main():
    train_dataset_path = pathlib.Path().home() / 'synced' / 'shared' / 'datasets' / 'imagenette2-320' / 'train'
    validation_dataset_path = pathlib.Path().home() / 'synced' / 'shared' / 'datasets' / 'imagenette2-320' / 'val'

    input_shape = (256,256,3)
    epochs = 5
    batch_size = 64
    classes = 10

    resnet50 = keras.applications.resnet50(include_top=False,weights='imagenet',input_shape=input_shape)
    flattened = layers.Flatten()(resnet50.output)
    dense = layers.Dense(units=128,activation='relu')(flattened)
    softmax = layers.Dense(units=classes,activation='softmax')(dense)

    model = keras.models.Model(inputs=resnet50.input,outputs=softmax)
    model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])

    train_img_gen = ImageDataGenerator()
    train_data = train_img_gen.flow_from_directory(directory=train_dataset_path,class_mode='categorical',shuffle=True,batch_size=batch_size,target_size=input_shape[:2])

    validation_img_gen = ImageDataGenerator()
    validation_data = validation_img_gen.flow_from_directory(directory=validation_dataset_path,target_size=input_shape[:2])

    history = model.fit(x=train_data,epochs=epochs,steps_per_epoch=train_data.samples / batch_size,verbose=1,validation_data=validation_data,validation_steps=validation_data.samples / batch_size)


if __name__ == '__main__':
    main()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)