Author: João Felipe De Souza
Empirical comparison of Absolute Positional Embeddings vs Rotary Position Embeddings (RoPE) across four dimensions:
- Attention sink strength
- KV-cache eviction tolerance
- Perplexity scaling with context
- Decode throughput
Models compared:
- GPT-2-medium (354M, absolute learned PE)
- Qwen2-0.5B (494M, RoPE)
For architecture details, see DESIGN.md.
The choice between absolute PE and RoPE affects:
- how strongly the model relies on attention sinks
- how well the model tolerates KV-cache eviction
- how context scaling behaves
This project closes the loop between the attention-sink-profiler and the kv-cache-eviction-benchmark by comparing the positional encoding systems behind them.
At seq_len=512:
| PE type | Sink share (first 4) | Boost vs uniform |
|---|---|---|
| Absolute | 0.432 | 55.3× |
| RoPE | 0.315 | 40.3× |
Absolute PE concentrates 37% more attention on the first tokens than RoPE.
PPL ratio at budget=64 (vs full 512-token context):
| PE type | Sliding window | Sink8 + window |
|---|---|---|
| Absolute | 57.5× | 50.5× |
| RoPE | 42.1× | 38.2× |
Both degrade badly at extreme compression, but RoPE is ~25% more tolerant.
At budget=128:
| PE type | Sliding | Sink8 + window |
|---|---|---|
| Absolute | 6.1× | 8.0× |
| RoPE | 5.2× | 6.4× |
Interestingly, sink-preserving sometimes makes things slightly worse at moderate budgets because the discontinuity between sink tokens and recent tokens confuses the model.
| seq_len | Absolute PPL | RoPE PPL |
|---|---|---|
| 128 | 10.49 | 8.68 |
| 256 | 3.27 | 3.27 |
| 512 | 1.81 | 1.98 |
| 768 | 1.49 | 1.67 |
RoPE is better at short context; absolute PE is better at longer context. Both converge at moderate lengths.
| Model | PE | seq=512 throughput |
|---|---|---|
| GPT-2-medium | Absolute | 49.7 tok/s |
| Qwen2-0.5B | RoPE | 33.4 tok/s |
GPT-2-medium has fewer parameters (354M vs 494M) and simpler architecture, so it decodes faster despite being an older design.
Using the correct methodology (masking keys, not truncating input), the difference between absolute PE and RoPE becomes dramatic:
Masking first 8 tokens:
| PE type | PPL ratio | Degradation |
|---|---|---|
| Absolute | 1.6458 | +64.6% |
| RoPE | 1.0118 | +1.2% |
Masking recent 8 tokens:
| PE type | PPL ratio |
|---|---|
| Absolute | 1.7604 (+76%) |
| RoPE | 1.0873 (+8.7%) |
Masking middle 8 tokens:
| PE type | PPL ratio |
|---|---|
| Absolute | 1.0099 (~0%) |
| RoPE | 0.9985 (~0%) |
Absolute PE is 63× more sensitive to sink token removal than RoPE.
This means:
- for absolute PE models: sink-preserving KV-cache policies are essential
- for RoPE models: simple sliding window eviction works well
- StreamingLLM-style sink preservation is mainly needed for absolute PE architectures
- Absolute PE produces stronger attention sinks than RoPE
- RoPE tolerates KV-cache eviction slightly better
- Both PE types need sink-preserving policies for extreme compression
- Perplexity scaling is similar — PE type alone does not determine context quality
The practical implication:
- for long-context serving with aggressive eviction, RoPE has a slight edge
- for short-context serving, the PE difference matters less than model quality
| File | Description |
|---|---|
| results/attention_sink.csv | Per-layer sink metrics |
| results/perplexity.csv | PPL at different context lengths |
| results/eviction_tolerance.csv | Eviction policy comparison |
| results/decode_throughput.csv | Decode performance |
| results/metadata.json | Configuration |
| File | Description |
|---|---|
| plots/sink_comparison.png | Sink strength: absolute vs RoPE |
| plots/perplexity_comparison.png | PPL vs context length |
| plots/eviction_tolerance.png | Eviction tolerance comparison |
rope-vs-absolute-pe-benchmark/
├── rope_benchmark.py
├── plot_rope.py
├── README.md
├── DESIGN.md
├── LICENSE
├── requirements.txt
├── results/
└── plots/
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
python3 rope_benchmark.py
python3 plot_rope.py- Only two models compared (not the same parameter count)
- Single GPU, FP16
- Eviction test uses simple input truncation, not masked-key ablation
- Different tokenizers between models affect token count
- Su et al., RoFormer: Enhanced Transformer with Rotary Position Embedding (2021)
- Xiao et al., Efficient Streaming Language Models with Attention Sinks (2023)
- Vaswani et al., Attention Is All You Need (2017) — absolute PE