2

I am running an LSTM model on AWS instance g3.8xlarge which has 2 GPUs, and using tf.distribute.MirroredStrategy() so that I can use the 2 GPUs. However, the training time is actually slower than without using this. Does anyone know how to solve this?

I am using:

  • Ubuntu 16.04
  • NVIDIA-SMI 440.33.01
  • CUDA Version 10.1.105
  • Cudnn 7.6.5
  • tensorflow-gpu 2.1.0

My code is:

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


matthias_h
  • 11,356
  • 9
  • 22
  • 40
sunday
  • 31
  • 1
  • Simple answer: switch to Horovod. I've used Mirrored Strategy as well and found out i've never had a performance speed-up. Also, by doing some research, i've never found a solution to this. – vinx.py Aug 06 '20 at 09:26

0 Answers0