|

warp-ctcA fast parallel implementation of CTC, on both CPU and GPU.
IntroductionConnectionist Temporal Classificationis a loss function useful for performing supervised learning on sequence data,without needing an alignment between input data and labels. For example, CTCcan be used to trainend-to-endsystems forspeech recognition,which is how we have been using it at Baidu's Silicon Valley AI Lab.

The illustration above shows CTC computing the probability of an outputsequence "THE CAT ", as a sum over all possible alignments of input sequencesthat could map to "THE CAT ", taking into account that labels may be duplicatedbecause they may stretch over several time steps of the input data (represented bythe spectrogram at the bottom of the image).Computing the sum of all such probabilities explicitly would be prohibitively costly due to thecombinatorics involved, but CTC uses dynamic programming to dramaticallyreduce the complexity of the computation. Because CTC is a differentiable function,it can be used during standard SGD training of deep neural networks.
In our lab, we focus on scaling up recurrent neural networks, and CTC loss is animportant component. To make our system efficient, we parallelized the CTCalgorithm, as described in this paper.This project contains our high performance CPU and CUDA versions of the CTC loss,along with bindings for Torch.The library provides a simple C interface, so that it is easy tointegrate into deep learning frameworks.
This implementation has improved training scalability beyond theperformance improvement from a faster parallel CTC implementation. ForGPU-focused training pipelines, the ability to keep all data local toGPU memory allows us to spend interconnect bandwidth on increased dataparallelism.
PerformanceOur CTC implementation is efficient compared with many of the other publicly available implementations. It isalso written to be as numerically stable as possible. The algorithm is numerically sensitive and we have observedcatastrophic underflow even in double precision with the standard calculation - the result of division of two numbers on the order of 1e-324 which should have been approximately one, instead become infinity when the denominator underflowed to 0. Instead, by performing the calculation in log space, it is numericallystable even in single precision floating point at the cost of significantly more expensive operations. Instead ofone machine instruction, addition requires the evaluation of multiple transcendental functions. Because of this,the speed of CTC implementations can only be fairly compared if they are both performing the calculation the sameway.
We compare our performance with Eesen, a CTC implementation built on Theano,and a Cython CPU only implementation Stanford-CTC.We benchmark the Theano implementation operating on 32-bit floating-point numbers and doing the calculation in log-space,in order to match the other implementations we compare against. Stanford-CTC was modified to perform the calculationin log-space as it did not support it natively. It also does not support minibatches larger than 1, so would requirean awkward memory layout to use in a real training pipeline, we assume linear increase in cost with minibatch size.
We show results on two problem sizes relevant to our English and Mandarin end-to-end models, respectively, where T represents the number of timesteps in the input to CTC, L represents the length of the labels for each example, and A represents the alphabet size.
On the GPU, our performance at a minibatch of 64 examples ranges from 7x faster to 155x faster than Eesen, and 46x to 68x faster than the Theano implementation.
GPU PerformanceBenchmarked on a single NVIDIA Titan X GPU.
[td]T=150, L=40, A=28 | warp-ctc | Eesen | Theano | N=1 | 3.1 ms | .5 ms | 67 ms | N=16 | 3.2 ms | 6 ms | 94 ms | N=32 | 3.2 ms | 12 ms | 119 ms | N=64 | 3.3 ms | 24 ms | 153 ms | N=128 | 3.5 ms | 49 ms | 231 ms | [td]T=150, L=20, A=5000 | warp-ctc | Eesen | Theano | N=1 | 7 ms | 40 ms | 120 ms | N=16 | 9 ms | 619 ms | 385 ms | N=32 | 11 ms | 1238 ms | 665 ms | N=64 | 16 ms | 2475 ms | 1100 ms | N=128 | 23 ms | 4950 ms | 2100 ms | CPU PerformanceBenchmarked on a dual-socket machine with two Intel E5-2660 v3processors - warp-ctc used 40 threads to maximally take advantage of the CPU resources.Eesen doesn't provide a CPU implementation. We noticed that the Theano implementation was notparallelizing computation across multiple threads. Stanford-CTC provides no mechanismfor parallelization across threads.
[td]T=150, L=40, A=28 | warp-ctc | Stanford-CTC | Theano | N=1 | 2.6 ms | 13 ms | 15 ms | N=16 | 3.4 ms | 208 ms | 180 ms | N=32 | 3.9 ms | 416 ms | 375 ms | N=64 | 6.6 ms | 832 ms | 700 ms | N=128 | 12.2 ms | 1684 ms | 1340 ms | [td]T=150, L=20, A=5000 | warp-ctc | Stanford-CTC | Theano | N=1 | 21 ms | 31 ms | 850 ms | N=16 | 37 ms | 496 ms | 10800 ms | N=32 | 54 ms | 992 ms | 22000 ms | N=64 | 101 ms | 1984 ms | 42000 ms | N=128 | 184 ms | 3968 ms | 86000 ms | InterfaceThe interface is ininclude/ctc.h.It supports CPU or GPU execution, and you can specify OpenMP parallelismif running on the CPU, or the CUDA stream if running on the GPU. Wetook care to ensure that the library does not perform memoryallocation internally, in order to avoid synchronizations andoverheads caused by memory allocation.
Compilationwarp-ctc has been tested on Ubuntu 14.04 and OSX 10.10. Windows is not supportedat this time.
First get the code:
git clonecd warp-ctccreate a build directory:
mkdir buildcd buildif you have a non standard CUDA install export CUDA_BIN_PATH=/path_to_cuda so that CMake detects CUDA andto ensure Torch is detected, make sure th is in $PATH
run cmake and build:
cmake ../makeThe C library and torch shared libraries should now be built along with testexecutables. If CUDA was detected, then test_gpu will be built; test_cpuwill always be built.
TestsTo run the tests, make sure the CUDA libraries are in LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for OSX).
The Torch tests must be run from the torch_binding/tests/ directory.
Torch Installationluarocks make torch_binding/rocks/warp-ctc-scm-1.rockspec
You can also install without cloning the repository using
luarocks install http://raw.githubusercontent.com ... -ctc-scm-1.rockspec
There is a Torch CTC tutorial.
ContributingWe welcome improvements from the community, please feel free to submit pullrequests.
Known Issues / LimitationsThe CUDA implementation requires a device of at least compute capability 3.0.
The CUDA implementation supports a maximum label length of 639 (timesteps areunlimited).
|
|