Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Jane Street Tech Blog 11 min read Research hardMaster

Using group theory to explore the space of positional encodings for attention

Requiring a positional encoding for attention to be linear in queries and keys, translation-invariant (depending only on relative position) and continuous forces it to be a one-parameter matrix group A(t)=exp(tX). Classifying the generator X recovers the known options: zero gives NoPE, negative real eigenvalues give exponential decay as in linear attention, and complex conjugate pairs give RoPE, optionally damped as in RetNet and Mamba-3. Defective (non-diagonalizable) generators yield a largely unexplored family with polynomial time terms, and an addendum shows ALiBi can be built from one by augmenting queries and keys. The practical takeaway is that the sensible encodings in this space are probably already in use.

Assumes: attention mechanism in transformerslinear algebra and eigendecompositionmatrix exponentialsbasic group theory

Related posts

  • You could have designed state of the art positional encoding

    Hugging Face hardMaster

    Rotary Positional Encoding (RoPE) can be derived step by step from simple ideas. The derivation starts from the permutation-equivariance of self-attention, demonstrated with Llama 3.2 1B embeddings, and lists five desirable properties for a positional scheme. It then iterates from integer to binary to sinusoidal encodings, showing that sinusoidal encoding already encodes relative offsets as a rotation matrix. The final step moves to a multiplicative rotation of queries and keys inside the QK^T dot product, which preserves vector norms and yields RoPE as used in modern transformers.

  • Falcon-H1: A Family of Hybrid-Head Language Models Redefining Efficiency and Performance

    Hugging Face hardMaster

    Falcon-H1 is a family of six open-weight language models (0.5B to 34B, base and instruct, Apache 2.0-based license) built on a parallel hybrid mixer that runs attention and Mamba-2 SSM heads side by side, with a tunable attention/SSM ratio. Design experiments found that a small fraction of attention suffices, larger SSM memory size and very large RoPE base values help, and depth matters most but costs efficiency. Training departed from convention: hard data shown from the start rather than via a curriculum, high-quality samples reused more often, 35 tuned μP multipliers, and dampening multipliers to remove SSM loss spikes. The models support 256K context and 18 languages, and reach up to 4× prefill and 8× generation throughput over Qwen2.5-32B at long sequence lengths, though they are slightly slower at short contexts.

  • Understanding BigBird's Block Sparse Attention

    Hugging Face hardMaster

    BigBird replaces BERT's quadratic full attention with block sparse attention, which combines sliding-window, global and random attention to approximate full attention at linear cost. That makes sequences up to 4096 tokens practical. Graph intuition shows how global and random connections shorten information paths between tokens, so fewer layers are needed to propagate context. The implementation groups tokens into blocks and uses shifted key copies and gathered random blocks, so the sparse pattern becomes dense matrix multiplications that run efficiently on GPUs and TPUs. The walkthrough maps the 🤗Transformers code, block by block, to the query segments it computes.

  • Optimizing your LLM in production

    Hugging Face mediumAdept

    Serving billion-parameter LLMs efficiently comes down to three levers: lower precision, Flash Attention, and inference-friendly architectures such as ALiBi, rotary embeddings, Multi-Query Attention and Grouped-Query Attention. Weights need roughly 2 GB of VRAM per billion parameters in bfloat16, and measurements on OctoCoder (~15B parameters) show peak memory dropping from about 29 GB in bfloat16 to 15 GB with 8-bit and 9.5 GB with 4-bit bitsandbytes quantization, with little output change but slightly slower inference. Flash Attention addresses self-attention's quadratic memory growth with sequence length by restructuring the computation to make better use of GPU memory. Code examples in Hugging Face Transformers accompany each technique.

  • Perceiver IO: a scalable, fully-attentional model that works on any modality

    Hugging Face hardMaster

    Perceiver IO avoids the quadratic cost of self-attention by running attention over a small fixed set of latent variables (e.g. 256×1280). Inputs of any modality enter only through cross-attention, where the latents supply the queries, and outputs are produced by cross-attention with trainable decoder queries. Walking through the Hugging Face Transformers implementation, the post traces tensor shapes through preprocessors, the latent encoder, decoders and postprocessors. Examples cover byte-level text classification and masked language modeling, which reaches 81.8 on GLUE without a tokenizer, and image classification with learned, Fourier or convolutional preprocessing.

The quest for software engineering knowledge.

Look:
Layout: