Why Does the Effective Context Length of LLMs Fall Short?

## Abstract

Abstract Advancements in distributed training and efficient attention mechanisms have significantly expanded the context window sizes of large language models (LLMs). However, recent work reveals that the effective context lengths of open-source LLMs often fall short, typically not exceeding half of their training lengths. In this work, we attribute this limitation to the left-skewed frequency distribution of relative positions formed in LLMs pretraining and post-training stages, which impedes their ability to effectively gather distant information.
To address this challenge, we introduce S hif T ed R otray position embedd ING ( StRing ). StRing shifts well-trained positions to overwrite the original ineffective positions during inference, enhancing performance within their existing training lengths.
Experimental results show that without additional training, StRing dramatically improves the performance of the latest large-scale models, such as Llama3.1 70B and Qwen2 72B, by over 10 points on popular long-context benchmarks RULER and InfiniteBench, establishing new state-of-the-art results for open-source LLMs. Compared to commercial models, Llama 3.1 70B with StRing even achieves better performance than GPT-4-128K and clearly surpasses Claude 2 and Kimi-chat.

## 1 Introduction

The increase in context length for large language models (LLMs; OpenAI ; Anthropic ; Bai et al. ; Xiong et al. ; Llama Team ) has facilitated the development of a wide range of applications (Pang et al., ; Bairi et al., ), substantially expanding the capabilities of AI systems.
Recent advancements in efficient training and attention calculation (Li et al., ; Dao, ; Liu et al., ) have made it feasible to train LLMs with exceptionally long context windows.
For instance, Llama3.1 (Llama Team, ) features a context length of 128K tokens, which is $64\times$ longer than that of its initial release (Touvron et al., ).

This trend towards longer context lengths in LLMs promises enhanced capabilities. Previous work has primarily focused on extending the context length of LLMs, with significant efforts devoted to improving data engineering techniques (Fu et al., ; Hu et al., ; Bai et al., ; Zhao et al., ). High-quality natural long-context data are scarce in real-world settings, limiting the availability of such data for training purposes. To address this challenge, recent methods aim to generate synthetic training data that better capture the nuances of naturally occurring long-context information, despite inherent challenges such as time consumption in continual training and potential biases (Zhao et al., ; An et al., ; Lv et al., ). Researchers have also focused on addressing specific architectural limitations. Efforts have been made to correct the improper adjustment of the base frequency in Rotary Position Embedding (RoPE) (Su et al., ; Peng et al., ; Chen et al., ; Lin et al., ; Chen et al., ).

However, recent studies (An et al., ; Zhang et al., ; Li et al., ; Wang et al., ) reveal a notable discrepancy between these theoretical improvements and observed performance. In practice, the effective context utilization of these models often falls substantially below their claimed or training context lengths. For example, on the widely used RULER benchmark (Hsieh et al., ), the effective context length of the latest Llama 3.1 70B model is only 64K, despite employing scaled RoPE base frequency (Peng et al., ) and having sufficient training data (Llama Team, ). In fact, most open-source models demonstrate an effective context length less than 50% of their training length (Hsieh et al., ). A key research question emerges from these observations: Why does the effective context length of LLMs fall short of their training context lengths?

In this study, instead of further extending the context window size of current LLMs, we take a fresh perspective to understand and address this gap. Our core insight revolves around a phenomenon we term the left-skewed position frequency distribution – a pattern of severe undertraining of long-distance position indices during pretraining and post-training stages. This skewed distribution significantly contributes to the model’s suboptimal performance in long-range modeling tasks. In SlimPajama-627B (Cerebras, ), a widely used pretraining corpus (Geng & Liu, ; Zhang et al., ), we clearly observe this left-skewed phenomenon. As illustrated in Figure 1(a), even with presumably adequate long-sequence data, the frequency of position indices decreases dramatically as distances increase. For instance, when training a model with a 2048 context length on SlimPajama, the frequency of position indices used to model relationships between distant tokens (distances $\geq 1024$) is less than 20%, and for even longer distances ($\geq 1536$), it drops below 5%.
Probing experiments conducted during pretraining reveal that the frequency of exposure to specific position indices has a crucial impact on the training context utilization.
Capturing long-range dependencies is inherently more challenging (Zhu et al., ; Wu et al., ), and this challenge is exacerbated when the frequency of position indices allocated to gather distant information is exceedingly low, as observed in Figure 1. In other words, the difficulty in modeling long-term dependencies, coupled with the undertraining of the positions responsible for them, provides a compelling explanation for the discrepancy between the theoretical and practical context lengths in LLMs.

Building on these findings, we investigate whether well-trained positions can be leveraged to capture information from distant inputs during inference. To address this, we propose a training-free approach called ShifTed Rotray position embeddING (StRing). This method eschews the use of positions at the tail of the frequency distribution during inference. Specifically, StRing shifts position indices from the main diagonal of the position matrix toward its bottom-left corner. This adjustment enables the model to represent long-range dependencies using frequently encountered position indices, effectively approximating the undertrained ones. StRing can be efficiently implemented using Flash Attention (Dao, ) by combining two key components: (1) sliding window attention (Beltagy et al., ; Ding et al., ; Xiao et al., ; ) around the diagonal, and (2) self-attention at the bottom-left corner using shifted position indices (Algorithm 1). This implementation incurs no additional computational costs and causes no obvious slowdowns during inference.

By strategically overwriting position indices in the upper range of the training length, we achieve substantial performance enhancements across seven open-source LLMs with context lengths ranging from 2K to 128K on the Needle-in-a-Haystack (4-needle) test, resulting in an average score increase of 18 points.
StRing requires no additional training, enabling seamless scaling up with powerful large-scale models such as Llama3.1 70B (Llama Team, ) and Qwen2 72B (Bai et al., ). This integration not only establishes new state-of-the-art performance for open-source LLMs on long-context benchmarks RULER (Hsieh et al., ) and InfiniteBench (Zhang et al., ) but also enables Llama3.1 to outperform leading commercial models, including GPT-4-128K (OpenAI, ), Claude-2 (Anthropic, ), and Kimi-chat (Moonshot AI, ), across a wide range of synthetic and practical tasks. The substantial improvements achieved by StRing provide strong evidence for our hypothesis: underrepresented position indices at the tail of the position frequency distribution, strongly constrain the long-context capabilities of current LLMs. We hope our findings will inspire new approaches to overcome these limitations and lead to more effective long-context processing in future LLM designs.

## 2 Left-Skewed Position Frequency Distribution

### 2.1 Position Embeddings in LLMs

Self-attention mechanisms (Vaswani et al., ; Radford et al., ; Dai et al., ) inherently lack positional information (Liu et al., ; Su et al., ; Sun et al., ). To introduce positional information, a common approach is to design a function $p$. For an input at position $i$, we inject positional information using the following method: $\mathbf{h}_{i}=p(\mathbf{h},i)$ where $\mathbf{h}$ is the hidden representation of the input token. Another approach involves relative positional encodings (Bao et al., ), such as T5-bias (Raffel et al., ) and ALiBi (Press et al., ), which injects relative positional information by incorporating the relative distance $(i-j)$ when computing the attention score between the $j$-th token and the $i$-th token.

