Table of Contents
Fetching ...

DiJiang: Efficient Large Language Models through Compact Kernelization

Hanting Chen, Zhicheng Liu, Xutao Wang, Yuchuan Tian, Yunhe Wang

TL;DR

DiJiang introduces Frequency Domain Kernelization to convert vanilla Transformer attention into a linear-time operation using Weighted Positive Fixed Features and a Discrete Cosine Transform, justified by Bochner's theorem. The method, expressed as $FKA(Q,K,V)=\phi_{WDCF}(Q)\phi_{WDCF}(K)^{\intercal}V$, achieves linear complexity and substantially lowers retraining costs while maintaining performance close to the original Transformer. Empirical results across scales from 70M to 2.8B parameters and on LLaMA2-7B show training cost reductions around 1/16 with up to 10x faster inference, matching or closely approaching baseline accuracy on diverse benchmarks. The work demonstrates that accurate, efficient large-language-model fine-tuning is feasible without full retraining, offering broad applicability to future scalable NLP systems.

Abstract

In an effort to reduce the computational load of Transformers, research on linear attention has gained significant momentum. However, the improvement strategies for attention mechanisms typically necessitate extensive retraining, which is impractical for large language models with a vast array of parameters. In this paper, we present DiJiang, a novel Frequency Domain Kernelization approach that enables the transformation of a pre-trained vanilla Transformer into a linear complexity model with little training costs. By employing a weighted Quasi-Monte Carlo method for sampling, the proposed approach theoretically offers superior approximation efficiency. To further reduce the training computational complexity, our kernelization is based on Discrete Cosine Transform (DCT) operations. Extensive experiments demonstrate that the proposed method achieves comparable performance to the original Transformer, but with significantly reduced training costs and much faster inference speeds. Our DiJiang-7B achieves comparable performance with LLaMA2-7B on various benchmark while requires only about 1/50 training cost. Code is available at https://github.com/YuchuanTian/DiJiang.

DiJiang: Efficient Large Language Models through Compact Kernelization

TL;DR

DiJiang introduces Frequency Domain Kernelization to convert vanilla Transformer attention into a linear-time operation using Weighted Positive Fixed Features and a Discrete Cosine Transform, justified by Bochner's theorem. The method, expressed as , achieves linear complexity and substantially lowers retraining costs while maintaining performance close to the original Transformer. Empirical results across scales from 70M to 2.8B parameters and on LLaMA2-7B show training cost reductions around 1/16 with up to 10x faster inference, matching or closely approaching baseline accuracy on diverse benchmarks. The work demonstrates that accurate, efficient large-language-model fine-tuning is feasible without full retraining, offering broad applicability to future scalable NLP systems.

Abstract

In an effort to reduce the computational load of Transformers, research on linear attention has gained significant momentum. However, the improvement strategies for attention mechanisms typically necessitate extensive retraining, which is impractical for large language models with a vast array of parameters. In this paper, we present DiJiang, a novel Frequency Domain Kernelization approach that enables the transformation of a pre-trained vanilla Transformer into a linear complexity model with little training costs. By employing a weighted Quasi-Monte Carlo method for sampling, the proposed approach theoretically offers superior approximation efficiency. To further reduce the training computational complexity, our kernelization is based on Discrete Cosine Transform (DCT) operations. Extensive experiments demonstrate that the proposed method achieves comparable performance to the original Transformer, but with significantly reduced training costs and much faster inference speeds. Our DiJiang-7B achieves comparable performance with LLaMA2-7B on various benchmark while requires only about 1/50 training cost. Code is available at https://github.com/YuchuanTian/DiJiang.
Paper Structure (14 sections, 7 theorems, 32 equations, 4 figures, 3 tables, 1 algorithm)

This paper contains 14 sections, 7 theorems, 32 equations, 4 figures, 3 tables, 1 algorithm.

Key Result

Theorem 3.1

(Bochner's Theorem) feller1966introduction. A continuous shift invariant scaled kernel function $K(x,z): \mathbb{R}^d \to R$ is positive definite if and only if it is the Fourier Transform of a unique finite probability measure $p$ on $\mathbb{R}^d$. where the symbol $z^*$ denotes the complex conjugate of $z$.

Figures (4)

  • Figure 1: Illustration of the proposed method, where the computation of queries and keys in the attention mechanism of a Transformer is efficiently mapped to the frequency domain using a fast Discrete Cosine Transform (DCT). This mapping effectively eliminates the softmax operation, thereby substantially reducing the computational complexity of the Transformer.
  • Figure 2: Training Curve of different methods. The proposed method achieves the lowest PPL and the fastest converge speed.
  • Figure 3: Visualization of attention map of different architectures. The results are averaged by multiple heads.
  • Figure 4: Comparison of inference memory and throughput between the proposed DiJIang and vanilla Transformer architecture.

Theorems & Definitions (9)

  • Theorem 3.1
  • Theorem 3.2
  • Theorem 3.3
  • Theorem 1.1
  • proof
  • Theorem 1.2
  • proof
  • Lemma 1.3
  • Lemma 1.4