arXiv:2610.26722cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.26722

Copying Under Repetition: From Prefix Matching to Position Hashing

Anxin Guo, Tianlong Huang, Chenxiao Yang, Zhiyuan Li

ABSTRACT

Frontier LLMs can copy random text almost flawlessly, yet they often overrun or truncate long blocks of repeated characters. In repeated strings, matching local content no longer reliably identifies where copying should continue or when it should stop. Nevertheless, we show that a two-layer transformer with O(log⁡log⁡N)O(\log \log N)-bit precision and O(log⁡N/log⁡log⁡N)O(\log N/\log \log N) width can copy every string up to a chosen design horizon N and terminate correctly under arbitrary repetition. We use RoPE-style rotations of attention values and outputs (VO-rotations) with small prime periods to encode distances from delimiter anchors modulo those primes. By the Chinese Remainder Theorem, these periodic encodings jointly distinguish all required distances, allowing one retrieval rule to select either the next source token or the end marker. In contrast, we prove a width-independent impossibility result for copying under sequential finite-precision softmax accumulation. It applies to transformers whose only positional input is an additive attention bias that eventually becomes constant, including NoPE and a recursive implementation of ALiBi. Once an identical-token run exceeds the resulting saturation threshold, further repetitions leave the logits unchanged. If this threshold grows sublinearly with N, these models cannot both complete a long all-identical copy and stop correctly, a pattern resembling the termination errors of frontier LLMs. In synthetic copying experiments, baseline transformer models fail on long repeated strings even within the training range. Trained VO models, by contrast, generalize beyond the training lengths with near-perfect accuracy up to length ∼5005\sim 5005, the selected primes' period product.

1 INTRODUCTION

Autoregressively copying text is a fundamental primitive for modern large language models (LLMs). LLMs copy when they reuse retrieved documents, quote code or data, or transfer a specific answer from a chain of thought into the final response. Historically, this copying task has motivated explicit pointer or copy mechanisms in sequence models (Vinyals et al., 2015; Gu et al., 2016; See et al., 2017). Meanwhile, transformers seem to learn to copy easily, often through the “induction head” mechanism (Olsson et al., 2022): they match the already-copied prefix to its earlier occurrence in the prompt and retrieve the subsequent token. For random sequences, short local contexts uniquely identify the occurrence. Jelassi et al. (2024) formalized this content-addressed mechanism, showing that a two-layer transformer (with a particular position encoding) can copy strings of length ≤L\leq L with O(log⁡log⁡L)O(\log \log L) precision—provided the input contains no repeated n-grams.

Surprisingly, however, removing this non-repetition assumption seems to change the difficulty of copying qualitatively. As shown in Figure 1, frontier LLMs that copy random strings near-perfectly sometimes fail catastrophically on strings with long repeated runs of letters, either overgenerating severely or stopping early. Repetition changes what the task demands: when many positions carry

∗^{*}Work partially conducted while at Toyota Technological Institute at Chicago.

the same local content, matching the already-copied prefix no longer picks out which occurrence to continue from, so the model must tell these occurrences apart by other means.

To make this problem concrete, consider one step of autoregressive copying, with current context

⟨BOS⟩,s1,…,sL,⟨EOI⟩,⟨COPY⟩,s1,…,sk,\left\langle\mathrm{B O S}\right\rangle,s_{1},\ldots,s_{L},\left\langle\mathrm{E O I}\right\rangle,\left\langle\mathrm{C O P Y}\right\rangle,s_{1},\ldots,s_{k},

for some k≤Lk \leq L. The task is to output sk+1s_{k+1} if k<Lk < L, or output ⟨EoS⟩\langle EoS \rangle if k=Lk = L. 1^{1} An all-identical source, with si=σs_i = \sigma for every ii, isolates the termination problem: continuing requires only another σ\sigma, but stopping at the right point requires distinguishing progress that local content windows cannot reveal. This raises the question: Can a shallow, low-precision transformer copy reliably under arbitrary repetition and terminate correctly?

The answer is yes: for any fixed finite vocabulary and each sufficiently large design horizon N, a single two-layer transformer can copy every source of length at most N under arbitrary repetition and terminate correctly, using O(log⁡log⁡N)O(\log \log N)-bit precision and O(log⁡N/log⁡log⁡N)O(\log N/\log \log N) width. Our construction uses its first layer to encode each position's offset relative to delimiters—specifically, its distance to the preceding delimiter ( ⟨BOS⟩\langle BOS \rangle in the source or ⟨COPY⟩\langle COPY \rangle in the copy segment)—so that tokens can be retrieved by position rather than by matching their content. The need for a delimiter anchor arises because on an all-identical source, attention cannot extract positional signals from the source tokens themselves. RoPE's query/key rotations (Su et al., 2024) and ALiBi's logit biases (Press et al., 2022) change attention weights but leave the source value vectors identical: redistributing a fixed total attention weight among these tokens does not change their contribution to the output. Position can still affect the output through the weights assigned to special delimiters, such as the beginning-of-source token ⟨BOS⟩\langle BOS \rangle, but only by changing how much of each delimiter's fixed value enters the output. By contrast, value/output rotations (VO-RoPE; Su, 2025) let position act on the returned vector itself: even when two queries attend entirely to ⟨BOS⟩\langle BOS \rangle, the returned vectors can differ because the rotation encodes each query's distance from it.

Our first layer applies these rotations with small prime periods (e.g., 2, 3, ...) to encode delimiter-relative offsets. For each prime period, the rotation encodes the offset modulo that prime, using a few well-separated phases that remain distinguishable at very low precision. By the Chinese Remainder Theorem, the periods jointly distinguish every offset below their product, so the first layer resolves a long range of offsets with low precision and width. The second layer then uses these representations to retrieve either the next source token or the end marker, handling copying and termination with one rule.

References (73)