To achieve better training stability and lower perplexity, mainstream large models like Qwen (Hui et al., ) and Llama (Llama Team, ) employ Rotary Position Embedding (RoPE) (Su et al., ) as their positional encoding method. RoPE directly injects positional information into the query and key vectors, enabling the inner product to encode the relative position information between the query and key. We adopt the notation $p$ for the embedding function of RoPE. Considering the $i$-th query and the $j$-th key, we have:
$\mathbf{q}_{i}=p(\mathbf{q},i)$ and $\mathbf{k}_{j}=p(\mathbf{k},j)$.
When computing attention, the inner product $\mathbf{q}_{i}^{\top}\mathbf{k}_{j}$ contains only the relative positional information $(i-j)$, which means for any pair ($m$, $n$) such that $m-n=i-j$, it holds that $\mathbf{q}_{m}^{\top}\mathbf{k}_{n}=\mathbf{q}_{i}^{\top}\mathbf{k}_{j}$.

### 2.2 Relative Position Matrix and Position Frequency

Figure: (a) Natural data distribution
Refer to caption: x1.png

Using relative positional encodings implies that, given training length $L$, the resulting relative position matrix $P$ after computing $\mathbf{Q}^{\top}\mathbf{K}$ is defined by:

$$ $P=\begin{pmatrix}0&&&&\\ 1&0&&&\\ \ddots&\ddots&\ddots&&\\ L-2&\cdots&1&0&\\ L-1&L-2&\cdots&1&0\\ \end{pmatrix}$ (1) $$

where the Toeplitz matrix $P$ captures the relative positional relationships between tokens, with each element $P[m][n]=m-n$ encoding the relative distance between the $m$-th and $n$-th tokens in a sequence. Based on Eq. 1, we define the frequency of relative position $i$ by $f(i)=L-i$, which is the number of occurrences of a relative position $i$. Throughout the remainder of this paper, the term “position” refers to relative position.
The structure of matrix $P$ is linearly skewed toward smaller positions, which inherently favors performance on shorter sequences.
For example, when using a training context window of $L=2048$ tokens, the relative position 2047 occurs only once in $P$.

The frequency of relative positions in $P$ also depends on the data length distribution of the pretraining corpus $\mathcal{C}$.
We can obtain the frequency of relative position $i$ by the following equation:

$$ $f(i)=\sum_{s\in\mathcal{C}}\max(|s|-i,\,0),\quad 0\leq i<L$ (2) $$

We observe that the position frequency distribution is usually highly left-skewed, indicating that the model is frequently exposed to small positions, while larger positions account for only a small proportion. To illustrate this phenomenon, we examine the position distribution when using SlimPajama-627B (Cerebras, ) as the training corpus. The blue bars in Figure 1 illustrate the position frequency distribution based on the natural data length distribution of SlimPajama. Specially, when the training length is 2048, the position indices $i\leq 1024$ account for more than 80% of all indices, whereas those with $i\geq 1536$ constitute less than 5%.
In addition to the biased relative position matrix $P$, the real-world data length distribution is also biased. Given a training context length of 2048 tokens, the data length distribution is shown in Figure 1(a) (orange bars): about 20% of the data consists of sequences around 256-512 tokens, and approximately 20% of the samples are around 2048 tokens. This latter percentage arises because long sequences are segmented into multiple sequences of length 2048, following popular open-source pretraining projects (Geng & Liu, ; Zhang et al., ). Due to the combined effect of the data distribution and the relative position matrix, the frequency of positions decreases following a polynomial trend as the position indices increase.

Despite capturing local dependencies is often effective for LLMs, the imbalance in position frequency distribution when modeling both local and long-range dependencies is more pronounced than expected. This may result in a substantial underrepresentation long-range dependencies.

## 3 A Probing Experiment on Position Frequency and Model Effective Length

In this section, we empirically investigate the impact of the left-skewed position frequency distribution on the effective context length of LLMs.
Since the training data distributions for most open-source LLMs are opaque and cannot be directly analyzed by researchers, this study represents the first exploration of the impact of position frequency during the pretraining stage.

#### Evaluation

To measure the effective context length, we adopt the popular Needle-in-a-Haystack task (gkamradt, ). We use the 4-needle setting, the same as described in the Llama 3.1 report (Llama Team, ), which involves inserting four needles (6-digit numbers (Hsieh et al., ; Mohtashami & Jaggi, )) into the context at various positions. The model should perfectly retrieve at least two of them. The input examples used in this experiment can be found in Table 5 of the Appendix.
The evaluation context length increases in 128-token steps until the model fails to correctly find 2 of 4 inserted needles. We perform 500 tests at each length.

#### Experimental Setup

Figure: (a) Effective length vs. consumed tokens
Refer to caption: x4.png

We pretrain two 1.3B-parameter models (referred to as TinyLlama-1.3B) from scratch on the natural data distribution of the SlimPajama dataset to observe changes in the model’s effective length. The total training tokens are 1T and we evaluate the model’s effective context length for every 10B tokens during training. Both models begin to exhibit needle-retrieval ability after about 50B tokens of training. Since position frequency is difficult to control directly, we perform controlled experiments by adjusting two factors: (1) consumed tokens, and (2) the training context window size. The first factor is straightforward. For the second factor, we illustrate the position frequency distribution after training with 1T tokens using different training lengths (2K and 4K) in Figure 3. The configuration of our pretraining codebase and models is detailed in Section A.2.

#### Findings

Following previous work (Kaplan et al., ),
we demonstrate how the models’ effective length grows with increasing training tokens for two different training lengths (Finding (1)), while our further analysis reveals that the position frequency is the underlying factor (Findings (2) and (3)).

(1) Larger training context window consumes fewer tokens to achieve the same effective context length:
In Figure 2(a), a notable observation is that training with longer sequences results in a greater effective context length when the same number of tokens is consumed. Specifically, the model trained with a sequence length of 4K tokens achieves an effective context length of 1.4K after consuming 400B tokens. In contrast, the model with a 2K training length needs around 1T tokens to attain the same effective context length.

Figure: Figure 3: Position frequency distribution for models trained with different training lengths after consuming 1T tokens. With the same number of tokens, training length has little effect on small relative positions. For example, the relative position 0 appears 4K times in both a single 4K sequence and two 2K sequences with the same total token count of 4K in each case.
Refer to caption: x6.png

(2) Models can achieve similar effective context lengths if they have been exposed to similar frequencies of position indices, even if their maximum training lengths differ:
By directly plotting the effective context length against the frequency of position indices used to model that length (Figure 2(b)), we observe that the growth trends of effective lengths for different models align when the Y-axis represents the frequency of indices at that length. For instance, when the effective context length reaches 1,280 tokens, both models exhibit a position frequency $f(1280)$ of 100B.
This indicates that models can attain comparable effective context lengths when they have been trained on similar frequencies of position indices, regardless of differences in their maximum training lengths.

(3) The growth trend of the model’s effective length aligns with the position frequency distribution:
In Figure 3, we observe that models with different training lengths have close position frequencies when the position index $i\leq 1024$. As $i$ continues to increase, the frequency gap between models trained with 4K and 2K context lengths becomes increasingly larger. The growth rates of these two models’ effective lengths also align with this trend (Figure 2). Both models consume roughly the same number of tokens (around 300B) when reaching an effective length of 1024. However, as the effective length increases further, the growth rate of the model pretrained with a 2K context window becomes significantly slower.

#### Limitations in Gathering Distant Inputs

We visualize the performance of infrequent positions with the Needle-in-a-Haystack (4-needle) test (gkamradt, ). The distance between the query and the needles increases as the depth becomes smaller and the testing context length becomes longer.
The results indicate that when the needle and query are far apart, both TinyLlama 1.3B and the latest Llama3.1 8B model fail to retrieve the needle effectively. In Figure 4, when we place the query at the end of the document, we find that models fail at retrieving information from the beginning of the document. Concretely, in Llama3.1, performance significantly degrades when position indices exceed 90K. TinyLlama struggles to gather information when the distance exceeds 1,536 tokens. We also evaluate 13 models from the open-source community, as shown in Table 4, and find that most failure cases occur within the first $\frac{L}{3}$ of the document. This may indicate that the last $\frac{L}{3}$ positions of current LLMs all fall in the tail of the position frequency distribution.

