2

我在具有 2 个 GPU 的 AWS 实例 g3.8xlarge 上运行 LSTM 模型,并且使用tf.distribute.MirroredStrategy()它以便我可以使用 2 个 GPU。但是,训练时间实际上比不使用它要慢。有谁知道如何解决这个问题?

我在用:

  • Ubuntu 16.04
  • NVIDIA-SMI 440.33.01
  • CUDA 版本 10.1.105
  • 库顿 7.6.5
  • 张量流-GPU 2.1.0

我的代码是:

from tensorflow.keras.models import Sequential 
from tensorflow.keras.layers import LSTM 
from tensorflow.compat.v1.keras.layers import CuDNNLSTM 
from tensorflow.keras.layers import Dense 
from tensorflow.keras.layers import Dropout 
from tensorflow.keras.layers import RepeatVector 
from tensorflow.keras.layers import TimeDistributed 
from tensorflow.keras.optimizers import SGD 
import tensorflow.keras.backend as K 
import tensorflow as tf

def lstm_model(timesteps, features, neurons_1, dropout, learning, momentum, decay, init ) :
   distribute = tf.distribute.MirroredStrategy()
   with distribute.scope():
       model = Sequential()
       model.add(CuDNNLSTM(neurons_1, return_sequences=False, input_shape = (timesteps, features), kernel_initializer = init))
       model.add(Dropout(dropout))
       model.add(Dense(1))
       SGD( lr = learning, momentum = momentum, decay = decay, nesterov = False)
       model.compile(loss = lambda y, f: tilted_loss(0.5, y,f), optimizer = 'adam')
   return model


4

0 回答 0