NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

On-the-Fly Adaptive Distillation of Transformer to Dual-State Linear Attention

Yeonju Ro, Zhenyu Zhang, Souvik Kundu, Zhangyang Wang, Aditya AkellaarXiv 2025 · DOI

Introduction

Large Language Models (LLMs) have revolutionized natural language processing, but their reliance on standard self-attention mechanisms presents significant scaling challenges. The quadratic complexity ($O(T^2)$) of self-attention relative to sequence length and the massive Key-Value (KV) cache requirements make long-context inference both memory- and compute-intensive. While sub-quadratic alternatives like linear attention and State Space Models (SSMs) offer efficiency, they often suffer from "recency bias"—a tendency to forget early tokens in favor of recent ones, which degrades performance on complex, long-range reasoning tasks.

Furthermore, real-world LLM serving environments are highly dynamic. Sudden bursts of long-context requests can lead to unpredictable GPU memory spikes, potentially causing Out-of-Memory (OOM) errors.

Dynamic memory requirements across different nodes, highlighting the memory spikes (hotspots) that can lead to OOM errors in standard LLM serving.

This paper introduces Dual-State Linear Attention (DSLA) and an accompanying adaptive inference framework, DSLA-Serve, to address these challenges. By dynamically swapping standard Transformer layers for DSLA layers, the system can manage memory pressure on the fly without sacrificing accuracy.

Dual-State Linear Attention (DSLA)

The core architectural innovation is the Dual-State Linear Attention mechanism. Unlike traditional linear attention that compresses history into a single fixed-size state, DSLA maintains two specialized hidden states: one for historical context and one for recent tokens.

Visualization of attention scores across different layers and heads, demonstrating the recency bias and varying attention patterns in Transformer models.

As shown in Figure 6, standard attention patterns often exhibit a strong recency bias (e.g., Layer 31, Head 15). DSLA uses a learnable parameter to blend these states layer-by-layer, allowing the model to recover global attention patterns. To ensure these states remain distinct, a contrastive regularization loss is applied during training, forcing the states to attend to different parts of the sequence.

DSLA-Serve: Adaptive Inference

To handle dynamic workloads, the authors propose DSLA-Serve. This framework ranks layers by "sensitivity" using attention entropy. During inference, if the server detects high memory pressure, it progressively converts the least sensitive self-attention layers into DSLA layers. This process instantly releases the associated KV caches, providing a "pay-as-you-go" approach to resource management.

To maintain model integrity during these transitions, the authors employ Chained Fine-Tuning. This progressive distillation strategy ensures the model remains robust across any partial-conversion configuration by training layers to match the teacher model in the specific order they are converted at runtime.

Experimental Evaluation

The proposed methods were evaluated using a wide range of datasets, including SlimPajama for distillation, and various benchmarks for long-context (e.g., HotpotQA, LCC) and short-context (e.g., MMLU, PIQA) performance. Serving simulations utilized augmented Azure LLM inference traces from 2023.

Key Results

  • Efficiency: DSLA-Serve achieves up to 2.3x faster end-to-end latency compared to a Llama2-7B baseline and 3.0x faster than static hybrid models like Zamba-7B.
  • Memory Management: Converting just 25% of layers saves approximately 1GB of KV cache for a 4K context and 2GB for an 8K context.
  • Accuracy: DSLA significantly outperforms pure linear models (GLA-7B, Mamba-7B). Notably, a 25%-converted DSLA model slightly outperformed its Llama2-7B teacher on multi-document QA, demonstrating the effectiveness of dual-state distillation in capturing long-range dependencies.

Discussion and Future Work

While DSLA-Serve effectively reduces dynamic KV cache memory, it introduces a static memory overhead because both Transformer and DSLA weights must reside in GPU memory for instant swapping. Additionally, performance begins to degrade if more than 75% of layers are converted.

Future work aims to mitigate static memory costs through asynchronous weight offloading and prefetching. By leveraging the known conversion order, the system could fetch DSLA weights from the CPU just-in-time, hiding loading latency and further optimizing the memory footprint.

Summary updated

BibTeX
@misc{ro2025fly,
  author = {Yeonju Ro and Zhenyu Zhang and Souvik Kundu and Zhangyang Wang and Aditya Akella},
  title = {{On-the-Fly Adaptive Distillation of Transformer to Dual-State Linear Attention}},
  year = {2025},
  eprint = {2506.09316},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.09316},
}
Figure