Figure: Figure 4: NIAH results for our pretrained model TinyLlama-1.3B (2K) and Llama3.1 (128K) where the X-axis means input context length and the Y-axis represents the document depth. In this figure, we clearly observe that for TinyLlama 2K and Llama3.1 128K, most poor-performing cases are concentrated in the lower-left triangle, indicating that the models are unable to gather distant needles.
Refer to caption: x7.png

## 4 Shifted Rotary Position Embedding

In Figure 1(c), we demonstrate that even when all data are concatenated to fill the training context window, positions at the tail remain infrequent. In this section, we introduce ShifTed Rotray position embeddING (StRing), StRing shifts position indices from the diagonal of $P$ towards its bottom-left corner, allowing the model to gather distant information with frequent position indices.

Figure: Figure 5: A illustrative example of StRing for a sequence length of $L=9$. (a) Position indices $6$, $7$, and $8$ are removed from the matrix. (b) Indices 0 0, $1$, $2$, $3$, $4$, and $5$ are shifted from the main diagonal to the lower-left triangle with an offset of $3$. (c) A small constant $W$ is added to all diagonals where $m\geq n-3$, thereby restoring emphasis on the neighboring $W$ tokens. The position matrix of Llama3.1-128K using StRing is shown in Figure 8 Appendix.
Refer to caption: x8.png

### 4.1 Manipulating the Position Matrix

StRing is implemented by manipulating the position matrix $P$. The three main procedure of StRing is shown in Figure 5:

(1) Dropping Infrequent Positions: We begin by assuming that position indices greater than a threshold $N$ falls into the infrequent area. Consequently, StRing initially drops all position indices $i\geq N$. As depicted in Figure 5a, we set $N=6$ and $L=9$, resulting in the removal of position indices $6$, $7$, and $8$ from the matrix and leaving an empty area.

(2) Shifting Frequent Positions: Next, we shift the remaining position indices from the main diagonal (the high-frequency area) to fill the empty triangle in the bottom-left corner of $P$. The shift offset is defined as $S=L-N$. In our example, $S=9-6=3$, as shown in Figure 5b.
For instance, let’s consider the last row of the matrix $P$. The position indices after dropping are $[\color[rgb]{0,0,0}{-,-,-},\color[rgb]{0.12109375,0.46484375,0.70703125}{5,4,3
,2,1,0}]$. To fill the 3 empty slots, we shift the positions leftwards with a stride of 3, and they become $[\color[rgb]{0.12109375,0.46484375,0.70703125}{5,4,3,2,1,0},\color[rgb]{0,0,0}
{2,1,0}]$.
Formally, the updated position matrix is defined as:

$$ $P[m][n]=\begin{cases}P[m][n]-S&\text{if }m\geq n-S,\\ P[m][n]&\text{otherwise}.\end{cases}$ (3) $$

Here, $m,n$ is the row/column index, $m=n-S$ indicates that the element is located on a diagonal of $S$ away from the main diagonal, and $m\geq n-S$ signifies that the element is in the lower-left region relative to this diagonal. The resulting position matrix after this operation is shown in Figure 5b.

(3) Restoring Locality with a Small Window: Applying Eq. 3 disrupts the model’s ability to capture local relationships because it alters the relative positions between neighboring tokens (Su, ; Jin et al., ; An et al., ). Specifically, the relative positions on the $S$-th diagonal are set to zero. Since neighboring tokens are crucial for generating fluent content, we introduce a small local window value $W\ll S$ for elements where $m\geq n-S$, as illustrated in Figure 5c. This adjustment maintains emphasis on the closest $W$ neighboring tokens.
The final position matrix is defined as:

$$ $P[m][n]=\begin{cases}P[m][n]-S+W&\text{if }m\geq n-S,\\ P[m][n]&\text{otherwise}.\end{cases}$ (4) $$

In Eq.4, $S$ is the shift offset, and $W$ is used to ensure the neighboring $W$ tokens remain the closest in terms of positional encoding. Notably, $W$ does not rely on $L$, whereas $S$ heavily depends on $L$. We suggest setting the local window $W\geq 32$ and the offset $\frac{L}{3}\leq S\leq\frac{L}{2}$.
We set $S=\frac{L}{3}$ and $W=128$ for all models across downstream tasks. An ablation study is shown in Figure 7.

#### FlashAttention Implementation

We implement StRing using FlashAttention (Dao et al., ), which is essential for verifying the method on modern large language models (LLMs) that typically have long context windows (e.g., 128K tokens). StRing can be efficiently implemented by modifying the position indices used in RoPE and combining two attention patterns. The pseudocode for StRing is provided in Algorithm 1.
Our implementation splits the standard self-attention mechanism into two components:

- 1.
Sliding Window Attention (lines 11--13):
This approach calculates the attention outputs around the main diagonal by considering positions where $m<n-S$ (line 13). When computing the sliding window attention, there is no need to modify the position indices for either queries (line 6) or keys (line 7).
- 2.
Shifted Self-Attention (lines 15--19):
This method computes the attention outputs in the bottom-left triangle, specifically for positions where $m\geq n-S$, utilizing causal self-attention (line 19). In this process, the position indices for queries are replaced with shifted position indices (line 16). StRing controls the relative distance by only modifying the position indices for queries and there is no influence on caching keys and values.

Finally, we merge the attention outputs from the sliding window around the main diagonal and the left-bottom triangle to produce the final output. An example of applying StRing on Llama3.1 is shown in Section §A.1 and the efficiency test of StRing is shown in Figure 9.

Figure: Algorithm 1 Pseudocode of StRing with FlashAttention

### 4.2 Main results of StRing

In this section, we evaluate the effectiveness of StRing across three widely recognized long-context benchmarks: Needle-in-a-Haystack (NIAH) (gkamradt, ), RULER (Hsieh et al., ), and InfiniteBench (Zhang et al., ).
These tasks enable us to assess StRing’s performance across a broad spectrum of practical scenarios. We also provide some case studies in Tables 7 and 6 in the Appendix.

#### Baselines

We primarily compare StRing with the original position embedding RoPE used in mainstream Large Language Models. Additionally, we evaluate RoPE against several effective extrapolation baselines. Specifically, we compare StRing with the following training-free extrapolation methods: NTK-Aware RoPE (LocalLLaMA, ; ), YaRN (Peng et al., ), ReRoPE (Su, ), Self-Extend (Jin et al., ), and DCA (An et al., ). Extrapolation refers to testing LLMs on sequence lengths beyond their training lengths while StRing focus on improving the performance within the training context size.
NTK-Aware RoPE and YaRN implement extrapolation by increasing the base frequency of RoPE. Meanwhile, ReRoPE, Self-Extend, and DCA modify the position matrix to aviod unseen positions. We reproduced their results using scripts from their official repositories. When testing these extrapolation baselines, we modify the training length of the model to $\frac{2}{3}$ of the original length and set the extrapolation scaling factor to $\frac{L_{\text{test}}}{L_{\text{train}}}=\frac{3}{2}$, meaning the test sequence length is 1.5 times the training length. All other configurations remain the same as in their paper. Our findings indicate that although extrapolation methods can extend the model’s capability to handle longer sequences, the performance improvements are still limited within the original training length.

