在 GPU 上训练 RNN - 我应该使用哪个 tf.keras 层?

Training RNN on GPU - which tf.keras layer should I use?

我正在训练使用 tf.keras.layers.GRU 层构建的 RNN。他们需要很长时间来训练(> 2 小时),所以我打算将它们部署到 GPU 上进行训练。我想知道关于 GPU 训练的一些事情:

  1. tf.keras.layers.CuDNNGRUtf.keras.layers.GRU(以及 tf.keras.layers.LSTMtf.keras.layers.CuDNNLSTM)有什么区别?我从 this post 了解到 CuDNNGRU 层比 GRU 层训练得更快,但是
    • 使用相同的种子,2 层会收敛到不同的结果吗?
    • 这两个层在推理过程中表现相同吗?
    • CuDNN 层在推理过程中是否需要 GPU?
    • GRU 层 运行 可以在 GPU 上进行推理吗?
    • CuDNN 层是否易于部署?我目前正在使用 coremlconverter 将我的 keras 模型转换为 CoreML 以进行部署。
  2. tf.keras.layers.SimpleRNN(即tf.keras.layers.CuDNNSimpleRNN)是否有等效的 CuDNN 层?我还没有致力于特定的架构,所以我相信如果我决定使用 SimpleRNN,我将需要 tf.keras.layers.CuDNNSimpleRNN 层,并且 CuDNN 层具有我需要的一些功能。
  3. 有了 CuDNN 层,我需要安装 tensorflow-gpu 吗?或者只要我安装了相关的驱动程序,它们仍然会部署到 GPU 上吗?

如果您使用的是与 cuda 兼容的 gpu,那么使用 CuDNN 层绝对有意义。他们有一个不同的实现,试图克服 RNN 架构中固有的计算并行化问题。虽然它们通常表现得有点差,但速度要快 3 到 6 倍 https://twitter.com/fchollet/status/918170264608817152?lang=en

Do the 2 layers converge to different results with the same seed?

Do the 2 layers perform the same during inference?

你应该有可比较的性能但不完全相同

Do CuDNN layers require a GPU during inference?

是的,但您可以转换为与 CuDNN 兼容的 GRU/LSTM

Can GRU layers run inference on a GPU?

With CuDNN layers, do I need to have tensorflow-gpu installed? Or do they still get deployed to the GPU as long as I have the relevant drivers installed?

是的,你需要一个 cuda 兼容的 gpu