Which calculation moved to the GPU?
A swipe trace contains many positions, while its label contains just a few letters. Connectionist temporal classification (CTC) trains on these pairs by summing over the possible alignments between frames and letters. Its blank state lets the model represent consecutive copies of the same letter. A new implementation can accelerate this calculation only if it preserves both the loss and its training gradients.
The study compared copying the loss calculation to the CPU, running the framework’s native GPU implementation, and an independently written Metal version specialized for short words. The specialized implementation used single-precision inputs with at most 256 frames, 24 target letters and 32 classes. Both GPU paths passed 159 expanded comparisons each, including repeated letters and paths with no valid alignment.
Wall time for a complete training step
Values are milliseconds. Each reported value is the median of three timing-cell medians in a quiet desktop replay. The table includes fresh batch preparation and the rest of model training.
| Model and batch | CPU loss | Native GPU loss, CPU metadata | Specialized Metal loss |
|---|---|---|---|
| Temporal convolution, 32 | 6.217 | 7.257 | 6.880 |
| Temporal convolution, 128 | 16.415 | 16.038 | 15.769 |
| Temporal convolution, 512 | 58.406 | 53.442 | 53.455 |
| Transformer, 32 | 9.489 | 9.608 | 9.283 |
| Transformer, 128 | 15.876 | 16.158 | 15.474 |
| Transformer, 512 | 61.029 | 56.040 | 55.769 |
Why the batch size mattered
At 512 examples, a separate measurement of just the loss, log-softmax and gradient took 14.147 ms on the CPU path and 1.704 ms on the specialized path with prepared metadata. The calculation was about 8.3 times faster. Complete training steps still had to prepare the batch, run the network and update parameters. At batch 32, the temporal convolution trained fastest with the CPU loss.
The experiment established a bounded numerical and timing result for these word lengths, models and device. Earlier training had found a recognition cost to larger batches at equal example exposure. Time to reach a target recognition quality therefore requires its own comparison.
Sources
- Swaptype word-bounded Metal CTC numerical and runtime experiment
- Graves et al., Connectionist temporal classification
- Apple, Accelerated PyTorch training on Mac