Learn offline 'cheat-sheets' so a 4k LLaMA2 handles 128k tokens, cutting tokens and latency

April 11, 20247 min

Overview

Decision SnapshotReady For Pilot

Compress documents offline, finetune small LoRA adapters on those compressed embeddings, and at inference retrieve and prepend embeddings plus the matching adapter. This reduces token costs and latency while preserving or improving QA accuracy on evaluated datasets.

Citations1

Evidence Strength0.85

Confidence0.90

Risk Signals10

Trust Signals

Findings with numeric evidence: 5/5

Findings with evidence refs: 5/5

Results with explicit delta: 1/5

Reproducibility

Status: Code + data available

Open source: Partial

At A Glance

Cost impact: 80%

Production readiness: 75%

Novelty: 60%

Authors

Sijun Tan, Xiuyu Li, Shishir Patil, Ziyang Wu, Tianjun Zhang, Kurt Keutzer, Joseph E. Gonzalez, Raluca Ada Popa

Links

Abstract / PDF / Code / Data

Why It Matters For Business

LLoCO cuts token processing and GPU costs for long-document QA while improving accuracy and latency, letting teams serve very long documents without buying larger models or more GPUs.

Who Should Care

Summary TLDR

LLoCO compresses long documents offline into short token-embedding "cheat sheets" and then finetunes small LoRA adapters on those embeddings. At inference it retrieves compressed embeddings and the matching adapter, prepends embeddings to the LLM, and generates answers. On LLaMA2-7B this extends effective context to 128k tokens, uses ~30× fewer tokens, gives up to 7.62× inference speedup and up to 11.52× finetuning throughput on A100, and improves long-document QA on several benchmarks. Main limits: the compressor is tied to a specific LLM and adapters are per-document-group.

Problem Statement

Transformer LLMs slow down and run out of GPU memory on very long documents because self-attention and KV caches scale poorly with sequence length. This raises latency, GPU costs, and token billing for long-document QA and summarization.

Main Contribution

Introduce LLoCO: offline context compression + in-domain LoRA finetuning + retrieval of compressed embeddings at inference.

Extend LLaMA2-7B (4k) to effectively handle up to 128k tokens using compressed embeddings.

Key Findings

LLoCO raises average QA performance vs base LLaMA2-7B on evaluated long-doc tasks.

NumbersAvg score 23.44 -> 30.67 (Table 1; +7.23 pts)

Practical UseFinetune small LoRA adapters on compressed embeddings to get measurable QA gains on long documents while processing far fewer tokens.

Evidence RefTable 1

Inference token footprint is reduced by about 30× via compression.

Numbers30× compression ratio (AutoCompressor: 153650 per chunk)

Practical UseIndex compressed embeddings instead of raw text to cut token billing and reduce prompt sizes in production.

Evidence RefAbstract, Table 1, Sec 3

Results

MetricValueBaselineDeltaSplit / DatasetEvidenceEvidence Ref
Average QA score (selected long-doc tasks)30.67 (LLoCO)23.44 (LLaMA2-7B-4k)+7.23QuALITY, Qasper, QMSum, NarrativeQA, HotpotQA (validation)Table 1 shows LLoCO avg 30.67 vs baseline 23.44Table 1
Compression ratio (tokens)30×AutoCompressor setting (153650 embeddings)AutoCompressor compresses chunks 1536→50; used across experimentsSec 3, Table 1

What To Try In 7 Days

Compress a sample collection with an available compressor (AutoCompressor or ICAE) and store embeddings in your vector DB.

Finetune one small LoRA adapter on compressed embeddings for a representative document group and validate QA accuracy.

Serve queries by retrieving compressed embeddings + the matching LoRA adapter, and measure token cost and latency vs your current RAG baseline.

Optimization Features

Token Efficiency
30× fewer tokens during inference
Infra Optimization
Enables long-sequence decoding (up to 128k) without blowing GPU VRAMLower per-token latency on common GPUs (A100, A6000)
Model Optimization
LoRA
System Optimization
Index compressed embeddings in vector DB and retrieve at runtimeLoRA
Training Optimization
LoRA
Inference Optimization
Prepend short summary embeddings instead of full context to reduce KV cacheRetrieve only compressed embeddings for relevant passages

Reproducibility

Code AvailableYes
Data AvailableYes
Open Source StatusPartial
LicenseUnknown

Data URLs

QuALITYQasperNarrativeQAHotpotQAQMSumLongBench

Risks & Boundaries

Limitations

Context encoder (AutoCompressor) is tied to a specific base LLM; a new encoder is needed per model.

Training a high-quality compressor can be costly (authors note ~15B tokens used).

When Not To Use

You need a model-agnostic compressor that works unchanged across many LLMs.

Tasks require long, detailed generated outputs rather than concise Q&A answers.

Failure Modes

Hallucination if LoRA adapter is not trained for the document distribution or compression loses critical facts.

Performance drops on out-of-distribution documents and datasets not represented in finetuning.

Core Entities

Models

LLaMA2-7B-4kLLaMA2-7B-32kLLaMA2-7B-128k (comparative)Longchat7b-v1.5-32kAutoCompressorICAE

Metrics

Exact Match (EM)F1ROUGE (geometric mean)

Datasets

QuALITYQasperNarrativeQAHotpotQAQMSumLongBench

Benchmarks

LongBench

Context Entities

Models

GPT-4 (used for distilled training data)CEPESnapKV