【发布时间】:2021-02-25 10:50:22
【问题描述】:
我正在使用 NVIDIA RTX-2060(带有图灵核心)进行深度学习模型训练。正如在线论坛上提到的,启用混合精度训练有助于图灵架构卡的训练速度比没有混合精度训练的速度更快。当我启用混合精度训练时,每步时间增加而不是减少。我无法理解为什么会发生这种情况,我非常感谢任何提出解决方案的人。我花了这么多钱买了这个gpu,如果我不能用它来更快地训练模型,那就没有用了。
代码:
import tensorflow as tf
def create_model():
model = keras.Sequential([
keras.layers.Flatten(input_shape=(32,32,3)),
keras.layers.Dense(3000, activation='relu'),
keras.layers.Dense(1000, activation='relu'),
keras.layers.Dense(10, activation='sigmoid')
])
model.compile(optimizer= 'SDG',
loss= 'categorical_crossentropy',
metrics=['accuracy'])
return model
tf.keras.mixed_precision.set_global_policy('mixed_float16')
%%timeit -n1 -r1 # time required toexecute this cell once
model = create_model()
model.fit(X_train_scaled, y_train_categorical, epochs=50)
你必须知道的事情:
我已经成功安装了 cuda 和 cudnn 并且 tensorflow 可以检测到我的 gpu。
我已经安装了 tensorflow-gpu。
我正在使用 nvidia rtx 2060 gpu 在 ciphar10 数据集上训练我的模型。
我一直在使用 Jupyter Notebook 进行基准测试:Link
【问题讨论】:
-
你的基准测试怎么样?
-
对每个epoch使用张量流输出时间
-
您是否尝试过使用预训练模型进行基准测试?
标签: python tensorflow keras