Optimizing BFloat16 Deployment of Tiny Transformers on Ultra-Low Power Extreme Edge SoCs

Alberto Dequino, Luca Bompani, Luca Benini, Francesco ContiJournal of Low Power Electronics and Applications 2025 · DOI

TL;DR

This paper tackles the challenge of deploying powerful Transformer models on ultra-low-power microcontrollers for edge AI applications. By combining aggressive model pruning with optimized BFloat16 kernels and a specialized library for RISC-V architectures, they achieve significant reductions in memory and power consumption without sacrificing accuracy, opening the door for advanced AI on tiny devices.

What Problem Does This Paper Address?

Modern AI, particularly in areas like natural language processing and computer vision, heavily relies on Transformer architectures. These models, while achieving state-of-the-art performance, are notoriously large and computationally intensive. This makes them unsuitable for resource-constrained devices like microcontrollers, which are common in TinyML applications. Traditional methods to shrink these models, such as aggressive quantization (e.g., to INT4 or INT8), often require complex retraining and can lead to significant accuracy degradation. The authors aim to bridge this gap by enabling the deployment of Transformer models on these extreme edge devices without the need for such intricate quantization techniques.

Methods

The core of the paper's methodology involves a two-pronged approach:

  • Extensive Pruning: The authors exploit the inherent redundancy in Transformer models. They propose a systematic pruning strategy that removes less critical encoder layers. This is not a one-size-fits-all approach; they investigate the impact of pruning on different architectures (MobileBert, TinyViT, tinyLLAMA2) and demonstrate that a controlled accuracy trade-off can be achieved. Crucially, they show that a brief fine-tuning phase can often restore accuracy to near-original levels after pruning.
  • Optimized BFloat16 Kernels and Library: To deploy these pruned models efficiently, they developed optimized kernels for key Transformer operations, particularly Multi-Head Self-Attention (MHSA). They leverage BFloat16 (a 16-bit floating-point format) instead of INT8/INT4, avoiding complex quantization. These kernels are specifically designed for RISC-V multi-core microcontrollers, exploiting features like hardware loops and SIMD instructions. They also incorporated optimizations for the softmax function, including Schraudolph's approximation, and efficient matrix multiplication routines. Their work extends the PULP-Trainlib, a software framework for DNN deployment on RISC-V, to support these Transformer optimizations.

Datasets

The paper evaluates its methodology on several pre-trained Transformer models:

  • MobileBert: Used for sentiment analysis on the GLUE benchmark.
  • TinyViT: Evaluated on the ImageNet-1k dataset.
  • tinyLLAMA2: Used for generative tasks, trained on TinyStories.

No new benchmarks were introduced; instead, existing datasets and tasks were used to demonstrate the effectiveness of their approach.

Key Insights and Ideas

  • Pruning is a viable alternative to aggressive quantization: The paper convincingly shows that judicious pruning of Transformer encoder layers can drastically reduce model size and computational cost, often with minimal accuracy loss, making it a more accessible path to edge deployment than complex quantization schemes.
  • BFloat16 is a sweet spot for edge Transformers: By using BFloat16, the authors avoid the accuracy degradation and retraining complexities associated with lower-bit integer quantization, while still offering significant memory and power savings over FP32.
  • RISC-V microcontrollers are capable of running Transformers: The work demonstrates that with the right optimizations, even small, low-power RISC-V MCUs can execute sophisticated Transformer models, pushing the boundaries of what's possible at the extreme edge.
  • MHSA is the computational bottleneck, but MatMul dominates: While MHSA is the core of Transformers, the paper highlights that matrix multiplication (MatMul) within MHSA accounts for the vast majority of computations and cycles, making it the primary target for optimization.

Key Results

  • Speedup: Achieved up to 220x speedup compared to a naïve C port of the Multi-Head Self Attention PyTorch kernel using BFloat16.
  • Memory Reduction:
    • MobileBert: Memory footprint reduced by up to ~94%.
  • TinyViT: Memory footprint reduced by up to ~57%.
  • tinyLLAMA2 Deployment: Achieved a throughput of 1219 tokens/s with an average power consumption of just 57 mW.
  • Accuracy:
    • MobileBert: Accuracy error below 0.19 (compared to 0.084 for the baseline) with a single encoder layer.
  • TinyViT: Achieved a trade-off with up to ~57% memory reduction and ~39% latency reduction, with an accuracy error increase of ~20% in some configurations.
  • Optimized Kernels: FP32 MHSA kernel is over 116x faster, and FP16 kernel is over 220x faster than the naïve C port.

Limitations and Future Work

  • Accuracy Trade-off with Aggressive Pruning: While the paper demonstrates effective pruning, highly aggressive pruning (e.g., reducing to a single encoder layer) can lead to a noticeable increase in accuracy error, especially for architectures like TinyViT.
  • Softmax Complexity: Despite optimizations, the softmax operation remains computationally more expensive than matrix multiplication, especially as sequence length increases, and may require hardware acceleration for further improvements.
  • Future Work: The authors suggest that further optimization of non-linear activation functions like Softmax and ReLU might require more hardware-focused solutions. They also highlight the potential for further exploration of pruning strategies and the deployment of even larger Transformer models on more capable edge devices.

Summary updated

Abstract

Transformers have emerged as the central backbone architecture for modern generative AI. However, most ML applications targeting low-power, low-cost SoCs (TinyML apps) do not employ Transformers as these models are thought to be challenging to quantize and deploy on small devices. This work proposes a methodology to reduce Transformer dimensions with an extensive pruning search. We exploit the intrinsic redundancy of these models to fit them on resource-constrained devices with a well-controlled accuracy tradeoff. We then propose an optimized library to deploy the reduced models using BFLoat16 with no accuracy loss on Commercial Off-The-Shelf (COTS) RISC-V multi-core micro-controllers, enabling the execution of these models at the extreme edge, without the need for complex and accuracy-critical quantization schemes. Our solution achieves up to 220× speedup with respect to a naïve C port of the Multi-Head Self Attention PyTorch kernel: we reduced MobileBert and TinyViT memory footprint up to ∼94% and ∼57%, respectively, and we deployed a tinyLLAMA SLM on microcontroller, achieving a throughput of 1219 tokens/s with an average power of just 57 mW.
BibTeX
@article{dequino2025optimizing,
  author = {Alberto Dequino and Luca Bompani and Luca Benini and Francesco Conti},
  title = {{Optimizing BFloat16 Deployment of Tiny Transformers on Ultra-Low Power Extreme Edge SoCs}},
  journal = {Journal of Low Power Electronics and Applications},
  year = {2025},
  doi = {10.3390/jlpea15010008},
}
Figure