**Table 1: Needle-in-a-haystack (4 needles) results of 7 base models across various methods (columns reordered from smallest to largest average) where $L_{train}$ means the size of the training context window. All the models were tested using their training length. The number of test cases is 500.**
| Model | $L_{train}$ | ReRoPE | NTK | RoPE(origin) | Self-Extend | YaRN | DCA | StRing |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| TinyLlama-1.3B (ours) | 2k | 62.8 | 62.0 | 56.6 | 60.2 | 68.6 | 74.4 | 84.6 |
| TinyLlama-1.1B-3T | 2k | 77.2 | 79.8 | 69.8 | 83.2 | 88.0 | 80.2 | 97.2 |
| Llama-2-7B | 4k | 98.6 | 98.6 | 98.0 | 95.4 | 98.0 | 91.6 | 100.0 |
| Llama-3-8B | 8k | 99.6 | 100.0 | 99.8 | 99.8 | 100.0 | 99.9 | 99.6 |
| LWM-7B-base | 32k | 25.2 | 19.4 | 31.8 | 29.0 | 22.2 | 28.8 | 50.4 |
| Mistral-7B-base | 32k | 54.5 | 42.2 | 52.8 | 54.2 | 48.2 | 64.2 | 73.0 |
| Llama-3.1-8B | 128k | 53.6 | 71.2 | 66.0 | 65.8 | 68.8 | 72.8 | 95.2 |
| Average | – | 67.3 | 67.6 | 67.8 | 69.6 | 70.5 | 73.1 | 85.7 |

#### Needle-in-a-Haystack

Needle-in-a-Haystack (gkamradt, ) (NIAH) is the most popular long-context task, extensively utilized in recent studies (Zheng et al., ; Liu et al., ). As reported by Hsieh et al. (); Wang et al. (), single needle retrieval is no longer a challenging task for current LLMs, and we adopt the multi-needle setting following Llama 3.1 (Llama Team, ) and the input example can be found in Table 5. We verify the effectiveness of our method on seven community models with training lengths ranging from 2K to 128K.
Across all seven models, LargeWorldModel (LWM-7B-base) (Liu et al., ), Mistral 7B (Mistral.AI, ), and Llama 3.1 8B (Llama Team, ) are continually trained on longer contexts.
On models with various training context lengths, StRing consistently outperforms other methods, achieving the highest scores on each model. Notably, StRing improves the average performance by a significant margin, reaching 85.7% compared to the next best method, DCA, at 73.1%, and the original RoPE at only 67.8%.

**Table 2: Performance of various models and methods on RULER with a tested at a sequence length of 128K. The RULER benchmark consists of 13 tasks (500 test cases for each task) categorized into Needle-in-a-Haystack (NIAH), Variable Tracing (VT), Aggregation, and Question Answering (QA). We report the average scores for each category as well as the overall average across all 13 tasks. Effective denotes the actual effective sequence length as defined in RULER, indicating whether the model surpasses the performance of Llama2 (Touvron et al., ), and Claimed represents the sequence length reported by the model.**
| Models | Effective/Claimed | NIAH | VT | Aggregation | QA | Avg. (13 tasks) |
| --- | --- | --- | --- | --- | --- | --- |
| Llama2-chat | 4K / 4K | 96.9 | 89.7 | 84.8 | 49.7 | 85.6 |
| GPT-4-1106-preview | 64K / 128K | 84.8 | 99.6 | 79.7 | 59.0 | 81.2 |
| GLM4 (Open-source best) | 64K / 1M | 94.4 | 97.7 | 49.7 | 63.6 | 83.1 |
| LWM (7B) | 4K / 128K | 83.4 | 15.2 | 29.1 | 52.6 | 65.0 |
| Phi3-medium (14B) | 8K / 128K | 51.3 | 26.0 | 43.5 | 38.0 | 46.1 |
| Llama3.1 (8B) | 32K / 128K | 92.6 | 70.4 | 36.2 | 58.8 | 77.0 |
| + YaRN | 32K / 128K | 94.7 | 39.8 | 38.2 | 58.8 | 76.3 |
| + DCA | 32K / 128K | 89.5 | 62.5 | 39.2 | 55.2 | 74.4 |
| + Self-Extend | 32K / 128K | 94.9 | 65.0 | 37.3 | 49.8 | 76.8 |
| + ReRoPE | 32K / 128K | 90.0 | 56.3 | 38.7 | 56.9 | 74.4 |
| + StRing | 32K / 128K | 94.0 | 88.1 | 37.6 | 62.7 | 80.0 |
| Yi (34B) | 32K / 200K | 90.2 | 76.8 | 43.4 | 59.9 | 77.3 |
| GradientAI/Llama3 (70B) | 16K / 1M | 84.9 | 56.2 | 41.4 | 59.8 | 72.1 |
| Mixtral (8x22B) | 32K / 64K | 23.8 | 0.0 | 69.7 | 40.8 | 31.7 |
| Command-R-plus (104B) | 32K / 128K | 65.7 | 97.2 | 59.5 | 39.2 | 63.1 |
| Llama3.1 (70B) | 64K / 128K | 78.9 | 59.2 | 39.8 | 47.6 | 66.6 |
| + StRing | 100K / 128K | 92.7 | 95.6 | 50.0 | 63.0 | 81.7 |
| Qwen2 (72B) | 64K / 128K | 48.0 | 79.0 | 70.3 | 47.2 | 53.7 |
| + StRing (new SOTA) | 100K / 128K | 91.2 | 98.4 | 83.7 | 52.2 | 84.6 |
| Test Length: 100K |  |  |  |  |  |  |
| Llama3.1-StRing (70B) | 100K / 128K | 94.6 | 97.8 | 72.1 | 67.3 | 87.2 |
| Qwen2-StRing (72B) | 100K / 128K | 93.9 | 97.7 | 88.1 | 57.8 | 87.8 |

#### RULER

