Swap
← Research library

Experiments · October 26, 2026

When a faster alignment calculation helps training

An eightfold improvement in one loss calculation became about a nine-percent improvement in a complete large-batch training step.

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 batchCPU lossNative GPU loss, CPU metadataSpecialized Metal loss
Temporal convolution, 326.2177.2576.880
Temporal convolution, 12816.41516.03815.769
Temporal convolution, 51258.40653.44253.455
Transformer, 329.4899.6089.283
Transformer, 12815.87616.15815.474
Transformer, 51261.02956.04055.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

← Browse all research