LinearARD: Linear-Memory Attention Distillation for RoPE Restoration

· Source: cs.CL updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, extended

Summary

LinearARD is a novel self-distillation method designed to restore the original capabilities of Large Language Models (LLMs) whose context windows have been extended using Rotary Position Embeddings (RoPE) scaling. This approach addresses the common issue where RoPE scaling and subsequent Continual Pre-Training (CPT) degrade short-text performance. LinearARD achieves this by enforcing attention-structure consistency, aligning the row-wise distributions of dense Q/Q, K/K, and V/V self-relation matrices with a frozen native-RoPE teacher model. To overcome the quadratic memory bottleneck associated with n x n relation maps, it introduces a linear-memory kernel that computes exact Kullback-Leibler divergence and gradients. On LLaMA2-7B extended from 4K to 32K, LinearARD recovers 98.3% of short-text performance and surpasses state-of-the-art baselines on long-context benchmarks, using only 4.25M training tokens, a 60x reduction compared to 256M tokens required by methods like LongReD and CPT. It also recovers 94.8%, 94.2%, and 95.0% of native short-context average accuracy on LLaMA2-7B, LLaMA3-8B, and Mistral-7B-v0.1, respectively, while achieving strong RULER scores.

Key takeaway

For Machine Learning Engineers extending LLM context windows with RoPE scaling, you should consider LinearARD to efficiently restore model capabilities. This method significantly reduces training costs, requiring 60x fewer tokens (4.25M vs. 256M) than CPT or hidden-state distillation, while recovering over 94% of native short-text performance and improving long-context robustness. Implement its two-stage approach, focusing on QKV relation distillation, to maintain structural integrity and avoid catastrophic forgetting.

Key insights

RoPE-scaled LLM capabilities are restored by directly aligning internal QKV self-relation distributions using a linear-memory KL distillation kernel.

Principles

Method

LinearARD employs a two-pass tiled kernel: first, compute and store row-wise log-sum-exp statistics; then, iterate query/key tiles, recompute logits, reconstruct probabilities, and accumulate exact KL gradients with O(n) memory.

In practice

Topics

Code references

Best for: Research Scientist, AI Engineer, AI Scientist, Machine Learning Engineer, NLP Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.CL updates on arXiv.org.