Distance Generalization: Why Positional Encoding Might Be the Problem
A new arXiv paper probes whether transformers can handle changed inter-token distances at inference time. The answer says more about positional encoding than you might expect.
What you will learn
- Why distance generalization is a sharper test of transformer reasoning than length extrapolation.
- How the paper's two synthetic delay copy tasks isolate finite inter-token distance.
- What full versus selective copying reveals about attention and positional encoding.
- Where positional encoding helps, where it hurts, and what the limitation is.
- How to think about positional design for long-context and retrieval workloads.
What is distance generalization, and why does it matter?
Length generalization gets all the attention. You train a transformer on short sequences, test it on longer ones, and watch it fall apart. But length generalization conflates two things: the number of tokens and the distances between them. A new arXiv paper titled Distance generalization in transformers: why bother with positional encoding? separates them. It fixes context length and changes only inter-token distances between training and inference. That is a cleaner probe of whether a model actually learns relational structure or just memorizes positional patterns.
According to the paper, the authors construct two synthetic delay copy tasks. Both involve finite distances between a source token and the point where it must be recalled. In one variant, tokens are copied fully; in the other, selectively. The setup is deliberately minimal: no natural language, no pretraining, just a controlled distance shift. If a transformer fails here, positional encoding is the first suspect. If it succeeds, the paper asks the obvious follow-up: why bother with positional encoding at all?
This matters beyond synthetic benchmarks. Every retrieval-augmented pipeline, every long-context agent, every code assistant that has to jump from a definition to a call site depends on distance generalization. If your model only works when the gap between source and recall looks like training data, your production system has a hidden distribution shift. The paper's framing is a useful lens for anyone building on top of transformers rather than training them from scratch.

The broader context here is that positional encoding has become a default, rarely questioned. Rotary embeddings, ALiBi, learned absolute positions: each is a bet about how distance should be represented. The paper's two delay copy tasks are a way to test that bet directly. You can read the full arXiv entry here.
How do the two delay copy tasks isolate distance?
The design is elegant. In the full-copy task, every source token must be reproduced after a delay. In the selective-copy task, only some tokens are recalled. Both keep context length constant, so any failure is attributable to distance, not sequence length. The paper reported that this separation is what makes the result interpretable: you are not guessing whether the model ran out of context window or lost track of position.
What the authors found is that distance generalization is not automatic. Models trained on a narrow band of distances do not reliably transfer to new ones, even when the total number of tokens is unchanged. That is a stronger claim than the usual length-generalization result, because it removes the confound of longer attention spans. It also implicates positional encoding directly: if the model's only signal about distance is the encoding, then a distance shift is a positional shift, and the model has no fallback.
The selective-copy variant is the more interesting one. Full copying can be solved by a relatively blunt attention pattern. Selective copying requires the model to bind a token to its position and retrieve it later, which is closer to what real tasks demand. The paper's framing suggests that the selective task is where positional encoding earns its keep, and where its failure modes show up most clearly.
So why bother with positional encoding?
Here is the honest answer: because without it, a transformer is permutation-invariant. Attention alone cannot tell token A at position 1 from token A at position 50. Positional encoding is the mechanism that breaks that symmetry. The paper's question is not whether to have it, but whether the standard choices generalize across distances. The evidence points to a gap: models learn the distances they see and do not extrapolate gracefully.
That has a practical implication. If you are fine-tuning a model on a retrieval task where the source is always near the query, you are training a distance-specific model. Move the source farther away at inference and performance degrades, even if the context window is large enough. The paper's synthetic tasks are a controlled version of that failure. For teams building agent memory or long-document QA, this is a design constraint, not a footnote. Related work on keeping reasoning compact rather than sprawling, like SwarmEvolve's approach to skipping chain-of-thought, makes a similar point from a different angle: structure matters more than raw context.
My read is that positional encoding is not the villain. The villain is training on a narrow distance distribution and assuming it will hold. The paper's contribution is to make that assumption testable. If you want a model that generalizes across distances, you need distance diversity in training, or an encoding scheme that is explicitly relative rather than absolute. The paper does not settle which is better, but it gives you the experiment to find out.
What are the limitations, and who should care?
The obvious limitation is that synthetic delay copy tasks are not natural language. Success or failure here does not map directly to a chatbot or a coding assistant. The paper is careful about this, but it is worth stating plainly: distance generalization on toy tasks is a necessary signal, not a sufficient one. A model that passes may still fail on real retrieval, and a model that fails may still be useful within its trained distance band.
The second limitation is scope. The paper focuses on finite distances between source and recall, not on unbounded extrapolation. That is a deliberate choice, and it makes the results cleaner, but it leaves open the question of what happens when distances grow without bound. For practitioners, the takeaway is narrower than the title suggests: know your distance distribution, and test outside it. If you are building on long-context models, the same discipline applies as in OpenAI's air-gapped training approach: control the variables you can, and measure the ones you cannot.
Who should care? Anyone who assumes a bigger context window solves retrieval. It does not, if the model never learned to handle the distances you are asking about. The paper is a useful corrective, and the two delay copy tasks are a cheap way to run the check yourself. For a related look at how evaluation design shapes claims, see Dharma-AI's cost-cut claim. The lesson is the same: the benchmark defines the conclusion.
Source and attribution
arXiv
Distance generalization in transformers: why bother with positional encoding?
Discussion
Add a comment