Professional Documents
Culture Documents
LSTM Benchmark
LSTM Benchmark
Stefan Braun
[email protected]
Abstract
arXiv:1806.01818v1 [cs.LG] 5 Jun 2018
1 Introduction
In recent years, deep learning frameworks such as PyTorch [1], TensorFlow [2], Theano-based
Lasagne [3, 4], Keras [5], Chainer [6] and others [7] have been introduced and developed at a rapid
pace. These frameworks provide neural network units, cost functions and optimizers to assemble
and train neural network models. In typical research applications, network units may be combined,
modified or new network units may be introduced. In all cases the training time is a crucial factor
during the experimental evaluation: faster training allows for more experiments, larger datasets or
reduced time-to-results. Therefore, it is advantageous to identify deep learning frameworks that allow
for fast experimentation.
This study focuses on the benchmarking of the widely-used LSTM cell [8] that is available in
the mentioned frameworks. The LSTM architecture allows for various optimization steps such as
increased parallelism, fusion of point-wise operations and others [9]. While an optimized LSTM
implementation trains faster, it is typically more difficult to implement (e.g. writing of custom CUDA
kernels) or modify (e.g. exploring new cell variants, adding normalization etc.). Resultingly, some
frameworks provide multiple LSTM implementations that differ in training speed and flexibility
towards modification. For example, TensorFlow offers 5 LSTM variants: (1) BasicLSTMCell, (2)
LSTMCell, (3) LSTMBlockCell, (4) LSTMBlockFusedCell and (5) cuDNNLSTM.
To summarize, neural network researchers are confronted with a two-fold choice of framework and
implementation, and identifying the fastest option helps to streamline the experimental research
phase. This study aims to assist the identification process with the following goals:
• Provide benchmarks for different LSTM implementations across deep learning frameworks
• Use common input sizes, network configurations and cost functions as in typical automatic
speech recognition (ASR) scenarios
• Share the benchmark scripts for transparency and to help people coding up neural networks
in different frameworks
Table 1: Deep learning frameworks considered for evaluation. Top half: framework comparison,
bottom half: PyTorch comparison
2 Related work
The deep learning community put considerable effort into benchmarking and comparing neural-
network related hardware, libraries and frameworks. A non-exhaustive list is presented followingly:
• DeepBench [10]. This project aims to benchmark basic neural network operations such
as matrix multiplies and convolutions for different hardware platforms and neural network
libraries such as cuDNN or MKL. In comparison, our study focuses solely on the LSTM
unit and compares on the higher abstraction level of deep learning frameworks.
• DAWNBench [11]. This is a benchmark suite for complete end-to-end models that measures
computation time and cost to train deep models to reach a certain accuracy. In contrast, our
study is limited to measuring the training time per batch.
• Comparative studies. Other comparative studies such as [12] have only small sections on
LSTMs and are already quite old for deep learning time scales (2016, PyTorch was not even
released back then).
• CNN-benchmarks. For standard convolutional neural networks (CNNs) such as
AlexNet [13], VGG [14] or ResNet [15], there exist several benchmark repositories [16, 17].
• TensorFlow LSTMs. Benchmarks for the TensorFlow LSTM variants are presented in [18],
but deep learning frameworks other than TensorFlow are not considered.
• Chainer LSTMs. Benchmarks for the Chainer LSTM variants are presented in [19], but
deep learning frameworks other than Chainer are not evaluated.
3 Setup
The experiments cover (1) a comparison between the PyTorch, TensorFlow, Lasagne and Keras
frameworks and (2) a comparison between four versions of PyTorch. The experimental details are
explained in the following sections.
The benchmarks cover 10 LSTM implementations, including the cuDNN [9] and various optimized
and basic variants. The complete list of the covered LSTM implementations is given in Table 2. The
2
main differences between the implementations occur in the computation of a single time step and
the realization of the loop over time, and possible optimization steps are described in [9]. While the
cuDNN and optimized variants are generally faster, the basic variants are of high interest as they are
easy to modify, therefore simplifying the exploration of new recurrent network cells for researchers.
Input data The input data covers a short sequence length (100 time steps) and a long sequence
length scenario (up to 1000 time steps). The data is randomly sampled from a normal distribution
N (µ = 0, σ = 1).
• Short & fixed length. The short input size is 64x100x123 (batch size x time steps x features)
and the sequence length is fixed to 100 time steps. The target labels consist of 10 classes
and 1 label is provided per sample. This setup is similar to an isolated digit recognition task
on the TIDIGITS [21] data-set. 1
• Long & fixed length. The long input size is 32x1000x123 and covers 1000 time steps. The
target labels consist of 10 classes and 1 label is provided per sample.
• Long & variable length. The sequence length is varied between 500 to 1000 time steps,
resulting in an average length of 750 time steps. All 32 samples are zero-padded to the
maximum length of 1000 time steps, resulting in a 32x1000x123 input size. The target
labels consist of 59 output classes, and each sample is provided with a label sequence of 100
labels. The variable length setup is similar to a typical continuous speech recognition task on
the Wall Street Journal (WSJ) [22] data-set.2 . The variable length information is presented
in the library specific format, i.e. as PackedSequence in PyTorch, as sequence_length
parameter of dynamic_rnn in TensorFlow and as a mask in Lasagne.
Loss functions The fixed length data is classified with the cross-entropy loss function, which
is integrated in all libraries. The variable length data is classified with the CTC [24] loss. For
TensorFlow, the integrated tf.nn.ctc_loss is used. PyTorch and Lasagne do not include CTC loss
functions, and so the respective bindings to Baidu’s warp-ctc [25] are used [26, 27].
Model All networks consist of LSTMs followed by an output projection. The LSTM part uses
either a single layer of 320 unidirectional LSTM units, or four layers of bidirectional LSTMs with
320 units per direction. When using the cross entropy loss, the output layer consists of 10 dense units
that operate on the final time step output of the last LSTM layer. In contrast, the output layer of the
CTC loss variant uses 59 dense units that operate on the complete sequence output of the last LSTM
layer.
Optimizer All benchmarks use the framework-specific default implementation of the widely used
ADAM optimizer [28].
3.4 Measurements
The reported timings reflect the mean and standard deviation of the time needed to fully process one
batch, including the forward and backward pass. The benchmarks were carried out on a machine with
a Xeon W-2195 CPU (Skylake architecture3 ), a NVIDIA GTX 1080 Founders Edition graphics card
(fan speed @ 100% to avoid thermal throttling) and Ubuntu 16.04 operating system (CPU frequency
1
ASR-task on TIDIGITS/isolated digit recognition, default training set (0.7 hours of speech): 123-
dimensional filterbank features with 100fps, average sequence length of 98, alphabet size of 10 digits and
1 label per sample
2
ASR-task on WSJ/continuous speech recognition, pre-processing with EESEN [23] on training subset
si-284 (81h of speech): 123-dimensional filterbank features with 100fps, average sequence length 783, alphabet
size of 59 characters and average number of characters per sample 102
3
This CPU scales its clock frequency between 2.3GHz to 4.3Ghz. In order to reduce the fluctuation of the
CPU frequency, the number of available CPU cores was restricted to 4 such that all 4 cores maintained 4.0GHz
to 4.3GHz clock frequency
3
Table 2: LSTM implementations considered for evaluation. Click on the name for a hyperlink to the documentation.
ort ng ng ong
E -sh E-lo E-lo TC-l
C C C C
20/ x320/ x320/ x320/
Framework Name 1x3 1 4 4 Detail
Name Layers x LSTM units Output Loss Input [NxTxC] Sequence length Labels per sample
1x320/CE-short 1x320 unidirectional 10 Dense cross entropy 64x100x123 fixed ∈ {100} 1
1x320/CE-long 1x320 unidirectional 10 Dense cross entropy 32x1000x123 fixed ∈ {1000} 1
4x320/CE-long 4x320 bidirectional 10 Dense cross entropy 32x1000x123 fixed ∈ {1000} 1
4x320/CTC-long 4x320 bidirectional 59 Dense CTC 32x1000x123 variable ∈ {500, ..., 1000} 100
governor in performance mode4 ). The measurements were conducted over 500 iterations and the
first 100 iterations were considered as warm-up and therefore discarded.
The limitations reflect the current state of the benchmark code, and may be fixed in future versions.
Further issues can be reported in the github repository.
• The benchmark scripts are carefully written, but not optimized to squeeze that last bit of
performance out of them. They should reflect typical day-to-day research applications.
• Due to time constraints, only the 1x320 LSTM benchmark covers all considered frameworks.
For the multi-layer 4x320 networks, only implementations that provided helper functions to
create stacked bidirectional networks were evaluated. An exemption of this rule was made
for Lasagne, in order to include a Theano-based contender for this scenario.
4
By default, Ubuntu 16.04 uses the mode powersave which significantly decreased performance during the
benchmarks
4
• The TensorFlow benchmarks use the feed_dict input method that is simple to implement,
but slower than the tf.data API [29]. Implementing a high performance input pipeline
in TensorFlow is not trivial, and only the feed_dict approach allowed for a similar
implementation complexity as in the PyTorch and Lasagne cases.
• The TensorFlow cuDNNLSTM was not tested with variable length data as it does not support
such input [30].
• The TensorFlow benchmark uses the integrated tf.nn.ctc_loss instead of the warp-
ctc library, even though there is a TensorFlow binding available [25]. The performance
difference has not been measured.
• PyTorch 0.4.0 merged the Tensor and Variable classes and does not need the Variable
wrapper anymore. The Variable wrapper has a negligible performance impact on version
0.4.0, but is required for older PyTorch releases in the PyTorch version comparison.
4 Results
The complete set of results is given in Table 4 and the most important findings are summarized below.
• Fastest LSTM implementation. The cuDNNLSTM is the overall fastest LSTM implementa-
tion, for any input size and network configuration. It is up to 7.2x faster than the slowest
implementation (Keras/TensorFlow LSTM , 1x320/CE-long). PyTorch, TensorFlow and
Keras provide wrappers to the cuDNN LSTM implementation and the speed difference
between frameworks is small (after all, they are wrapping the same implementation).
• Optimized LSTM implementations. When considering only optimized LSTM implemen-
tations other than cuDNNLSTM, then the TensorFlow LSTMBlockFusedCell is the fastest
variant: it is 1.3x faster than PyTorch LSTMCell-fused and 3.4x faster than TensorFlow
LSTMBlockCell (1x320/CE-long). The fused variants are slower than the cuDNNLSTM but
faster than the more flexible alternatives.
• Basic/Flexible LSTM implementations. When considering only flexible implementa-
tions that are easy to modify, then Lasagne LSTMLayer, Keras/Theano LSTM and Py-
Torch LSTMCell-basic are the fastest variants with negligible speed difference. All three
train 1.6x faster than TensorFlow LSTMCell, and 1.8x faster than Keras/TensorFlow LSTM
(1x320/CE-long). For Keras, the Theano backend is faster than the TensorFlow backend.
• 100 vs 1000 time steps. The results for the short and and long input sequences allow for
similar conclusions, with the main exception being that the spread of training time increases
and the fastest implementation is 7.2x (1x320/CE-long) vs. 5.1x (1x320/CE-short) faster
than the slowest.
• Quad-layer networks. The cuDNNLSTM wrappers provided by TensorFlow and PyTorch
are the fastest implementation and deliver the same training speed, and they are between
4.7x to 7.0x faster than the networks built with Lasagne LSTMLayer and TensorFlow
LSTMBlockCell / LSTMCell (4x320/CE-long and 4x320/CTC-long).
• Fixed vs. variable sequence length. Going from 4x320/CE-long to 4x320/CTC-long (fixed
vs. variable sequence length, cross entropy vs. CTC loss function) slows down training
by a factor of 1.1x (PyTorch cuDNNLSTM) to 1.2x (Lasagne LSTMLayer). The TensorFlow
implementations stabilize at roughly the same level.
• PyTorch versions. The two most recent versions 0.4.0 and 0.3.1post2 are significantly faster
than the older versions, especially for the flexible LSTMCell-basic where the speedup
is up to 2.2x (1x320/CE-long). The 4x320/CTC-long benchmark is very slow for version
0.2.0_4 which suffered from a slow implementation for sequences of variable length that is
fixed in newer versions [31]. The older PyTorch versions tend to produce larger standard
deviations in processing time, which is especially visible on the 1x320/CE-short test.
5 Conclusion
This study evaluated the training time of various LSTM implementations in the PyTorch, TensorFlow,
Lasagne and Keras deep learning frameworks. The following conlusions are drawn:
5
• The presented LSTM benchmarks show that an informed choice of deep learning framework
and LSTM implementation may increase training speed by up to 7.2x on standard input
sizes from ASR.
• The overall fastest LSTM implementation is the well-optimized cuDNN variant provided
from NVIDIA which is easily accessible in PyTorch, TensorFlow and Keras, and the training
speed is similar across frameworks.
• When comparing deep learning frameworks and less optimized, but more customizable
LSTM implementations, then PyTorch trains 1.5x to 1.6x faster than TensorFlow and
Lasagne trains between 1.3x to 1.6x faster than TensorFlow. Keras is between 1.5x to 1.7
faster than TensorFlow when using the Theano backend, but 1.1x slower than TensorFlow
when using the TensorFlow backend.
• The comparison of PyTorch versions showed that for PyTorch users it is a good idea to
update to the most recent version.
On a final note, the interested reader is invited to visit the github page and run his own benchmarks
with custom network and input sizes.
Acknowledgments
I thank my PhD supervisor Shih-Chii Liu for support and encouragement in the benchmarking
endeavours. I also thank the Sensors group from the Institute of Neuroinformatics, University of
Zurich / ETH Zurich for feedback and discussions. This work was partially supported by Samsung
Advanced Institute of Technology.
6
Table 4: Benchmarking results: mean and standard deviation of training time per batch in [ms]
7
References
[1] A. Paszke, S. Gross, S. Chintala, G. Chanan, E. Yang, Z. DeVito, Z. Lin, A. Desmaison, L. Antiga, and
A. Lerer, “Automatic differentiation in PyTorch,” in NIPS Workshop Autodiff, 2017.
[2] M. Abadi, A. Agarwal, P. Barham, E. Brevdo, Z. Chen, C. Citro, G. S. Corrado, A. Davis, J. Dean,
M. Devin, S. Ghemawat, I. Goodfellow, A. Harp, G. Irving, M. Isard, Y. Jia, R. Jozefowicz, L. Kaiser,
M. Kudlur, J. Levenberg, D. Mané, R. Monga, S. Moore, D. Murray, C. Olah, M. Schuster, J. Shlens,
B. Steiner, I. Sutskever, K. Talwar, P. Tucker, V. Vanhoucke, V. Vasudevan, F. Viégas, O. Vinyals, P. War-
den, M. Wattenberg, M. Wicke, Y. Yu, and X. Zheng, “TensorFlow: Large-scale machine learning on
heterogeneous systems,” 2015. Software available from tensorflow.org.
[3] R. Al-Rfou, G. Alain, A. Almahairi, C. Angermüller, D. Bahdanau, N. Ballas, F. Bastien, J. Bayer,
A. Belikov, A. Belopolsky, Y. Bengio, A. Bergeron, J. Bergstra, V. Bisson, J. B. Snyder, N. Bouchard,
N. Boulanger-Lewandowski, X. Bouthillier, A. de Brébisson, O. Breuleux, P. L. Carrier, K. Cho,
J. Chorowski, P. F. Christiano, T. Cooijmans, M. Côté, M. Côté, A. C. Courville, Y. N. Dauphin, O. Delal-
leau, J. Demouth, G. Desjardins, S. Dieleman, L. Dinh, M. Ducoffe, V. Dumoulin, S. E. Kahou, D. Erhan,
Z. Fan, O. Firat, M. Germain, X. Glorot, I. J. Goodfellow, M. Graham, Ç. Gülçehre, P. Hamel, I. Harlouchet,
J. Heng, B. Hidasi, S. Honari, A. Jain, S. Jean, K. Jia, M. Korobov, V. Kulkarni, A. Lamb, P. Lamblin,
E. Larsen, C. Laurent, S. Lee, S. Lefrançois, S. Lemieux, N. Léonard, Z. Lin, J. A. Livezey, C. Lorenz,
J. Lowin, Q. Ma, P. Manzagol, O. Mastropietro, R. McGibbon, R. Memisevic, B. van Merriënboer,
V. Michalski, M. Mirza, A. Orlandi, C. J. Pal, R. Pascanu, M. Pezeshki, C. Raffel, D. Renshaw, M. Rocklin,
A. Romero, M. Roth, P. Sadowski, J. Salvatier, F. Savard, J. Schlüter, J. Schulman, G. Schwartz, I. V.
Serban, D. Serdyuk, S. Shabanian, É. Simon, S. Spieckermann, S. R. Subramanyam, J. Sygnowski, J. Tan-
guay, G. van Tulder, J. P. Turian, S. Urban, P. Vincent, F. Visin, H. de Vries, D. Warde-Farley, D. J. Webb,
M. Willson, K. Xu, L. Xue, L. Yao, S. Zhang, and Y. Zhang, “Theano: A python framework for fast
computation of mathematical expressions,” arXiv preprint arXiv:1605.02688, 2016.
[4] S. Dieleman, J. Schlüter, C. Raffel, E. Olson, S. K. Sønderby, D. Nouri, D. Maturana, M. Thoma,
E. Battenberg, J. Kelly, J. D. Fauw, M. Heilman, D. M. de Almeida, B. McFee, H. Weideman, G. Takács,
P. de Rivaz, J. Crall, G. Sanders, K. Rasul, C. Liu, G. French, and J. Degrave, “Lasagne: First release.,”
Aug. 2015.
[5] F. Chollet et al., “Keras.” https://keras.io, 2015.
[6] S. Tokui, K. Oono, S. Hido, and J. Clayton, “Chainer: a next-generation open source framework for deep
learning,” in NIPS Workshop Machine Learning Systems, 2015.
[7] “Wikipedia: Comparison of deep learning software.” https://en.wikipedia.org/wiki/
Comparison_of_deep_learning_software. Accessed: 2018-05-04.
[8] S. Hochreiter and J. Schmidhuber, “Long short-term memory,” Neural computation, vol. 9, no. 8, pp. 1735–
1780, 1997.
[9] J. Appleyard, T. Kocisky, and P. Blunsom, “Optimizing performance of recurrent neural networks on
GPUs,” arXiv preprint arXiv:1604.01946, 2016.
[10] “DeepBench.” https://github.com/baidu-research/DeepBench. Accessed: 2018-05-04.
[11] C. Coleman, D. Narayanan, D. Kang, T. Zhao, J. Zhang, L. Nardi, P. Bailis, K. Olukotun, C. Ré, and
M. Zaharia, “DAWNBench: An End-to-End Deep Learning Benchmark and Competition,” Training,
vol. 100, no. 101, p. 102, 2017.
[12] S. Bahrampour, N. Ramakrishnan, L. Schott, and M. Shah, “Comparative study of caffe, neon, theano, and
torch for deep learning,” in ICLR Workshop Track, 2016.
[13] A. Krizhevsky, I. Sutskever, and G. E. Hinton, “ImageNet Classification with Deep Convolutional Neural
Networks,” in Advances in Neural Information Processing Systems 25, pp. 1097–1105, 2012.
[14] K. Simonyan and A. Zisserman, “Very deep convolutional networks for large-scale image recognition,”
CoRR, vol. abs/1409.1556, 2014.
[15] K. He, X. Zhang, S. Ren, and J. Sun, “Deep residual learning for image recognition,” in Proceedings of the
IEEE conference on computer vision and pattern recognition, pp. 770–778, 2016.
[16] “convnet-benchmarks.” https://github.com/soumith/convnet-benchmarks. Accessed: 2018-05-
04.
[17] “Deep-learning-benchmark.” https://github.com/u39kun/deep-learning-benchmark. Accessed:
2018-05-04.
[18] “TensorFlow LSTM benchmark.” http://returnn.readthedocs.io/en/latest/tf_lstm_
benchmark.html. Accessed: 2018-05-04.
[19] M. Sato, “Performance comparison of LSTM with and without cuDNN(v5) in Chainer.” https://
chainer.org/general/2017/03/15/Performance-of-LSTM-Using-CuDNN-v5.html. Accessed:
2018-05-04.
8
[20] “MILA and the future of Theano.” https://groups.google.com/forum/#!msg/theano-users/
7Poq8BZutbY/rNCIfvAEAwAJ. Accessed: 2018-05-04.
[21] R. G. Leonard and G. Doddington, “TIDIGITS speech corpus,” Texas Instruments, Inc, 1993.
[22] J. Garofalo, D. Graff, D. Paul, and D. Pallett, “CSR-I (WSJ0) complete, LDC93S6A,” Linguistic Data
Consortium, Philadelphia, 2007.
[23] Y. Miao, M. Gowayyed, and F. Metze, “EESEN: End-to-end speech recognition using deep RNN models
and WFST-based decoding,” in IEEE Workshop on Automatic Speech Recognition and Understanding
(ASRU), pp. 167–174, 2015.
[24] A. Graves, S. Fernández, F. Gomez, and J. Schmidhuber, “Connectionist temporal classification: Labelling
unsegmented sequence data with recurrent neural networks,” in Proceedings of the 23rd International
Conference on Machine learning (ICML), pp. 369–376, 2006.
[25] “Baidu warp-ctc.” https://github.com/baidu-research/warp-ctc. Accessed: 2018-05-04.
[26] S. Naren, “warp-ctc binding for PyTorch.” https://github.com/SeanNaren/warp-ctc. Accessed:
2018-05-04.
[27] “Theano CTC.” http://deeplearning.net/software/theano/library/tensor/nnet/ctc.
html. Accessed: 2018-05-04.
[28] D. P. Kingma and J. Ba, “Adam: A method for stochastic optimization,” arXiv preprint arXiv:1412.6980,
2014.
[29] “TensorFlow feed_dict.” https://www.tensorflow.org/performance/performance_guide#
input_pipeline_optimization. Accessed: 2018-05-04.
[30] “TensorFlow issue 6633.” https://github.com/tensorflow/tensorflow/issues/6633. Accessed:
2018-05-04.
[31] “PyTorch issue 1788.” https://github.com/pytorch/pytorch/issues/1788. Accessed: 2018-05-
04.