You could have designed state of the art positional encoding
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.
Related posts
- Using group theory to explore the space of positional encodings for attention
Jane Street Tech Blog hardMasterRequiring 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.
- Differential Transformer V2
Hugging Face hardMasterDifferential Transformer V2 reworks differential attention by doubling query heads while keeping key-value heads fixed, subtracting paired heads within the same GQA group using a per-token, per-head sigmoid-gated λ. This keeps decoding speed on par with a standard Transformer, needs no custom FlashAttention kernels, and drops V1's per-head RMSNorm, which amplified outputs up to ~90x at 8K context and caused gradient instability. A context-RMS analysis shows the gated subtraction lets output magnitude reach zero, helping eliminate attention sinks, with comparisons to off-by-one softmax, gpt-oss sinks and gated attention. Early production-scale pretraining, including a 30A3 MoE, shows 0.02–0.03 lower loss at 1T tokens, fewer loss and gradient spikes at high learning rates, and smaller activation outliers. Ablations confirm that pairing heads across GQA groups, removing λ, or dropping the sigmoid all hurt results.
- The N Implementation Details of RLHF with PPO
Hugging Face hardMasterA from-scratch PyTorch reproduction of OpenAI's 2019 lm-human-preferences RLHF codebase closely matches the original learning curves on stylistic tasks like sentiment and descriptiveness. Along the way it catalogs the implementation details that matter for faithful replication: reward model and value head scoring the concatenated query and response, a dedicated out-of-vocabulary padding token, position-index adjustment for padding, fixed-length sampling that ignores EOS, learning-rate annealing, per-process seeds, reward normalization, rejection sampling and reward whitening. It also documents a TensorFlow vs PyTorch Adam numerical difference that causes overly aggressive updates, and how different base models behave when reward labels come from gpt2-large. Practical notes show how to replicate each behaviour with Hugging Face transformers, along with the hardware constraints of running the original TF1 code.
- Nyströmformer: Approximating self-attention in linear time and memory via the Nyström method
Hugging Face hardMasterNyströmformer replaces quadratic softmax self-attention with an O(n) approximation built on the Nyström method, which reconstructs a matrix from a sampled subset of its rows and columns via a Moore-Penrose pseudoinverse. Sampling columns of the softmax matrix directly is impossible because each entry needs its full row for normalization. The model therefore builds landmarks from segment means of queries and keys and composes three small softmax kernels (n×m, m×m pseudoinverse, m×n), so QKᵀ is never computed. The paper reports 32–64 landmarks staying competitive at sequence lengths of 4096–8192. A walkthrough of the Hugging Face PyTorch implementation follows, along with masked-language-modeling usage of the released checkpoints.
- Introducing RWKV - An RNN with the advantages of a transformer
Hugging Face easyNoviceRWKV is an attention-free language model architecture, derived from Apple's Attention Free Transformer, that trains in parallel like a GPT-style transformer but runs inference as an RNN. Each step needs only matrix-vector operations, memory stays constant as context grows, and ctx8192 models run as fast as ctx1024 ones with the same RAM. RWKV-4 checkpoints from ~170M to 14B parameters were trained on the Pile, alongside Raven chat fine-tunes. The architecture is now integrated into Hugging Face transformers, with pipeline and generate examples and a script for converting raw RWKV weights to HF format.