Abstract: Heterogeneous hardware like the Gaudi processor has been developed to enhance computations, especially matrix operations for Transformer-based large language models (LLMs) for generative AI tasks. However, our analysis indicates that Transformers are not fully optimized on such emerging hardware, primarily due to inadequate optimizations in non-matrix computational kernels like Softmax and in heterogeneous resource utilization, particularly when processing long sequences. To address these issues, we propose an integrated approach (called GFormer) that merges sparse and linear attention mechanisms. GFormer aims to maximize the computational capabilities of the Gaudi processor's Matrix Multiplication Engine (MME) and Tensor Processing Cores (TPC) without compromising model quality. GFormer includes a windowed self-attention kernel and an efficient outer product kernel for causal linear attention, aiming to optimize LLM inference on Gaudi processors. Evaluation shows that GFormer significantly improves efficiency and model performance across various tasks on the Gaudi processor and outperforms state-of-the-art GPUs.
Introduction
GFormer is a novel optimization framework designed to accelerate Transformer models on Intel Gaudi processors by hybridizing sparse and linear attention mechanisms. By intelligently partitioning workloads between Gaudi’s Matrix Multiplication Engine (MME) and its programmable Tensor Processing Cores (TPC), GFormer achieves up to 2.2× speedups over standard implementations with negligible impact on model accuracy.
The Challenge: Hardware-Software Mismatch
While Transformers have become the gold standard for AI, their "self-attention" mechanism suffers from a quadratic bottleneck: as the input sequence length ($N$) grows, the computational cost grows by $N^2$. This makes processing long documents or high-resolution images incredibly expensive.
Specialized hardware like the Intel Gaudi processor was built to solve this, but it faces a "hardware-software mismatch." Gaudi features a heterogeneous architecture: a powerful Matrix Multiplication Engine (MME) for dense math and Tensor Processing Cores (TPC) for non-linear operations like Softmax.
Standard Transformers create a bottleneck at the TPC because Softmax operations don't scale well on SIMD (Single Instruction, Multiple Data) architectures. Furthermore, existing "efficient" attention algorithms often leave one part of the chip idle while the other is overwhelmed.
Proposed Solution: GFormer
GFormer introduces an integrated approach that "fills the chip" by combining two types of efficient attention:
- Windowed Sparse Attention (Optimized for TPC): Instead of every token looking at every other token, tokens only look at a local "window" of neighbors. The authors developed a custom TPC kernel that uses vectorized load/store operations and local memory to make this extremely fast.
- Linear Attention (Optimized for MME): This method approximates the Softmax operation using kernel features, turning the $O(N^2)$ problem into an $O(N)$ one. Since this is mostly matrix multiplication, it runs primarily on the MME.
- Workload Partitioning Algorithm: This is the "brain" of GFormer. It uses a performance model to decide exactly how many attention heads should be sparse vs. linear. The goal is to balance the timing so that the MME and TPC finish their work at the same time, maximizing hardware utilization.
- Efficient Outer Product Kernel: For causal models (like GPT), the authors created a specialized TPC kernel to handle the outer product operations required for linear attention, further offloading work from the MME when necessary.
Experimental Results
The authors evaluated GFormer across both Natural Language Processing (NLP) and Computer Vision (CV) tasks. GPT-Neo models were pre-trained on Wikitext-103 and BookCorpus, then fine-tuned on the GLUE benchmark. Vision Transformers (ViT) were pre-trained on ImageNet 2012.
- Speedups: GFormer achieved up to 2.0× speedup for GPT models and 2.2× speedup for ViT models compared to standard Softmax-based Transformers on Gaudi.
- Hardware Efficiency: The custom windowed attention kernel alone is up to 1.7× faster than the baseline.
- GPU Comparison: GFormer on a single Gaudi processor outperformed state-of-the-art V100 GPUs by up to 1.5× when handling long sequences (6k tokens).
- Accuracy Trade-off: The performance gains came with very little cost. The GPT model saw only a 1.2 point increase in perplexity, and the ViT model saw only a 1.4% drop in Top-1 accuracy on ImageNet.
Analysis and Future Directions
A key insight of this work is that the key to speed on modern hardware isn't just reducing total operations, but ensuring no part of the heterogeneous processor is sitting idle. By choosing windowed attention, GFormer ensures "coalesced" memory access, which TPCs handle efficiently. Furthermore, the use of a hyperparameter ($\tau$) to split attention heads allows for a balance between the local precision of sparse attention and the global context of linear attention.
Limitations include memory management for extremely long sequences (beyond 6k tokens). Future work will focus on extending GFormer to distributed systems, adapting it for other accelerators like AMD Versal ACAP, and exploring applications in Graph Neural Networks (GNNs).
Summary updated