SPT: Fine-Tuning Transformer-based Language Models Efficiently with Sparsification

Yuntao Gui, Xiao Yan, Peiqi Yin, Han Yang, James ChengarXiv 2023 · DOI

Fine-tuning large language models (LLMs) is the standard approach for task adaptation, yet even parameter-efficient methods like LoRA encounter significant bottlenecks as models scale. SPT (Sparsification for Pre-trained Transformers) addresses these challenges by introducing strategic sparsity into the Transformer architecture, optimizing both memory and computation.

The Bottlenecks of Dense Transformers

Standard Transformer fine-tuning faces two primary resource constraints:

  1. Memory Bottleneck in Multi-Head Attention (MHA): Storing $N \times N$ attention matrices scales quadratically with sequence length, limiting the context window on standard GPUs.
  2. Computational Bottleneck in Feed-Forward Networks (FFN): FFNs contain the majority of model parameters and account for the bulk of floating-point operations (FLOPs).

SPT identifies a "Memory-Time Asymmetry": MHA requires memory optimization (storage sparsity), while FFN requires computational optimization (execution sparsity).

Methodology: Strategic Sparsification

SPT introduces a two-stage pipeline consisting of a Model Adapter and a custom Sparse Engine to handle the unique requirements of sparsified Transformers.

The SPT workflow integrating a Model Adapter for sparsification and a Sparse Engine for efficient execution.

Sparse Multi-Head Attention (MHA)

The authors observe that after the Softmax operation, a tiny fraction of attention weights dominate the total distribution. SPT leverages Product Quantization (PQ) to identify these "top-$L$" query-key pairs efficiently. By mapping vectors to codewords in a codebook, the system estimates similarity using fast integer comparisons rather than expensive floating-point dot products.

Approximating attention scores using Product Quantization (PQ) and a codebook to identify top-L weights.

Routed Feed-Forward Networks (FFN)

To reduce FLOPs, SPT employs a "route network" that dynamically selects a subset of FFN parameter blocks to activate for each token. This dynamic pruning maintains the model's total capacity while significantly reducing the actual workload per forward and backward pass.

Sparse Execution Engine

To translate theoretical sparsity into actual wall-clock speedups, SPT includes a custom execution engine with optimized CUDA kernels, such as Blocked Sparse Matrix-Vector Multiply (BSpMV), designed to handle irregular memory access patterns on GPUs.

Experimental Results

Evaluations on models like OPT-2.7B and LLaMA-7B across benchmarks such as MMLU and Wikitext-103 demonstrate SPT's efficiency:

  • Throughput: Achieved up to a 2.2x speedup compared to full-parameter tuning.
  • Memory Efficiency: Reduced peak VRAM usage by up to 50%, enabling training on significantly longer sequences.
  • Model Quality: Maintained high accuracy with minimal degradation. For instance, on OPT-2.7B, the MMLU score only shifted from 27.0 to 26.1.

Conclusion

SPT proves that introducing sparsity into pre-trained Transformers can yield massive efficiency gains without sacrificing performance. While currently dependent on custom CUDA kernels and specific hyperparameter tuning for sparsity levels ($L$ and $\beta$), it provides a scalable path for leaner LLM adaptation.

Summary updated

BibTeX
@misc{gui2023spt,
  author = {Yuntao Gui and Xiao Yan and Peiqi Yin and Han Yang and James Cheng},
  title = {{SPT: Fine-Tuning Transformer-based Language Models Efficiently with Sparsification}},
  year = {2023},
  eprint = {2312.10365},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.10365},
}
Figure