Long Context · January 2024
Activation Beacon
intermediate
long-context
Extend a pretrained 4K-context model to 400K context by training a small set of 'beacon' tokens that compress past activations into a compact summary — without retraining the base model.
§ 1 · Premise
Long context without retraining the base
At LLaMA-2-7B’s 4K pretraining length, the per-layer KV cache is MB in fp16, summed to GB across the 32-layer stack. Extending the same model to 128K context multiplies that footprint by before any sequence-length-dependent compute is even started. The mainstream 2023 responses came in two flavours:
- Positional rescaling. YaRN (Peng et al. 2023, arXiv 2309.00071) reinterprets RoPE frequencies for the longer range and continues pretraining the whole model on long-document data — typically several hundred million tokens of fine-tuning, every parameter updated.
- Sliding eviction. StreamingLLM (Xiao et al. 2023, arXiv 2309.17453) keeps a fixed-size window plus a few attention-sink prefix tokens and discards the rest. Cheap, but information older than the window is irretrievably lost.
Activation Beacon (Zhang et al. 2024) takes a third route, closer in spirit to Compressive Transformer (Rae et al. 2019) but redesigned for the modern “freeze the base, fine-tune a small adapter” regime: insert learnable beacon tokens at regular intervals that compress the activations of the preceding window into a small handful of summary states; the base model attends to those summaries instead of the literal past keys. The base model’s weights stay frozen; only the beacon-specific projections are trained. The paper’s headline claim is a context extension (4K 400K) at the cost of B tokens of fine-tuning on a single A800 GPU (§4.1).
§ 2 · Derivation
From sliding-window to learned beacon compression
Starting point — interval segmentation. Partition the input stream into intervals of length (Zhang et al. use , §3.1). For each interval , choose a condensing ratio and append learnable beacon tokens after the interval’s real tokens:
With we get beacons per interval — a compression ratio of activations.
Step 1 — beacon-only projections. A standard Transformer layer applies the same projection matrices to every position. Activation Beacon duplicates these matrices into a parallel beacon set that are used only at beacon positions (§3.2, Eq. 2):
These beacon-specific matrices are the only new trainable parameters. Real-token projections remain frozen at their pretrained values. Crucially, since shares the input hidden dimension with , the model can express any beacon projection that the base attention mechanism is geometrically capable of consuming — no architectural surgery beyond the parallel weight set.
Step 2 — “stepwise expansion” attention mask. Beacons need a non-standard mask to make compression behaviour explicit. Within interval , all real tokens can attend to each other causally and to all earlier intervals’ beacons; no real token attends to any other interval’s real tokens directly. Beacons in interval attend to (a) the real tokens of interval , and (b) all beacons from intervals . Formally, with the real-token positions of interval and its beacon positions (Figure 2):
Two consequences:
- Real tokens never see other intervals’ raw activations — only beacons. The “long context” the base model perceives is a sequence of dense local windows interleaved with compressed summaries.
- Beacons compose hierarchically across intervals: attends to , so a deep enough stack can carry information across arbitrary numbers of intervals at constant per-interval cost.
Step 3 — the condensing ratio menu. A single fixed ratio overfits: short contexts don’t need aggressive compression, very long contexts need more than . Zhang et al. sample uniformly from at each training step (§3.3), training a single beacon parameter set that generalizes across the menu. At inference time, is chosen per deployment based on target context length — small for 16K, large for 400K. This is what gives the technique its extreme range without separate beacon parameters per regime.
Step 4 — autoregressive training loss. Training maximizes the standard next-token
log-likelihood on the real tokens only — beacons emit no prediction. Because beacons appear
in visible(t) for later real tokens, the beacon projections receive gradient from those
future-token losses, which is how the model learns what to compress. The base model’s
parameters never receive a gradient: they are frozen via requires_grad=False and the optimizer
state is only allocated for (§3.3).
Step 5 — cost accounting. Let be total context length, interval size, condensing ratio, heads, head dimension. The KV cache after processing all of :
At K, , the second term is tokens-equivalent of KV cache — well below the local window. The model streams through arbitrarily long contexts at near-constant memory beyond the local window, which is the practical claim behind “400K on a single A800”. Compute per-token attention cost is , linear in with a small constant.
Trainable parameter count. per layer, each , plus a per-layer beacon output projection — a total of per layer. For LLaMA-2-7B’s 32 layers at , that is B added parameters. Zhang et al. report training all of these in billion tokens of fine-tuning data (§4.1); the base 7B model is untouched.
§ 3 · Reference implementation
Beacon-parallel projections and stepwise mask
# Real-token attention weights are frozen; beacon weights are new and trainable.
# h: [B, T, d] hidden state at layer input
# is_beacon[t]: 1 if position t is a beacon token, else 0
# interval_id[t]: which interval position t belongs to (real or beacon)
def beacon_attention(h, is_beacon, interval_id, W_Q, W_K, W_V, W_Qb, W_Kb, W_Vb):
# Per-position projection: select between frozen and beacon weights
q = where(is_beacon[..., None], h @ W_Qb, h @ W_Q) # [B, T, H, d_h]
k = where(is_beacon[..., None], h @ W_Kb, h @ W_K)
v = where(is_beacon[..., None], h @ W_Vb, h @ W_V)
# Stepwise mask: real tokens see own-interval real + all earlier beacons;
# beacons see own-interval real + all earlier beacons.
same_interval = interval_id[None, :] == interval_id[:, None]
earlier_beacon = is_beacon[None, :] & (interval_id[None, :] < interval_id[:, None])
own_real_causal = same_interval & ~is_beacon[None, :] & (arange(T)[None, :] <= arange(T)[:, None])
mask = earlier_beacon | own_real_causal
return scaled_dot_product_attention(q, k, v, attn_mask=mask)
def sample_alpha():
return choice([2, 4, 8, 16, 32, 64, 128]) # per training step
def insert_beacons(tokens, L, alpha):
# Append ceil(L / alpha) beacon slots after each L-token interval
out = []
for chunk in batched(tokens, L):
out.extend(chunk)
out.extend([BEACON_TOKEN] * ceil(len(chunk) / alpha))
return out
The sketch elides the streaming inference loop, in which each interval’s beacons are written
into the KV cache and the interval’s real tokens are then evicted — only the
beacons survive across the long context. See the reference repo
FlagOpen/FlagEmbedding/Long_LLM/activation_beacon
for the full training-time mask construction and rotary-position handling.
§ 4 · Empirical evidence
What is and isn’t known
Introducing paper (Zhang et al. 2024).
- Language modeling at extended context. On PG-19, Proof-Pile, and CodeParrot, a LLaMA-2-7B-Chat base equipped with Activation Beacon at -mix training keeps perplexity within – of the 4K base out to K, and continues to lower perplexity (i.e., gains from longer context) out to K (Table 2, Figure 4). The 4K LLaMA-2 baseline diverges to PPL by 8K.
- Long-document QA. On the LongBench suite (Bai et al. 2023, arXiv 2308.14508) Activation Beacon scores 31.8 average across 9 English tasks, beating LLaMA-2-7B-Chat-4K (24.2), the YaRN-extended LLaMA-2-7B variant in the paper’s reproduction (28.7), and StreamingLLM-extended LLaMA-2-7B (25.9) (Table 3).
- Compression-ratio sweep. The sweep (Table 4) shows monotone PPL degradation as grows, but the degradation is modest ( PPL between and ) — most of the long-context value survives heavy compression.
- Training cost. GPU-hours of A800 time (single-node training) (§4.1). For comparison, YaRN’s continued-pretraining recipe for the same context regime reports an order of magnitude more (Peng et al. 2023, §5.2).
Independent follow-up.
- RULER benchmark (Hsieh et al. 2024, arXiv 2404.06654) evaluates Activation Beacon among 13 long-context techniques. RULER finds Activation Beacon-LLaMA-2-7B retains of base performance at 4K but drops off sharply on multi-hop tasks beyond 32K — the broad pattern is “exact-recall tasks degrade with , semantic tasks tolerate it” (Hsieh et al. §5).
- LongBench v2 (Bai et al. 2024, arXiv 2412.15204) inherited Activation Beacon’s evaluation tasks but the technique itself is not in its leaderboard; the authors note in §6 that “compression-based methods like Activation Beacon plateau on tasks requiring multi-document aggregation.”
- Survey coverage. The technique is consistently cited as one of the canonical “fixed-base compressed-summary” approaches in long-context surveys (e.g., Pawar et al. 2024, arXiv 2402.02244, §4.2).
Sensitivity studies — what is not publicly known. The introducing paper does not report ablations on (a) interval size holding fixed — only the joint sweep over both; (b) how beacon parameters interact with subsequent RoPE rescaling like YaRN or NTK-aware extension; (c) compositional behaviour when stacking Activation Beacon on top of GQA or MLA KV-compression. I don’t know of an independent reproduction at scales above LLaMA-2-7B; the published checkpoints and follow-up evaluations all sit at the 7B regime.
Production adoption. None recorded in this knowledge base. Activation Beacon sits in the research lineage that includes Compressive Transformer and Landmark Attention; its design influences appear in subsequent work on KV-cache compression (e.g., SnapKV, Li et al. 2024) but no frontier dense or MoE production model ships beacon-style learned compression as its long-context primitive.
Lineage
- Predecessors
- Compressive TransformerCompressive
Cite
BibTeX entry for the original paper
@article{arxiv2401_03462,
title = {Soaring from 4K to 400K: Extending LLM's Context with Activation Beacon},
author = {Peitian Zhang, Zheng Liu, Shitao Xiao, Ninglu Shao, Qiwei Ye, Zhicheng Dou},
year = {2024},
eprint = {2401.03462},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.03462}
} Or cite the paper directly: arXiv:2401.03462.
Export
BibTeX
@article{arxiv_2401_03462,
title = {Soaring from 4K to 400K: Extending LLM's Context with Activation Beacon},
author = {Peitian Zhang and Zheng Liu and Shitao Xiao and Ninglu Shao and Qiwei Ye and Zhicheng Dou},
year = {2024},
eprint = {2401.03462},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.03462}
} CSL JSON
{
"id": "arxiv_2401_03462",
"type": "article-journal",
"title": "Soaring from 4K to 400K: Extending LLM's Context with Activation Beacon",
"author": [
{
"literal": "Peitian Zhang"
},
{
"literal": "Zheng Liu"
},
{
"literal": "Shitao Xiao"
},
{
"literal": "Ninglu Shao"
},
{
"literal": "Qiwei Ye"
},
{
"literal": "Zhicheng Dou"
}
],
"issued": {
"date-parts": [
[
2024
]
]
},
"URL": "https://arxiv.org/abs/2401.03462",
"number": "2401.03462",
"source": "arXiv"
} RIS
TY - JOUR
TI - Soaring from 4K to 400K: Extending LLM's Context with Activation Beacon
AU - Peitian Zhang
AU - Zheng Liu
AU - Shitao Xiao
AU - Ninglu Shao
AU - Qiwei Ye
AU - Zhicheng Dou
PY - 2024
JO - arXiv
AN - arXiv:2401.03462
UR - https://arxiv.org/abs/2401.03462
ER -