Distill-then-Replace: Efficient Task-Specific Hybrid Attention Model Construction
Xiaojie Xia, Huigang Zhang, Chaoliang Zhong, Jun Sun, Yusuke Oishi
TL;DR
The paper tackles the high computational cost of full-attention transformers by proposing a two-stage approach to build task-specific hybrids that blend full and linear attention. It introduces blockwise local distillation to transfer per-block behavior from full-attention modules to linear counterparts, followed by a greedy, validation-driven layer replacement that yields an optimized hybrid in a single pass without re-training or architecture search. Empirical results across diverse datasets and backbones show that the resulting hybrids can match or exceed base model performance while delivering substantial throughput gains, with a backbone-agnostic workflow and favorable cost. This work offers a practical pathway to scalable, efficient deployment of foundation-model capabilities in resource-constrained or latency-sensitive settings.
Abstract
Transformer architectures deliver state-of-the-art accuracy via dense full-attention, but their quadratic time and memory complexity with respect to sequence length limits practical deployment. Linear attention mechanisms offer linear or near-linear scaling yet often incur performance degradation. Hybrid models that integrate full and linear attention layers promise a balance between efficiency and expressiveness, but face two major challenges: training such hybrid models from scratch is computationally expensive, and manually designing the optimal placement of attention types is highly nontrivial. We address both issues by first transferring weights from the pretrained full-attention modules to its linear attention counterparts through blockwise local distillation, and second, introducing a greedy layer replacement strategy that iteratively substitutes full attention blocks with linear ones while monitoring validation performance on the target task. This yields a task-specific hybrid model in a single efficient pass, without costly re-training or neural architecture search, and can be applied to any pretrained full-attention backbone for diverse downstream tasks.
