conv_einsum: A Framework for Representation and Fast Evaluation of Multilinear Operations in Convolutional Tensorial Neural Networks

Tahseen Rabbani, Jiahao Su, Xiaoyu Liu, David Chan, Geoffrey Sangston, Furong HuangarXiv 2024 · DOI

Abstract

Tensorial Neural Networks (TNNs) offer a powerful way to compress massive convolutional models, but they are notoriously difficult to train efficiently because standard libraries lack the capability to optimize the complex sequence of operations they require. This paper introduces conv_einsum, a framework that extends the popular einsum notation to include convolutions and uses a specialized "optimal sequencer" to find the mathematically fastest path to compute these layers. The framework results in up to a 90x reduction in FLOPs and significantly lower memory usage, enabling efficient training and deployment of compressed models.

Introduction: The Challenge of Evaluating Factorized Convolutions

Modern deep learning is characterized by a "size race," with state-of-the-art convolutional networks (ConvNets) reaching billions of parameters. This scale makes them nearly impossible to deploy on edge devices like phones or IoT sensors. Tensorial Neural Networks (TNNs) address this by factorizing giant weight tensors into several much smaller components using methods like CP or Tucker decomposition.

However, while the total number of parameters drops, the number of operations required to perform a forward pass can skyrocket. Evaluating a factorized layer involves a sequence of multilinear operations (MLOs). The order in which these operations are performed drastically changes the size of intermediate results and the total floating-point operations (FLOPs). Existing tools like NumPy’s einsum are optimized for simple contractions but do not support convolutions, leaving researchers to rely on "naive" evaluation paths that are slow and memory-intensive.

The conv_einsum Framework

The authors propose a two-part solution to optimize these operations:

  1. conv_einsum Notation: A new notation that extends the familiar einsum string. By adding a pipe delimiter (|), users can specify which dimensions should undergo convolution. For example, conv_einsum("bshw,tshw->bthw|hw", X, W) specifies a 2D convolution over height (h) and width (w).
  2. The Optimal Sequencer: The framework extends the netcon algorithm—originally used in physics for tensor network contractions—to handle convolutions. This sequencer analyzes the conv_einsum string and tensor dimensions to find a pairwise evaluation path that minimizes FLOPs.
Comparison of a naive evaluation path versus an optimized path generated by the conv_einsum sequencer. The optimized path significantly reduces both FLOP count and the size of intermediate tensors.

To ensure high performance on GPUs, the framework automatically maps these optimized paths to efficient, low-level PyTorch operations like conv1d and conv2d. Furthermore, it integrates gradient checkpointing to save memory during the backward pass by recomputing intermediate values rather than storing them in VRAM.

Experimental Results

The authors evaluated conv_einsum across image classification (CIFAR-10, ImageNet), video classification (UCF-101), and automatic speech recognition (LibriSpeech).

Performance Gains

The framework demonstrated massive reductions in computational overhead. For a ResNet-34 model, conv_einsum achieved a 90x speedup in FLOPs for the final convolutional layers compared to the naive approach. On ImageNet, this translated to a reduction in training time per epoch from 65 minutes to 41 minutes.

Training and testing time comparison between conv_einsum and a naive implementation with checkpointing across various compression ratios (CR). conv_einsum consistently outperforms the baseline.

Memory Efficiency

The sequencer avoids creating massive temporary intermediate tensors, which often lead to "Out of Memory" (OOM) errors in naive implementations. In video classification tasks, where standard PyTorch implementations often crashed with a batch size of 1, conv_einsum successfully handled batch sizes of 20-30 on the same hardware.

Conclusion

conv_einsum bridges the gap between theoretical tensor compression and practical deep learning performance by treating convolutions as first-class citizens in tensor networks. It allows for significant model compression (down to 5-10% of original parameters) while maintaining efficient training cycles. Future work will focus on extending support for non-communicative convolutions and deeper integration with specialized hardware acceleration libraries like NVIDIA’s TensorRT.

Summary updated

BibTeX
@misc{rabbani2024conv,
  author = {Tahseen Rabbani and Jiahao Su and Xiaoyu Liu and David Chan and Geoffrey Sangston and Furong Huang},
  title = {{conv\_einsum: A Framework for Representation and Fast Evaluation of Multilinear Operations in Convolutional Tensorial Neural Networks}},
  year = {2024},
  eprint = {2401.03384},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.03384},
}
Figure