The RULER benchmark (Hsieh et al., ) encompasses a variety of synthetic tasks, including eight variants of Needle-in-a-Haystack (NIAH), as well as tasks involving variable tracking, counting, and long-context question answering (QA). The evaluation code and metrics are from their official repository(^1^11[https://github.com/hsiehjackson/RULER](https://github.com/hsiehjackson/RULER)). The primary results are presented in Table 2.
The results on Llama3.1-8B reveal that, except for our proposed method (StRing), all other extrapolation-based approaches fail to achieve performance improvements. Since our method does not require additional training, we are able to validate its effectiveness on 70B-level models. Applying our method to larger models yields remarkable enhancements: a 15-point improvement on Llama3.1 70B and over a 30-point improvement on Qwen2 72B compared to the baseline. Furthermore, our approach achieved state-of-the-art performance on the RULER benchmark for open-source models. Notably, after applying StRing, both Llama3.1 70B and Qwen2 72B surpass GPT-4-128K in average performance. The remarkable performance gain on large models demonstrates that the frequent positions in large models may possess a stronger potential for modeling long-range dependencies.
Additionally, we also demonstrate that both Llama3.1 and Qwen2 can be effectively boosted to an effective sequence length of 100K on RULER by StRing (the last block in Table 2).

**Table 3: Comparison of StRing with three leading commercial long-context models on InfiniteBench. Each model is evaluated using a maximum context length of 128K.**
| Tasks | Commercial Models | Llama3.1 8B | Llama3.1 70B |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
| GPT-4 | Claude2 | Kimi-chat | RoPE(origin) | StRing | RoPE(origin) | StRing |  |
| En.Sum | 14.73 | 14.45 | 17.93 | 26.00 | 28.22 | 26.89 | 27.64 |
| En.QA | 22.22 | 11.97 | 16.52 | 10.05 | 10.20 | 13.68 | 16.73 |
| En.MC | 67.25 | 62.88 | 72.49 | 65.50 | 70.30 | 76.41 | 81.98 |
| En.Dia | 8.50 | 46.50 | 11.50 | 20.00 | 19.50 | 18.00 | 30.50 |
| Retr.PassKey | 100.00 | 97.80 | 98.14 | 100.00 | 100.00 | 100.00 | 100.00 |
| Retr.Number | 100.00 | 98.14 | 94.42 | 99.32 | 99.89 | 100.00 | 100.00 |
| Retr.KV | 89.00 | 65.40 | 53.60 | 42.00 | 83.00 | 2.22 | 76.07 |
| Code.debug | 39.59 | 2.28 | 18.02 | 22.84 | 26.90 | 29.20 | 32.80 |
| Math.find | 60.00 | 32.29 | 12.57 | 32.18 | 34.87 | 40.92 | 46.28 |
| Avg. | 55.69 | 47.96 | 43.91 | 46.43 | 52.54 | 45.25 | 56.88 |

#### InfiniteBench

InfiniteBench (Zhang et al., ) encompasses a variety of real-world tasks, including long-context question answering (QA), multiple-choice QA, mathematical problem-solving, long-dialogue QA, long-context summarization, retrieval tasks, and code debugging.

The evaluation code and metrics are sourced from the official repository(^2^22[https://github.com/OpenBMB/InfiniteBench](https://github.com/OpenBMB/InfiniteBench)). The results for commercial models are from Zhang et al. ().
We compare our method, StRing, with the original position embedding, RoPE, across two scales of Llama3.1: 8B and 70B parameters. The results are presented in Table 3. StRing demonstrates significant improvements for both models; for instance, we enhance the performance of Llama3.1 70B by over 10 points, establishing a new state-of-the-art for open-source models. On InfiniteBench, our method also surpasses the performance of strong baseline GPT-4-128K and significantly outperforms Claude-2 and Kimi-chat.

Figure: (a) Ablation on local window $W$ ($S=\frac{L}{3}$)
Refer to caption: x9.png

#### Ablation Study

We conduct an ablation study on the Needle-in-a-Haystack (4 needles) task to examine the impact of two main hyperparameters in our StRing: the local window size $W$ and the shifted offset size $S$. The experimental results are shown in Figure 7. We increase the local window size from 4 to 512 and find that when $W\geq 32$, the model achieves a significant improvement compared to the original RoPE method. Furthermore, as long as $W\ll S$, further increasing $W$ does not cause a performance drop. For the offset size $S$, we experiment with values ranging from $\frac{L}{5}$ to $\frac{L}{2}$. As $S$ increases, more position indices are discarded. We observe that within this range, the performance increased with the growth of $S$. However, the trend slowed down when $S$ exceeded $\frac{L}{3}$, indicating that at least the last 33% to 50% of the position can be overwritted.

## 5 Related Work

Long-Context Scaling of LLMs
Modeling long text has always been a challenging problem. With the development of large language models (LLMs), researchers have begun to explore ways to extend these models to handle longer contexts from various perspectives. (1) Efficient Architectures: Jiang et al. (); Fu et al. (); Ding et al. (); Song et al. (); Yang et al. (); Zhu et al. () demonstrate that the training and inference overhead of long-context LLMs can be substantially optimized by sparse attention patterns. Another crucial architecture is state space models (Gu & Dao, ; Yuan et al., ; Lieber et al., ).
(2) Continual Training with Long Data: Efforts have been made to continually train models by collecting high-quality long sequences (Fu et al., ; Zhu et al., ; Wu et al., ; Gao et al., ). (3) LLMs with Infinite Contexts: Recent work has shown that the context length of LLMs can be scaled to infinite, as evidenced by models such as StreamingLLM and InfLLM (Xiao et al., ; ; Han et al., ; Zhang et al., ; Cai et al., ; Lin et al., ; Dong et al., ). However, these methods typically cannot maintain a full KV cache, resulting in weakened long-context capabilities.

Length Extrapolation
Training to extend the model context length incurs significant overhead. Recent works focus on length extrapolation, training on short sequences to infer longer ones, as a means to address this issue (Press et al., ; Raffel et al., ; Han et al., ). An et al. (); Jin et al. (); Su (); Ma et al. (); Zhang et al. () believe that the model’s inability to generalize to longer contexts is caused by positions being out-of-distribution. They achieved effective extrapolation by repeating trained positions, thereby maintaining low perplexity in exceedingly long contexts. On the other hand, Zhu et al. () randomly places large position indices within the training window in the training and infer longer sequences. For RoPE-based LLMs, Peng et al. (); Men et al. (); Zhong et al. (); Wang et al. () reduce the long-range attenuation effect of RoPE by amplifying the base frequency, thereby bringing the remote token closer.

## 6 Conclusion

This work uncovers the limitations of current open-source large language models in effectively utilizing their extended training context windows. We show that using positions at the tail of the left-skewed position frequency distributions strongly hinders models’ long-range dependency modeling ability. We introduce StRing, a novel approach that shifts well-trained positions to replace ineffective ones during inference, thereby enhancing the model’s ability to capture distant contextual information without requiring additional training. Our experiments demonstrate that StRing significantly boosts the performance of strong baselines like Llama 3.1 70B and Qwen-2 72B on prominent long-context benchmarks, setting new state-of-the-art results for open-source LLMs.

## Appendix A Appendix

### A.1 Applying StRING on Llama3.1 128K

In this section, we demonstrate the application of StRing on Llama3.1 128K. We present the utilization of StRing to drop position indices greater than $\frac{2}{3}*L\approx 42$K and $\frac{1}{2}*L=64$K, where $L$=128K represents the training length of Llama3.1. The resulting position matrix is illustrated in Figure 8. In Figure 8a, let us consider the last row of the matrix. The original position indices are $[128\text{K}-1,\ldots,2,1,0]$. After dropping position indices $\geq$ 86K, they become
$[\underbrace{-,-,\ldots,-}_{\text{42K empty slots}},\underbrace{\color[rgb]{
0.12109375,0.46484375,0.70703125}{86\text{K}-1,\ldots,2,1,0}}_{\text{86K
indices}}]$.
To fill the empty slots, we shift the positions leftwards with a stride of $S=42$K, resulting in $[\color[rgb]{0.12109375,0.46484375,0.70703125}{86\text{K}-1,\ldots,2,1,0},
\color[rgb]{0,0,0}{42\text{K}-1,\ldots,2,1,0}]$.
After adding a local window $W$ of 128, we obtain the shifted position indices: $[\color[rgb]{0.12109375,0.46484375,0.70703125}{86\text{K}+127,..,129,128},
\color[rgb]{0,0,0}{42\text{K}-1,\ldots,2,1,0}]$.
Applying StRing with an offset $S=64$K is shown in (Figure 8b). The procedure is the same. We also illustrate the changes in the last row of the position matrix. After dropping position indices $\geq$ 64K, the row is converted to $[\underbrace{-,-\ldots,-}_{\text{64K empty slots}},\color[rgb]{
0.12109375,0.46484375,0.70703125}{64\text{K}-1,\ldots,2,1,0}]$. Then, the well-trained positions are shifted from the diagonal:$[\underbrace{-,-\ldots,-}_{\text{64K empty slots}},\color[rgb]{
0.12109375,0.46484375,0.70703125}{64\text{K}-1,\ldots,2,1,0}]$$\xrightarrow{}$$[\color[rgb]{0.12109375,0.46484375,0.70703125}{64\text{K}-1,..,1,0},\color[rgb
]{0,0,0}{64\text{K}-1,\ldots,1,0}]$.
Finally, the position indices after adding a local window of 128 are $[\color[rgb]{0.12109375,0.46484375,0.70703125}{64\text{K}+127,..,129,128},
\color[rgb]{0,0,0}{64\text{K}-1,\ldots,1,0}]$.

Figure: Figure 8: The resulted position matrix of Llama3.1 128K after shifting. In Figure (a), we use a shifted offset of $\frac{L}{3}\approx 42$K and the local window $W$ is 128. In Figure (b), we overwrite more infrequent positions and the shifted offset is $S=\frac{L}{2}=64$K.
Refer to caption: x11.png

### A.2 Pretraining Setup

We pretrain two 1.3B models with maximum context window sizes of 2048 and 4096 to observe how the models gain the effective context length. The model architecture aligns with TinyLlama 1.1B(^3^33[https://huggingface.co/TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T/blob/main/config.json](https://huggingface.co/TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T/blob/main/config.json)).
We utilize a hidden size of 2,048, the size of the feed-forward layers inside each transformer block is set to 5632. The model employs 32 attention heads and comprises 22 layers. The only difference is the use of the llama3
tokenizer (Llama Team, ), which has a larger vocabulary size of 128,256 tokens compared to the 32,000 tokens in TinyLlama 1.1B. This difference results in a larger embedding matrix. We used the SlimPajama-627B (Cerebras, ) dataset as our pretraining corpus and total training tokens for each model is 1T tokens.

Our pretraining codebase is primarily built on the TinyLlama project(^4^44[https://github.com/jzhang38/TinyLlama](https://github.com/jzhang38/TinyLlama)), a popular codebase for reproducing Llama at the 1B scale. The main speed optimization libraries employed in this project are Fully Sharded Data Parallel (FSDP)(^5^55[https://huggingface.co/docs/accelerate/usage_guides/fsdp](https://huggingface.co/docs/accelerate/usage_guides/fsdp)), FlashAttention-2 (Dao, )(^6^66[https://github.com/Dao-AILab/flash-attention](https://github.com/Dao-AILab/flash-attention)), and
xFormers (Lefaudeux et al., )(^7^77[https://github.com/facebookresearch/xformers](https://github.com/facebookresearch/xformers)). The entire project is based on PyTorch Lightning (^8^88[https://github.com/Lightning-AI/pytorch-lightning](https://github.com/Lightning-AI/pytorch-lightning)). We use the cross entropy loss as the pretraining objective and the AdamW optimizer (Loshchilov & Hutter, ).
Additionally, we employed a cosine learning rate schedule with a maximum learning rate of $4*10^{-4}$, starting from a minimum learning rate of $4*10^{-5}$.
The warmup steps are 2,000. The batch size is set to 4M tokens for different training context lengths. For the model pretrained with a 4K context length, the gradient accumulation is set to twice that of the model trained with a 2K context length. We pack the sequences in a mini-batch into a long sequence and used the variable-length version of Flash Attention(^9^99[https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/flash_attn_interface.py#L1178](https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/flash_attn_interface.py#L1178)) to calculate casual self-attention on packed sequences. A gradient clipping threshold of 1.0 is used to stablize the gradient.

We utilized 16 NVIDIA 80G A100 GPUs on 2 nodes. Training a 1.3B model with a 2K context length and 1T tokens took approximately 28 days, while expanding the context length to a 4K context length took around 32 days.

### A.3 Efficiency Test of StRing

In this section, we demonstrate that StRing can be implemented with negligible additional overhead compared to flash attention by comparing the inference time and GPU memory consumption. We test the baseline and StRing on a single NVIDIA 80G A100 GPU based on Llama3.1 8B. The long inputs are sourced from the summarization task in InfiniteBench (Zhang et al., ). We test the model 50 times and report the average results. The results of inference time are shown in Figure 9(a), where we test the model with context lengths ranging from 64K to 128K. StRing maintains the average time consumed per token within 0.3 seconds of the standard Flash Attention. Figure 9(b) shows the consumption of GPU memory, with the growth of input context lengths, StRing exhibiting only a less than $5$GB increase.

Figure: (a) Inference time
Refer to caption: x12.png

### A.4 Limitations

One limitation of this work is that it only investigates pretraining lengths smaller than 4K tokens, while the question of how to effectively implement long-context training remains an open open. The open-source community’s approaches to this problem remains diverse (Hu et al., ; Fu et al., ; An et al., ; Jin et al., ). For companies, Llama3.1 (Llama Team, ) reported using a 6-stage training approach to gradually implement long-context training, but this makes it difficult to analyze position frequencies because the data distribution used in each stage is unknown.

StRing achieves surprising results by only using frequent position during inference. It is clear that there are many ways to adjust the distribution of frequent positions during training, but this may require data with a distribution similar to the Llama training corpus to avoid the model losing its reasoning ability. A key feature of StRing is that it can be easily applied to all existing models without requiring the collection of high-quality data for training. We leave the problem of addressing the left-skewed distribution from a training perspective as a future work.

Figure: Algorithm 2 Pseudocode of merge_diag_shifted

**Table 4: Performance of GPT-4 and 13 community models on the Needle-in-a-Haystack task at various document depths. The document is split into three equal segments: 0-33% depth, 33-66% depth, and 66-100% depth. Peak Failure Depth indicates the document depth at which the most test cases failed for each model. Results are reported at the training length for each model.**
| Model | $L_{train}$ | HF_PATH | Peak Failure Depth | Acc |
| --- | --- | --- | --- | --- |
| GPT-4-128K | – | – | 0-33.3% | 100.0 |
| Trained on open-source data |  |  |  |  |
| TinyLlama-1.3b-1T(ours) | 2k | – | 0-33.3% | 56.6 |
| TinyLlama-1.1b-1T | 2k | TinyLlama/TinyLlama-1.1B-intermediate-step-480k-1T | 0-33.3% | 38.0 |
| TinyLlama-1.1b-3T | 2k | TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T | 0-33.3% | 69.8 |
| Pythia-1.4b | 2k | EleutherAI/pythia-1.4b | 0-33.3% | 22.5 |
| OpenLlama-3B | 2k | openlm-research/open_llama_3b | 0-33.3% | 85.0 |
| Llama2-7B | 4k | meta-llama/Llama-2-7b | 0-33.3% | 98.0 |
| Llama3-8B | 8k | meta-llama/Llama-3-7b | 0-33.3% | 99.8 |
| Together-base | 32k | togethercomputer/Llama-2-7B-32K | 0-33.3% | 63.0 |
| LWM-base | 32k | LargeWorldModel/LWM-Text-32K | 0-33.3% | 31.8 |
| Mistral-base | 32k | alpindale/Mistral-7B-v0.2-hf | 0-33.3% | 52.8 |
| Llama3.1-8B | 128k | meta-llama/Meta-Llama-3.1-8B | 0-33.3% | 66.0 |
| Yarn-base | 128k | NousResearch/Yarn-Llama-2-7b-128k | 0-33.3% | 32.4 |
| Yi-6b-200k | 200k | 01-ai/Yi-6B-200K | 0-33.3% | 20.8 |
| Gradient-Llama3-8B | 262k | gradientai/Llama-3-70B-Instruct-Gradient-256k | 0-33.3% | 46.0 |

Table: Table 5: The input format of the Needle-in-a-Haystack (4-Needle) test where the needles are 6-digit numbers and the haystack is Paul Graham Essays (gkamradt, ). The needles we use in this work are numbers to exclude the influence by inner-knowledge following previous work (Zhang et al., ; Mohtashami & Jaggi, ; Hsieh et al., ; Zhang et al., )

**Table 6: QA on the Llama3 report (Llama Team, ) using Llama3 StRing and Llama3 RoPE. The input consists of 95,179 tokens after tokenization, with questions primarily from Section 3 of the paper.**
| Llama 3 report | Read the following paper about Llama 3. Answer the question based on the paper. \n\n<br>The Llama 3 Herd of Models\n Llama Team, AI @ Meta1\n\n 1A detailed contributor list can be found in the appendix of this paper.Modern artificial intelligence (AI) systems are powered by foundation models. This paper presents a new set of foundation models, called Llama 3. It is a herd of language models that natively support multilinguality… |
| --- | --- |
| Question | How many long-context training stages does Llama3 have? Please describe them (The answer is in Section 3.4.2 of Llama Team () ) |
| Llama 3 RoPE | Llama3 is a large language model developed by Meta AI, and it has several training stages to achieve its impressive performance. The training stages are as follows:<br>1 Initial Pre-Training: In this stage, Llama3 is pre-trained using AdamW with a peak learning rate of 8x10-5, a linear warm-up of 8,000 steps, and a cosine learning rate schedule decaying to 8x10-7 over 1,200,000 steps.<br>2. Long Context Pre-Training: In this stage, Llama3 is trained on long sequences to support context windows of up to 128K tokens. The model is gradually adapted to the increased context length in increments, starting from the original 8K context window and ending in the final 128K✗(cannot follow instruction) |
| Llama 3 StRing | Llama3 has six stages of long-context training, starting from an 8K context window and ending in a 128K context window. This long-context pre-training stage was performed using approximately 800B training tokens.✓ totally the same as decribed in Section 3.4.2 Answer explanation: The question requires the reader to identify the number of long-context training stages in Llama3 and describe them |
| Question | Describe the differences in model architecture between Llama3 and Llama2<br>(The answer is in Section 3.2 of Llama Team () ) |
| Llama 3 RoPE | The paper describes Llama3 as a dense Transformer model with 405B parameters, while Llama2 is not specified to have a specific model architecture. However, based on the context, it can be inferred that Llama2 is likely a dense Transformer model as well, but with fewer parameters than Llama3. The paper highlights that Llama3 makes minimal architectural modifications to Llama2, suggesting that the main differences between the two models lie in the scale and hyperparameters rather than the architecture itself. ✗(not addressing the question) |
| Llama 3 StRing | The main differences between Llama-3 and Llama-2 are: 1. Llama-3 uses grouped query attention (GQA) with 8 key-value heads to improve inference speed and reduce the size of key-value caches during decoding. 2. Llama-3 uses an attention mask that prevents self-attention between different documents within the same sequence. 3. Llama-3 has a larger vocabulary with 128K tokens, which includes 100K tokens from the tiktoken tokenizer and 28K additional tokens to better support non-English languages. 4. Llama-3 increases the RoPE base frequency hyperparameter to 500,000, which enables better support for longer contexts.✓ |
| Question | How does Llama3 perform context parallelism in training<br>(The answer is in Section 3.3.2 of Llama Team ()) |
| Llama 3 RoPE | A. By using a combination of tensor parallelism, pipeline parallelism, and data parallelism. B. By using a combination of pipeline parallelism and data parallelism. C. By using a combination of tensor parallelism and data parallelism. D. By using a combination of context parallelism, pipeline parallelism, and data parallelism.E. By using only data parallelism. Answer: D✗(deviated from the question) |
| Llama 3 StRing | The context parallelism in Llama-3 training is implemented using an all-gather based method, where the key (K) and value (V) tensors are first all-gathered and then the attention output is computed for the local query (Q) tensor chunk. This approach is used to support different types of attention masks, such as the document mask, and to balance the communication and computation in the critical path. ✓ |
| Question | What are the two criteria used to assess successful adaptation in long-context training<br>(The answer is in Section 3.4.2 of Llama Team ()) |
| Llama 3 RoPE | Model performance on short-context evaluations and needle-in-a-haystack tasks. ✓correct but incomplete |
| Llama 3 StRing | The two criteria used to assess successful adaptation in long-context training are: 1. Model performance on short-context evaluations has recovered completely. 2. The model perfectly solves "needle in a haystack" tasks up to that length. These criteria are mentioned in Section 3.4.2 of the paper. ✓ |

**Table 7: QA on the Llama3 report (Llama Team, ) using Llama3 StRing and Llama3 RoPE. The input consists of 95,179 tokens after tokenization, with questions primarily from Section 4 of the paper.**
| Llama 3 report | Read the following paper about Llama 3. Answer the question based on the paper. \n\n<br>The Llama 3 Herd of Models\n Llama Team, AI @ Meta1\n\n 1A detailed contributor list can be found in the appendix of this paper.Modern artificial intelligence (AI) systems are powered by foundation models. This paper presents a new set of foundation models, called Llama 3. It is a herd of language models that natively support multilinguality, coding, reasoning, and tool usage. Our largest model is a dense Transformer with 405B parameters and a context window of up to 128K tokens. This paper presents an extensive empirical evaluation of Llama 3. We find that Llama 3 delivers… |
| --- | --- |
| Question | At which stages does the llama3 team average the models<br>(The answer is in Section 4.1.5 of Llama Team () ) |
| Llama 3 RoPE | obtained from experiments using various versions of data or hyperparameters at each RM, SFT, or DPO stage? The answer is 4.1.6, Iterative Rounds, and 4.1.6, Iterative Rounds✗(not fluent) |
| Llama 3 StRing | The Llama 3 team averages models obtained from experiments using various versions of data or hyperparameters at each RM, SFT, or DPO stage.✓ |
| Question | Describe the sources of Llama3’s SFT data<br>(The answer is in Section 4.2.2 of Llama Team () ) |
| Llama 3 RoPE | Llama3’s SFT data is sourced from various places, including human annotations, other NLP tasks, and translated data. Human annotations are collected from linguists and native speakers, and are used to create open-ended prompts that represent real-world use cases. ✗(hallucination! it describes the multilingual SFT data) |
| Llama 3 StRing | In the paper, it is stated that the SFT data is comprised of the following sources: "prompts from our human annotation collection with rejection-sampled responses" and "synthetic data targeting specific capabilities". Additionally, it is mentioned that the SFT data is also comprised of "human-curated data" and "small amounts of human-curated data" for certain capabilities. The Llama3 team uses a combination of model-based and rule-based techniques to filter out low-quality training samples and improve overall model performance.✓ (More accurate) |
| Question | From what is Llama-3’s multilingual SFT data derived<br>(The answer is in Section 4.3.2 ) of Llama Team ()) |
| Llama 3 RoPE | Human annotations, data from other NLP tasks, rejection sampled data, and translated reasoning data. ✓ |
| Llama 3 StRing | The multilingual SFT data is primarily derived from sources such as human annotations, data from other NLP tasks, rejection sampled data, and translated reasoning data.✓ |
| Question | How do the authors verify the long context code reasoning of Llama-3<br>(The answer is in Section 4.3.4 of Llama Team ()) |
| Llama 3 RoPE | They select the most commonly depended-upon files, specifically those referenced by at least five other files, and remove one of these key files from a repository.✗(not addressing the question) |
| Llama 3 StRing | The authors verify the long context code reasoning of Llama-3 by parsing Python files to identify import statements and determine their dependencies. From here, they select the most commonly depended-upon files, specifically those referenced by at least five other files. They remove one of these key files from a repository and prompt the model to identify which files depended on the missing file and to generate the necessary missing code. ✓ |
| Question | How does the llama3 team solve the Hallucinations issues<br>(The answer is in Section 4.3.6 of Llama Team ()) |
| Llama 3 RoPE | They follow the principle that post-training should align the model to "know what it knows" rather than add knowledge, and generate data that aligns model generations with subsets of factual data present in the pre-training data.✗(in complete) |
| Llama 3 StRing | The authors use a knowledge probing technique to align the model generations with subsets of factual data present in the pre-training data. This data generation process involves extracting a data snippet from the pre-training data, generating a factual question about these snippets, sampling responses from the model, scoring the correctness of the generations, scoring the informativeness of the generations, and generating a refusal for responses that are consistently informative and incorrect across the generations. ✓ |

## Peer Reviews

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: The results in the paper for the 1.3B Tiny-llama and the commercial models are impressive on the long-context benchmarks. However, assuming the "system" to mean the LLM and STRING combination will be used together, I'd also like to see benchmarks for short-context lengths - especially around coding (MBPP, Humaneval), tool-use (BFCL), and Reasoning (GSM-8K, MATH). If not for all, atleast for 1/2 models to reason if there are any trade-offs. I'm especially curious for coding and tooling benchmarks, since they need to adhere to syntax, which might be compromised by the re-positioning. 

Since you have implemented STRING, what is the latency overheads (and impact on throughput) vis-a-vis vanilla RoPE?
soundness: 3
strengths: Thank you for submitting your paper to ICLR. I thoroughly enjoyed reading your paper, especially it is very well written. 
1. The paper observes "left-skewed position frequency distribution" - a bias in the position indices required to answer a relevant question being towards the shorter end. For example, on SlimPajama, the authors observe that the frequency of position indices used to model relationships between distant tokens (distances
≥1024) is less than 20%, and for even longer distances (≥1536), it drops below 5%.
2. The authors also demonstrate interesting findings, such as "larger training context window consumes fewer tokens to achieve the same context length". Although it's only been tested on tinyllama (1.3B) so weather scaling laws hold is an open problem.
summary: The authors present STRING (Shifted Rotary position embedding) which proposes to shift the position relevance of tokens during inference. With STRING, the authors are able to demonstrate improved performance of 10+ points on RULER, and IB for LLAMA 70B. The authors further train a tiny-llama 1.3B model to demonstrate the effectiveness and compare STRING with SOTA models. The authors also discuss the implementation of STRING with modification to flash attention.
weaknesses: 1. The authors acknowledge in part (3) of 4.1 that "Applying Eq. 3 disrupts the model’s ability to capture
local relationships because it alters the relative positions between neighboring tokens" but I'm not fully convinced if the heuristic of "W" is sufficient to allevate this concern. While emperically the experiments suggest so, I'd have liked to see a slightly more detailed study on the impact of altering the relative positions between neighboring tokens.

---

confidence: 4
contribution: 4
initial_rating: 8
presentation: 4
questions: It is shown that the most distant position S indexes can be ignored during inference to obtain a better performance, have you conducted investigation whether it is the same case for training? Can decreasing the longest context window in training directly yields a better performance in inference?
soundness: 4
strengths: 1. The exploratory analysis about the left-skewed frequency-distribution of position index is insightful, and can help the community understand the potential reasons why the long-context problem exists in current methods.

2. The proposed method is intuitive and simple to implement, which seems effective simultaneously.

3. The presentation of the paper is very clear,  and the analysis together with the method description are easy to follow,
summary: This paper reveals the possible reasons why current LLM can't maintain good performance with long-context task even the training has involved such corpus. According to the analysis on the left-skewed frequency-distribution, the paper proposes a training-free method (STRING) to mitigate the position bias. By replacing infrequent long-range position index to frequently trained positions during inference, their method enhances the long-context capability without requiring additional training. The experiment results on multiple long-context benchmarks demonstrate the effectiveness of STRING.
weaknesses: 1. The parameter S and W needs to be set manually, which maybe improved by an automatic algorithm to obtain a better performance.

---

confidence: 3
contribution: 2
initial_rating: 6
presentation: 3
questions: 1. Can this method also be useful for context extrapolation? I understand that the primary focus of the paper is to improve performance within the pre-trained context window, but I believe this is also a large understated benefit of your method.
soundness: 3
strengths: 1. The paper is clearly written and easy to follow.
2. The proposed method is simple and effective. In particular, it improves the performance of existing LLMs within their pre-trained context window.
3. The proposed method can be easily deployed. STRING does not require any additional training and can therefore be easily applied to existing LLMs. The authors also provide a way to make the method compatible with FlashAttention, enabling fast and efficient inference.
summary: This paper suggests that large language models (LLMs) struggle to handle dependencies over long distances due to the skewed occurrence of relative distance towards shorter ranges while training. The authors propose STRING, a simple method that re-uses more frequently occuring positions for distant tokens, avoiding the use of under-utilized long-distance positions. Through extensive evaluations on long-context benchmarks, they demonstrate that STRING can improve the performance of SOTA models within their pre-trained context windows.
weaknesses: 1. Observation (1) in Section 3 (line 216) is overstated, as training with longer context involves larger computation demands due to the quadratic nature of self-attention. For fair comparison, training efficiency should be compared with the same amount of computation, instead of the number of consumed tokens.
2. STRING looks more like an empirical workaround to avoid using less-frequent positions, rather than a fundamental solution for the problem.

---

confidence: 3
contribution: 2
initial_rating: 6
presentation: 3
questions: 1. Where can we find your implementation of STRING?

2. Are error bars available for the tables in the experiments? If space is limited, could they be included in the Appendix to give readers a better understanding of the variability in the results?

3. Regarding the improved results shown in the experiments, could you provide more insights into why and how STRING performs effectively? Additionally, are there any scenarios where STRING might not perform as well?
soundness: 2
strengths: The paper is well-structured, with clear organization, understandable tables, and figures, effectively addressing an important topic in LLM development.

The empirical analysis of position frequency on the training data is thorough (However, I recommend providing additional explanation regarding the meaning of the plot in Figure 1 in the Appendix for further clarity) .

The method has been evaluated on/against quite a few LLMs.
summary: This paper discusses how current LLMs use only a portion of their maximum context length due to issues in handling distant information. The authors identify the root cause as a left-skewed distribution in the model's relative positions during pretraining and post-training. 

To address this, they introduce a new method called Shifted Rotary Position Embedding (STRING), which adjusts well-trained positions during inference to improve performance without extra training. 
Experimental results show that STRING enhances the context length usage of open-source models like Llama 3.1 70B and Qwen2 72B by over 10 points on benchmarks like RULER and InfiniteBench. STRING's effectiveness even surpasses commercial models like GPT-4-128K, Claude 2, and Kimi-chat.
weaknesses: 1. The code is missing; the provided GitHub link leads to a 404 error.

2. The analysis in Section 3 is intriguing, but the results are limited to small-sized LLMs. It remains uncertain whether the same findings apply to medium- and large-sized LLMs.

Meta-review: This paper proposes a simple and effective method that re-uses more frequently occuring positions for distant tokens via analyzing skewed distribution of LMs.

All reviewers agree the contributions of this paper such as interesting findings, in-depth analsysi, effective method, and promising results. Despite some minor concerns such as lack of experiments at scale, this paper can contribute to LLM community in terms of context length and position embedding. 

So, AC recommends accepting this paper.

Decision: Accept (Poster)