Skip to content

Repository files navigation

rope-vs-absolute-pe-benchmark

Author: João Felipe De Souza

Python PyTorch Transformers CUDA Platform GPU License


Overview

Empirical comparison of Absolute Positional Embeddings vs Rotary Position Embeddings (RoPE) across four dimensions:

  1. Attention sink strength
  2. KV-cache eviction tolerance
  3. Perplexity scaling with context
  4. Decode throughput

Models compared:

  • GPT-2-medium (354M, absolute learned PE)
  • Qwen2-0.5B (494M, RoPE)

For architecture details, see DESIGN.md.


Why This Matters

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.


Key Findings

Finding 1 — Absolute PE produces stronger attention sinks

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.

Finding 2 — RoPE tolerates eviction slightly better

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.

Finding 3 — Sink-preserving helps both, but neither wins cleanly

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.

Finding 4 — Perplexity scales similarly

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.

Finding 5 — GPT-2-medium is faster despite being smaller

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.


Finding 6 (strongest result) — Masked-key ablation proves the difference definitively

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

Main Conclusion

  1. Absolute PE produces stronger attention sinks than RoPE
  2. RoPE tolerates KV-cache eviction slightly better
  3. Both PE types need sink-preserving policies for extreme compression
  4. 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

Results Files

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

Plots

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

Repository Structure

rope-vs-absolute-pe-benchmark/
├── rope_benchmark.py
├── plot_rope.py
├── README.md
├── DESIGN.md
├── LICENSE
├── requirements.txt
├── results/
└── plots/

How to Run

python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
python3 rope_benchmark.py
python3 plot_rope.py

Limitations

  • 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

References

  • 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

About

Empirical comparison of Absolute PE vs RoPE showing that absolute PE is 63× more sensitive to sink token removal than RoPE. Includes attention sink measurement, KV-cache eviction tolerance, masked-key ablation, perplexity scaling, and decode throughput.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages