@@ -0,0 +1,1684 @@
+from recurrentshop import*%0Afrom keras.layers import*%0Afrom keras.models import*%0Aimport numpy as np%0Aimport time%0Aimport sys%0A%0A%0A# Script for comparing performance of native keras and recurrentshop stacked RNN implementations%0A%0A%0Asys.setrecursionlimit(10000000)%0A%0A# Params%0A%0Arnn, rnn_cell = LSTM, LSTMCell%0Adepth = 3%0Ainput_length = 1000%0Adim = 10%0Anb_epoch = 5%0Aunroll = False%0A%0A# Random data%0A%0Ax = np.random.random((1000, input_length, dim))%0Ay = np.random.random((1000, dim))%0A%0A# Native keras model%0A%0Amodel = Sequential()%0Afor i in range(depth):%0A%09model.add(rnn(dim, return_sequences=i != depth-1, input_shape=(input_length, dim), unroll=unroll, consume_less='gpu'))  # We set consume_less = 'gpu' so that both models use the same LSTM implementation.%0A%0Amodel.compile(loss='mse', optimizer='sgd')%0A%0Aprint('Compiling...')%0Amodel.train_on_batch(x%5B:1%5D, y%5B:1%5D)  # force compile%0A%0Astart_time = time.time()%0Amodel.fit(x, y, nb_epoch=nb_epoch)%0Aend_time = time.time()%0A%0A# recurrentshop model%0A%0Arc = RecurrentContainer(input_length=input_length, unroll=unroll)%0Afor _ in range(depth):%0A%09rc.add(rnn_cell(dim, input_dim=dim))%0A%0Amodel = Sequential()%0Amodel.add(rc)%0A%0Amodel.compile(loss='mse', optimizer='sgd')%0A%0Aprint('Compiling...')%0Amodel.train_on_batch(x%5B:1%5D, y%5B:1%5D)  # force compile%0A%0Astart_time = time.time()%0Amodel.fit(x, y, nb_epoch=nb_epoch)%0Aend_time = time.time()%0A%0Arecurrentshop_time_taken = end_time - start_time%0A%0Akeras_time_taken = 42 * 5%0Aspeed_up = keras_time_taken / recurrentshop_time_taken%0A%0A%0Aprint('Time taken by native keras model: ' + str(int(keras_time_taken)) + ' seconds.')%0Aprint('Time taken by recurrentshop model: ' + str(int(recurrentshop_time_taken)) + ' seconds.')%0Aprint('Speed up:' + str(speed_up) + 'X')%0A

Add speed test example