gpt4 book ai didi

tensorflow - 多 GPU 架构、梯度平均 - 模型不太准确?

转载 作者:行者123 更新时间:2023-12-02 18:48:11 25 4
gpt4 key购买 nike

当我按照 https://www.tensorflow.org/tutorials/deep_cnn 中所述执行 cifar10 模型时使用单个 GPU 大约 4 小时后,我达到了 86% 的准确度,当我使用 2 个 GPU 时,准确度下降到 84%,但在 2 个 GPU 上达到 84% 的准确度比 1 个 GPU 更快。

我的直觉是Average_gradients 函数定义于 https://github.com/tensorflow/models/blob/master/tutorials/image/cifar10/cifar10_multi_gpu_train.py返回不太准确的梯度值,因为梯度的平均值将不如实际梯度值准确。

如果梯度不太准确,那么作为训练一部分学习的控制函数的参数就不那么准确。查看代码 ( https://github.com/tensorflow/models/blob/master/tutorials/image/cifar10/cifar10_multi_gpu_train.py ) 为什么在多个 GPU 上平均梯度不如在单个 GPU 上计算梯度准确?

我对梯度进行平均产生不太准确的值的直觉正确吗?

模型中的随机性描述为:

The images are processed as follows:
They are cropped to 24 x 24 pixels, centrally for evaluation or randomly for training.
They are approximately whitened to make the model insensitive to dynamic range.
For training, we additionally apply a series of random distortions to artificially increase the data set size:

Randomly flip the image from left to right.
Randomly distort the image brightness.
Randomly distort the image contrast.

源代码:https://www.tensorflow.org/tutorials/deep_cnn

这对训练准确性有影响吗?

更新:

尝试进一步研究不同数量 GPU 的损失函数值训练。

Training with 1 GPU : loss value : .7 , Accuracy : 86%
Training with 2 GPU's : loss value : .5 , Accuracy : 84%

损失值不应该越低,精度越高,而不是反之亦然?

最佳答案

在您链接的代码中,使用 2 个 GPU 的函数 average_gradient 与简单地使用 1 个 GPU 和两倍的批量大小完全等效(1)/strong>.

你可以在定义中看到它:

grad = tf.concat(axis=0, values=grads)
grad = tf.reduce_mean(grad, 0)

使用较大的批量大小(给定相同的时期数)可能会对您的结果产生任何影响。

因此,如果您想在 1-GPU 或 2-GPU 情况下执行完全相同的 (1) 计算,您可能需要在后一种情况下将批量大小减半。 (人们有时会避免这样做,因为在某些情况下,较小的批量大小也可能使每个 GPU 上的计算速度变慢)

此外,这里需要小心学习率衰减。如果您使用它,您需要确保在 1-GPU 和 2-GPU 情况下第 n 轮的学习率是相同的 - 我不完全确定这段代码正在做正确的事情在这里。我倾向于在日志中打印学习率,例如

print sess.run(lr)

应该在这里工作。

(1) 忽略与伪随机数、有限精度或不能被批量大小整除的数据集大小相关的问题。

关于tensorflow - 多 GPU 架构、梯度平均 - 模型不太准确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43845644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com