I'm trying to figure out the reasoning behind the slow performance I get while training when using a GPU runtime.
Data: Ragged tensors of 11 feature. shape:(49724, None, 11)
.(Download dataset from Dropbox)
Targets: Each sample results with 3 targets ranged between 0-1. shape:(49724, 3)
.(Download targets from Dropbox)
The model is an LSTM network with an input layer using ragged=True
attribute. Code:
config = {
'learning_rate': 0.001,
'lstm_neurons':32,
'lstm_activation':'tanh',
'dropout_rate': 0.08,
'batch_size': 128,
'dense_layers':[
{'neurons': 32, 'activation': 'relu'},
{'neurons': 32, 'activation': 'relu'},
]
}
def get_model(num_features, output_size):
opt = Adam(learning_rate=0.001)
model = Sequential()
model.add(Input(shape=[None,num_features], dtype=tf.float32, ragged=True))
model.add(LSTM(config['lstm_neurons'], activation=config['lstm_activation']))
model.add(BatchNormalization())
if 'dropout_rate' in config:
model.add(Dropout(config['dropout_rate']))
for layer in config['dense_layers']:
model.add(Dense(layer['neurons'], activation=layer['activation']))
model.add(BatchNormalization())
if 'dropout_rate' in layer:
model.add(Dropout(layer['dropout_rate']))
model.add(Dense(output_size, activation='sigmoid'))
model.compile(loss='mse', optimizer=opt, metrics=['mse'])
print(model.summary())
return model
model = get_model(11 ,3)
I've created 2 Google Colab notebooks to demonstrate the issue. One is a GPU runtime while the other is a CPU runtime.
On the GPU runtime, 1 epoch takes 869s
, while on the CPU runtime it takes 252s
!
My question is why and can I do something about it?