Low latency transformers for speech processing

Jianbo Ma, Siqi Pan, Deepak Chandran, Andrea Fanelli, Richard CartwrightarXiv 2023

Abstract

The transformer is a fundamental building block in deep learning, and the attention mechanism is the transformer's core component. Self-supervised speech representation learning (SSRL) represents a popular use-case for the transformer architecture. Due to transformers' acausal behavior, the use of transformers for SSRL has been predominantly focused on acausal applications. However, several media processing problems, such as speech processing, require real-time solutions. In this paper, we present an implementation of the attention module that enables training of SSRL architectures with low compute and memory requirements, while allowing real-time inference with low and fixed latency. The attention module proposed in this paper includes two components, streaming attention (SA) and low-latency streaming attention (LLSA). The SA represents our proposal for an efficient streaming SSRL implementation, while the LLSA solves the latency build-up problem of other streaming attention architectures, such as the masked acausal attention (MAA), guaranteeing a latency equal to one layer even when multiple layers are stacked. We present a comparative analysis between the vanilla attention, which we will refer here as acausal attention (AA), the SA, and the LLSA, by training a streaming SSRL with automatic speech recognition as downstream task. When training on librispeech-clean-100 and testing on librispeech-test-clean, our low-latency attention module has a word error rate (WER) of 5.84%, which represents a significant improvement over the MAA (WER = 13.82%). Our implementation also reduces the inference latency from 1.92 to 0.16 seconds. The proposed low-latency module preserves many of the benefits of conventional acausal transformers, but also enables latency characteristics that make it applicable to real-time streaming applications.

Introduction

Transformers have become the gold standard for speech processing tasks, yet their inherent "acausal" nature presents a significant hurdle for real-time applications. Standard transformers require access to the entire sequence—including future frames—to calculate the representation of any single frame. While this "god-view" is beneficial for offline processing, it is impractical for live telecommunications or broadcasting where low latency is critical.

Existing attempts to adapt transformers for streaming often rely on "Masked Acausal Attention" (MAA). However, MAA suffers from two primary drawbacks: computational waste, as the model still computes a full attention matrix only to mask parts of it, and latency build-up, where the look-ahead requirements of stacked layers accumulate, leading to delays that can exceed several seconds.

Methods: Streaming and Low-Latency Attention

To address these limitations, this research introduces two novel modules: Streaming Attention (SA) and Low-Latency Streaming Attention (LLSA).

Streaming Attention (SA)

Instead of calculating a massive $N \times N$ attention matrix and masking it, SA restricts the computation to a specific "receptive field" consisting of a fixed number of past and future frames. This shift changes the computational complexity from quadratic ($O(N^2)$) to linear ($O(N)$), significantly reducing the memory footprint during training and inference.

The Scaled Dot-Product Attention (SDPA) mechanism, the core component modified by the proposed streaming attention modules.

Low-Latency Streaming Attention (LLSA)

The LLSA module is designed to solve the "latency stack" problem. In traditional streaming architectures, if each of 12 layers requires a 2-frame look-ahead, the total latency becomes 24 frames. LLSA introduces a multi-channel approach that manages look-ahead sizes across layers. This architectural innovation ensures that the total system latency remains equal to the look-ahead of just a single layer, regardless of the depth of the transformer stack.

To ensure these theoretical gains translate to actual performance, the authors developed custom CUDA kernels. These kernels are optimized for the "sliding window" operations required by SA and LLSA, bypassing the inefficiencies of standard dense matrix multiplication libraries.

SHuBERT: Streaming HuBERT

The proposed modules were integrated into the HuBERT (Hidden-Unit BERT) framework, a prominent self-supervised speech representation learning (SSRL) architecture. The resulting model, SHuBERT (Streaming HuBERT), demonstrates that high-performance SSRL can be effectively adapted for real-time, streaming environments.

The SHuBERT (Streaming HuBERT) architecture, incorporating the Streaming Transformer Module for real-time processing.

Experimental Results

The models were evaluated using the LibriSpeech corpus, pre-trained on 960 hours of unlabeled audio and fine-tuned on 100 hours of labeled data for speech recognition.

The results highlight a dramatic improvement in real-time viability:

  • Latency Reduction: Inference latency was slashed from 1.92 seconds (using standard MAA methods) to just 0.16 seconds with LLSA.
  • Accuracy Gains: On the test-clean dataset, the LLSA module achieved a Word Error Rate (WER) of 5.84%. This is a substantial improvement over the 13.82% WER produced by the standard masked approach (MAA).
  • Memory Efficiency: By scaling linearly with the receptive field size, the proposed method allows for larger batch sizes and more efficient training on consumer-grade hardware.

Conclusion and Future Work

SA and LLSA provide a robust framework for deploying transformer-based speech models in low-latency environments. While the current implementation already offers massive gains, future work will focus on further optimizing CUDA kernels to reach theoretical peak performance and testing the architecture on a broader range of audio tasks, such as real-time noise suppression and speaker identification.

Summary updated

BibTeX
@misc{ma2023low,
  author = {Jianbo Ma and Siqi Pan and Deepak Chandran and Andrea Fanelli and Richard Cartwright},
  title = {{Low latency transformers for speech processing}},
  year = {2023},
  eprint = {2302.13451},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.13451},
}
Figure