A Little Goes a Long Way: Efficient Long Context Training and Inference with Partial Contexts
On the map: Efficient LLM inference and serving → KV cache optimization
Abstract (arXiv)
Training and serving long-context large language models (LLMs) incurs substantial overhead. To address this, two critical steps are often required: a pretrained LLM typically undergoes a separate stage for context length extension by training on long-context data, followed by architectural modifications to reduce the overhead of KV cache during serving. This paper argues that integrating length extension with a GPU-friendly KV cache reduction architecture not only reduces training overhead during length extension, but also achieves better long-context performance. This leads to our proposed LongGen, which finetunes a pretrained LLM into an efficient architecture during length extension. LongGen builds on three key insights: (1) Sparse attention patterns, such as window attention (attending to recent tokens), attention sink (initial ones), and blockwise sparse attention (strided token blocks) are well-suited for building efficient long-context models, primarily due to their GPU-friendly memory access patterns, enabling efficiency gains not just theoretically but in practice as well. (2) It is essential for the model to have direct access to all tokens. A hybrid architecture with 1/3 full attention layers and 2/3 efficient ones achieves a balanced trade-off between efficiency and long-context performance. (3) Lightweight training on 5B long-context data is sufficient to extend the hybrid model's context length from 4K to 128K. We evaluate LongGen on both Llama-2 7B and Llama-2 70B, demonstrating its effectiveness across different scales. During training with 128K-long contexts, LongGen achieves 1.55x training speedup and reduces wall-clock time by 36%, compared to a full-attention baseline. During inference, LongGen reduces KV cache memory by 62%, achieving 1.67x prefilling speedup and 1.41x decoding speedup.
Key facts. Cited by 9 papers in the map (data through 14 Oct 2026). Placed in KV cache optimization, one of 12 directions in Efficient LLM inference and serving. Builds on 45 of its 48 references that are in the map. First posted on arXiv 2 Oct 2024.
Builds on
45 of 48 references.
Closest ancestors · 7
Same direction, newest first
- 2024RazorAttention: Efficient KV Cache Compression Through Retrieval Heads22 Jul
- 2024PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funneling4 Jun
- 2024SnapKV: LLM Knows What You are Looking for Before Generation22 Apr
- 2023Model Tells You What to Discard: Adaptive KV Cache Compression for LLMs3 Oct
- 2023Efficient Memory Management for Large Language Model Serving with PagedAttention12 Sep
- 2023H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models24 Jun
- 2023Scissorhands: Exploiting the Persistence of Importance Hypothesis for LLM KV Cache Compression at Test Time26 May
Other references · 38
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 13,028
- 2020Measuring Massive Multitask Language Understandingcited by 7,963
- 2021Measuring Mathematical Problem Solving With the MATH Datasetcited by 5,371
- 2023Mamba: Linear-Time Sequence Modeling with Selective State Spacescited by 4,718
- 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,703
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,673
- 2020Longformer: The Long-Document Transformercited by 3,413
- 2023Qwen Technical Reportcited by 3,344
- 2023Mistral 7Bcited by 3,164
- 2023FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioningcited by 2,598
- 2023Efficient Streaming Language Models with Attention Sinkscited by 2,186
26 more
- 2022Challenging BIG-Bench Tasks and Whether Chain-of-Thought Can Solve Themcited by 1,807
- 2020Big Bird: Transformers for Longer Sequencescited by 1,684
- 2019Generating Long Sequences with Sparse Transformerscited by 1,546
- 2024RULER: What's the Real Context Size of Your Long-Context Language Models?cited by 1,346
- 2024Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Dualitycited by 1,336
- 2020Efficient Transformers: A Surveycited by 790
- 2021Combining Recurrent, Convolutional, and Continuous-time Models with Linear State-Space Layerscited by 608
- 2020HiPPO: Recurrent Memory with Optimal Polynomial Projectionscited by 605
- 2024MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attentioncited by 383
- 2023Effective Long-Context Scaling of Foundation Modelscited by 303
- 2024Retrieval Head Mechanistically Explains Long-Context Factualitycited by 232
- 2024BABILong: Testing the Limits of LLMs with Long Context Reasoning-in-a-Haystackcited by 215
- 2024Simple linear attention language models balance the recall-throughput tradeoffcited by 208
- 2024Data Engineering for Scaling Language Models to 128K Contextcited by 186
- 2022Mega: Moving Average Equipped Gated Attentioncited by 179
- 2024Samba: Simple Hybrid State Space Models for Efficient Unlimited Context Language Modelingcited by 174
- 2019Blockwise Self-Attention for Long Document Understandingcited by 159
- 2024You Only Cache Once: Decoder-Decoder Architectures for Language Modelscited by 144
- 2024Zamba: A Compact 7B SSM Hybrid Modelcited by 124
- 2024Can Mamba Learn How to Learn? A Comparative Study on In-Context Learning Taskscited by 105
- 2023Towards Efficient Generative Large Language Model Serving: A Survey from Algorithms to Systemscited by 102
- 2023SlimPajama-DC: Understanding Data Combinations for LLM Trainingcited by 72
- 2024RNNs are not Transformers (Yet): The Key Bottleneck on In-context Retrievalcited by 64
- 2022Efficient Long Sequence Modeling via State Space Augmented Transformercited by 37
- 2024Resonance RoPE: Improving Context Length Generalization of Large Language Modelscited by 27
- 2023Sparse Modular Activation for Efficient Sequence Modelingcited by 20
Built on by
Citing papers per year: 2024: 3; 2025: 4; 2026: 2.
9 papers.
- 2025Context Length Alone Hurts LLM Performance Despite Perfect Retrievalcited by 127
- 2024When Precision Meets Position: BFloat16 Breaks Down RoPE in Long-Context Trainingcited by 15
- 2024LightTransfer: Your Long-Context LLM is Secretly a Hybrid Model with Effortless Adaptationcited by 12
- 2024MDCure: A Scalable Pipeline for Multi-Document Instruction-Followingcited by 10
- 2025Reconstructing KV Caches with Cross-layer Fusion For Enhanced Transformerscited by 6
- 2025PromptDistill: Query-based Selective Token Retention in Intermediate Layers for Efficient Large Language Model Inferencecited by 1
- 2025NeedleChain: Measuring Intact Context Comprehension Capability of Large Language Modelscited by 0
- 2026Learning how to Forget: Fine-tuning for Long-Context Sparse Attentioncited by 0
- 2026HHR: Hierarchical Hash Retrieval for Efficient LLM Generationcited by 0
- 2026HHR: Hierarchical Hash Retrieval for Efficient LLM Generation1 Oct 2026
- 2026Learning how to Forget: Fine-tuning for Long-Context Sparse Attention20 Aug 2026
- 2025Reconstructing KV Caches with Cross-layer Fusion For Enhanced Transformers3 Dec 2025
- 2025Context Length Alone Hurts LLM Performance Despite Perfect Retrieval6 Oct 2025
- 2025NeedleChain: Measuring Intact Context Comprehension Capability of Large Language Models30 Jul 2025
- 2025PromptDistill: Query-based Selective Token Retention in Intermediate Layers for Efficient Large Language Model Inference30 Mar 2025
- 2024When Precision Meets Position: BFloat16 Breaks Down RoPE in Long-Context Training20 Nov 2024
- 2024MDCure: A Scalable Pipeline for Multi-Document Instruction-Following30 Oct 2024
- 2024LightTransfer: Your Long-Context LLM is Secretly a Hybrid Model with Effortless Adaptation17 Oct 2024
Similar, not cited
Close in wording, no citation either way
- 2025InfiniteHiP: Extending Language Model Context Up to 3 Million Tokens on a Single GPU
- 2025From 128K to 4M: Efficient Training of Ultra-Long Context Large Language Models
- 2026Out of the Memory Barrier: A Highly Memory Efficient Training System for LLMs with Million-Token Contexts
- 2025RetroInfer: A Vector Storage Engine for Scalable Long-Context LLM Inference
- 2025HGCA: Hybrid GPU-CPU Attention for Long Context LLM Inference
- 2025Breaking the Boundaries of Long-Context LLM Inference: Adaptive KV Management on a Single Commodity GPU
- 2024Discovering the Gems in Early Layers: Accelerating Long-Context LLMs with 1000x Input Token Reduction
- 2024DuoAttention: Efficient Long-Context LLM Inference with Retrieval and Streaming Heads