Long-context continual pre-training (LCCP) is widely used to improve long-context capability, but how its benefits scale with the number of tokens used for LCCP remains unclear. We investigate this question through modeling, monitoring, and validating the benefits of scaling LCCP. First, we establish an empirical additive power law relating long-context performance to model size and the respective token budgets of short-context pre-training and LCCP. Experiments across five model scales and more than one hundred short- and long-context budget configurations show that the fitted law reproduces the observed trends and extrapolates well to held-out model scales. Second, we introduce Constant-Last4, a training and observation protocol that averages the four most recent consecutive checkpoints from a constant-learning-rate run to enable stable monitoring along a single extensible training trajectory. Under this protocol, the same scaling-law form fits well and accurately predicts the LCCP performance trajectory of a 1.22B-parameter model trained on approximately 100B LCCP tokens. Finally, downstream evaluations along this trajectory show continued improvements in long-context performance, with no clear sign of saturation within the evaluated range. These gains persist after both 128K context extension and supervised fine-tuning, with benefits extending to long-context understanding and agentic tasks. Together, these results argue for continuing to scale LCCP rather than stopping early: its gains are stably observable along an extensible trajectory, quantitatively predictable, and transferable to downstream tasks.
Figures & tables
Figure 1: Overview of our framework for modeling, monitoring, and validating long-context performance during LCCP scaling. We develop an empirical scaling law for long-context performance, introduce Constant-Last4 as an extensible training and observation protocol, and evaluate downstream performance gains after context extension and supervised fine-tuning.
Scale
Layers
Dimensions
Heads
Parameters
Hidden
FFN
Attn.
KV
Non-emb.
Total
S1
12
512
1,280
8
2
31M
165M
S2
15
640
1,600
10
2
61M
228M
S3
18
768
1,920
12
2
104M
305M
S4
24
1,024
2,560
16
2
245M
513M
S5
36
1,536
3,840
24
2
821M
1.22B
Table 1: Model configurations.
Figure 2: log(LongPPL) versus Ds and Dl , varying one budget while holding model size and the other budget fixed. Both trends are consistent with power-law decay with an offset.
Figure 3: Scale-extrapolation parity plots for fits from S1–S3 to S4 (left) and S1–S4 to S5 (right), with the fitted laws shown above each panel. Dashed lines denote ideal predictions ( y=x ). R2 and MAPE are computed in log(LongPPL) space on held-out configurations.
Figure 4: Comparison of training and observation protocols using ShortPPL and LongPPL. (a) Different observation rules on S4 with Ds=450N and Dl=50N . (b) Constant-Raw , Constant-Last4 , and matched Linear-Decay across 25 S4 configurations. Constant-Raw yields higher and noisier values for both metrics, whereas Constant-Last4 closely matches Linear-Decay . CCC denotes Lin’s concordance correlation coefficient ( Lin, 1989 ) .
Figure 5: Scaling-law fitting and extrapolation under Constant-Last4 : held-out S4 predictions from an S1–S3 fit (left and middle) and held-out S5 trajectory predictions from an S1–S4 fit (right). In the middle panel, dot colors indicate the absolute percentage error between predicted and measured log(LongPPL) . Precise fitted parameter values are reported in Appendix A.5 .
Figure 6: Prefix fitting of log(LongPPL) along the S5 Constant-Last4 run.
Figure 7: RULER-32K scores along the 32K LCCP trajectory of the S5 model.
Figure 8: Downstream performance after 128K extension and SFT at varying 32K LCCP budgets. Shaded regions in (b) show the range across 3 training seeds. Across these subsequent training stages, larger 32K LCCP budgets generally lead to improved downstream performance.
Appendix figures & tables23 assets
Supplementary material from the paper’s appendix.
Appendix
Quantity
Samples
Total tokens
Mean
Median
Min–max
Source document length
10,000
362,174,270
36,217
36,121
32,768–39,999
Evaluated sequence length
10,000
327,512,254
32,751
32,768
24,709–32,768
Long key tokens
10,000
4,662,555
466.3
330
6–7,127
Short key tokens
10,000
82,542,674
8,254.3
8,137
1,978–18,737
Appendix
Table 2: Statistics of the GovReport PPL test set. Document length is measured with the Llama-3.1 tokenizer; the remaining rows use the tokenizer shared by our evaluated models after truncation at 32,768 tokens.
Variant
Full formula
S4
S5
R2
MAPE
R2
MAPE
No offset
log(LongPPL)=NαA+DsβsBs+DlβlBl
0.7995
3.62%
-0.1031
9.05%
Nonnegative offset
log(LongPPL)=NαA+DsβsBs+DlβlBl+C,C≥0
0.7995
3.62%
-0.1031
9.05%
Free offset (ours)
log(LongPPL)=NαA+DsβsBs+DlβlBl+C
0.9663
1.43%
0.9516
1.71%
Combined budget
log(LongPPL)=NαA+(Ds+Dl)βB+C
0.8935
2.53%
0.8494
2.40%
Effective data
log(LongPPL)=NαA+(Dl+KDs)βB+C
0.9079
2.14%
0.8280
2.94%
Appendix
Table 3: Scale-extrapolation results for formula ablations on the Linear-Decay data. Both R2 and MAPE are computed in log(LongPPL) space. S5 contains five diagonal and four off-diagonal budget configurations. For the three powered-pair variants, k is allowed to vary over 0<k≤2 .
Variant
Full formula
S4
S5
R2
MAPE
R2
MAPE
No offset
log(LongPPL)=NαA+DsβsBs+DlβlBl
0.9354
1.89%
-4.0917
11.01%
Nonnegative offset
log(LongPPL)=NαA+DsβsBs+DlβlBl+C,C≥0
0.9354
1.89%
-4.0917
11.01%
Free offset (ours)
log(LongPPL)=NαA+DsβsBs+DlβlBl+C
0.9747
1.08%
0.9718
0.66%
Combined budget
log(LongPPL)=NαA+(Ds+Dl)βB+C
0.8901
1.95%
0.1388
4.02%
Effective data
log(LongPPL)=NαA+(Dl+KDs)βB+C
0.9155
1.46%
0.7943
1.49%
Appendix
Table 4: The same formula ablations on the Constant-Last4 data, with both R2 and MAPE computed in log(LongPPL) space. S4 contains a 5×5 grid, whereas S5 contains 24 points that hold N and Ds fixed and vary only Dl . For the three powered-pair variants, k is allowed to vary over 0<k≤2 .
Figure 9: Zero contours of the free-offset additive scaling law fitted on S1–S4. The left and right panels show the Linear-Decay and Constant-Last4 fits, respectively. Each curve contains the (Ds,Dl) combinations for which the fitted log(LongPPL) equals zero at the indicated non-embedding parameter count N .
Scale
N (M)
ηstable
ηend
GBS
MBS
Warmup
Realized Ds (B)
90N
180N
270N
360N
450N
S1
31.470
9.7656×10−4
9.766×10−5
128
8
500
2.83
5.66
8.49
11.32
14.16
S2
60.845
9.5419×10−4
9.542×10−5
128
8
1,000
5.48
10.96
16.43
21.91
27.39
S3
104.427
9.7656×10−4
9.766×10−5
256
8
1,000
9.40
18.80
28.20
37.59
46.99
S4
245.417
9.7656×10−4
9.766×10−5
256
4
1,000
22.08
44.17
66.25
88.33
110.42
S5
821.147
9.7656×10−4
9.766×10−5
512
4
1,000
73.99
147.98
221.96
295.95
369.94
Appendix
Table 5: Short-context pre-training configurations. All runs use a 4,096-token sequence length and RoPE base 10,000 . Token counts are in billions and correspond, from left to right, to the nominal 90N , 180N , 270N , 360N , and 450N budgets.
Scale
N (M)
ηstart
ηend
GBS
MBS
Warmup
Realized Dl (B)
10N
20N
30N
40N
50N
S1
31.470
9.766×10−5
9.766×10−6
16
1
0
0.31
0.63
0.94
1.26
1.57
S2
60.845
9.542×10−5
9.542×10−6
16
1
0
0.61
1.22
1.83
2.43
3.04
S3
104.427
9.766×10−5
9.766×10−6
32
1
0
1.04
2.09
3.13
4.18
5.22
S4
245.417
9.766×10−5
9.766×10−6
32
1
0
2.45
4.91
7.36
9.81
12.27
S5
821.147
9.766×10−5
9.766×10−6
64
1
0
8.22
16.44
24.66
32.88
41.10
Appendix
Table 6: Linear-Decay 32K LCCP configurations. All runs use a 32,768-token sequence length, RoPE base 500,000 , and no warmup. Token counts are in billions and correspond, from left to right, to the nominal 10N , 20N , 30N , 40N , and 50N budgets.
Scale
N (M)
Realized Ds (B)
ηstart
ηend
GBS
MBS
Warmup
Realized Dl (B)
10N
20N
30N
40N
50N
120N
S1
31.470
2.83
9.766×10−5
9.766×10−5
16
1
0
0.31
0.63
0.94
1.26
1.57
\
5.66
0.31
0.63
0.94
1.26
1.57
\
8.49
0.31
0.63
0.94
1.26
1.57
\
11.32
0.31
0.63
0.94
1.26
1.57
\
14.16
0.31
0.63
0.94
1.26
1.57
\
Appendix
Table 7: Constant-Raw / Constant-Last4 32K LCCP configurations. Each row reports the realized short- and long-context token counts. All runs use a 32,768-token sequence length, RoPE base 500,000 , and no warmup. The identical start and end learning rates indicate a constant schedule. Token counts are in billions; \ denotes an unavailable configuration.
Stage
Seq. len.
Steps
GBS/MBS
Tokens (B)
LR schedule
RoPE base
128K extension
131,072
1000
16/1
2.10
linear: 9.766×10−5→9.766×10−7
5,000,000
Long-context SFT
32,768
2000
32/1
2.10
linear: 9.766×10−5→9.766×10−7
500,000
Agentic SFT
32,768
4000
32/1
4.20
linear: 9.766×10−5→9.766×10−7
500,000
Appendix
Table 8: Training configurations applied after 32K LCCP. The token counts are the realized values obtained from the listed sequence length, GBS, and number of optimizer steps.
Source-document length
32K LCCP
128K extension
[0,4K)
27.63%
21.90%
[4K,8K)
14.39%
10.79%
[8K,16K)
10.55%
7.91%
[16K,32K)
12.54%
9.40%
[32K,64K)
11.12%
15.94%
[64K,128K)
8.68%
12.44%
Appendix
Table 9: Aggregate LCCP sampling weights by tokenized source-document length. Values denote percentages of the configured sampling mass.
Task family
Sampling mass
General and multilingual instruction following
10.00%
Long-context question answering and reasoning
40.00%
Search-agent trajectories
30.00%
Function and tool calling
20.00%
Total
100.00%
Appendix
Table 10: Task-level composition of the SFT mixture. Percentages denote configured sampling mass.
Fit
A
α
Bs
βs
Bl
βl
C
LD (S1–S3)
74.297012
0.223528
261.977808
0.239361
71.681123
0.235262
-0.600638
LD (S1–S4)
61.738434
0.208380
186.719700
0.220593
69.742890
0.234577
-0.817910
CL4 (S1–S3)
94.293321
0.232590
225.443760
0.231024
50.066563
0.223068
-0.710403
CL4 (S1–S4)
108.446353
0.244348
228.854134
0.231342
52.141761
0.225344
-0.613778
Appendix
Table 11: Fitted parameters of the joint scaling law. LD denotes Linear-Decay , and CL4 denotes Constant-Last4 . Training scales are shown in parentheses. Fits on S1–S3 predict S4; fits on S1–S4 predict S5. Parameters are rounded to six decimal places.
Figure 10: Normalized checkpoint-weight profiles on a common 25-position axis, including Last4 , Last8 , Last12 , Last25 , 1-Sqrt , and EMA with β=0.9 . Checkpoints are ordered from oldest to newest.
Figure 11: LAST4 window-spacing ablation on the S5 32K Constant trajectory. (a) LongPPL versus long-context budget. (b) Relative difference from the default Last4(1N) window, computed as 100×(LongPPL−LongPPL1N)/LongPPL1N (%).
Protocol
LongPPL
ShortPPL
Mean
Δ vs 1N
Mean
Δ vs 1N
Constant-Raw
2.284
+0.074
2.082
+0.041
Last4 ( 1N )
2.210
0.000
2.041
0.000
Last4 ( 2N )
2.202
−0.008
2.036
−0.005
Last4 ( 3N )
2.199
−0.011
2.034
−0.007
Last4 ( 4N )
2.200
−0.010
2.033
−0.008
Appendix
Table 12: Mean LongPPL and ShortPPL over the eleven target budgets. Δ is the original-space difference against Last4(1N).
Figure 12: Per-subtask RULER-32K performance along the S5 32K LCCP trajectory. Scores are computed from 500 samples per subtask.
Figure 13: Per-subtask RULER-128K performance after the fixed 128K context-extension stage. The horizontal axis denotes the amount of 32K LCCP completed before context extension. All results use 100 fixed samples per subtask.
Figure 14: Per-task performance after 2.10B tokens of SFT from checkpoints selected along the S5 32K LCCP trajectory for both Constant-Last4 and Constant-Raw . Each point is the mean over three SFT runs trained with different data seeds.
Figure 15: Performance after 4.20B-token SFT from S5 checkpoints at varying 32K LCCP budgets. Individual benchmark scores and their equal-weight average follow the 2.10B-token evaluation protocol. These single-data-seed results serve as a supplementary robustness check.
Figure 16: GAIA and BFCL-WebSearch performance after 4.20B-token agentic SFT along the S5 32K LCCP trajectory. Each point averages three evaluation runs.
Benchmark
Context
Avg
P50
P75
P90
Max
GAIA
final
7,036
6,603
10,470
13,361
31,512
GAIA
peak
12,533
12,749
21,074
21,167
31,512
BFCL-WebSearch
final (peak)
16,259
15,615
22,977
28,900
32,758
τ2 -telecom
final (peak)
10,844
10,543
11,376
12,376
32,766
Appendix
Table 13: Context lengths (tokens) of agentic evaluation trajectories.
Figure 17: Ratio of the log-scale elasticities of LongPPL and ShortPPL along the S5 Constant-Last4 LCCP trajectory. Markers show measurements through ( Dl=120N ). Solid curves show fits over the measured range; dashed curves extend these fits to ( Dl=240N ).
Metric
Training stage
n
Raw
Last4
Δ
32K LongPPL
32K LCCP
24
2.312
2.241
−0.071
RULER-32K
32K LCCP
24
44.29
45.48
+1.19
RULER-128K
128K LCCP
7
39.88
40.48
+0.60
SFT-4-avg (2.10B)
SFT
7
23.91
24.42
+0.51
SFT-4-avg (4.20B)
SFT
7
27.98
27.82
−0.16
Agentic-3-avg (4.20B)
SFT
7
35.21
35.37
+0.15
Appendix
Table 14: Mean performance of Constant-Raw and Constant-Last4 over comparable evaluation points. The training stage identifies where each metric is evaluated. For all rows, Δ=\textscLast4−\textscRaw ; negative values indicate improvement for LongPPL, whereas positive values indicate improvement for other task scores.
Figure 18: Retrieval-head metrics and RULER-32K performance along the S5 Constant-Last4 trajectory. The three square panels show the fixed-head retrieval score, retrieval-head count, and RULER-32K score.
Existing studies on Long-Context Continual Pre-training (LCCP) mainly focus on small-scale models and limited data regimes (tens of billions of tokens). We argue that directly migrating these small-scale settings to industrial-grade models risks insufficient adaptation and premature training termination. Furthermore, current evaluation methods rely heavily on downstream benchmarks (e.g., Needle-in-a-Haystack), which often fail to reflect the intrinsic convergence state and can lead to "deceptive saturation". In this paper, we present the first systematic investigation of LCCP learning dynamics using the industrial-grade Hunyuan-A13B (80B total parameters), tracking its evolution across a 200B-token training trajectory. Specifically, we propose a hierarchical framework to analyze LCCP dynamics across behavioral (supervised fine-tuning probing), probabilistic (perplexity), and mechanistic (attention patterns) levels. Our findings reveal: (1) Necessity of Massive Data Scaling: Training regimes of dozens of billions of tokens are insufficient for industrial-grade LLMs' LCCP (e.g., Hunyuan-A13B reaches saturation after training over 150B tokens). (2) Deceptive Saturation vs. Intrinsic Saturation: Traditional NIAH scores report "fake saturation" early, while our PPL-based analysis reveals continuous intrinsic improvements and correlates more strongly with downstream performance. (3) Mechanistic Monitoring for Training Stability: Retrieval heads act as efficient, low-resource training monitors, as their evolving attention scores reliably track LCCP progress and exhibit high correlation with SFT results. This work provides a comprehensive monitoring framework, evaluation system, and mechanistic interpretation for the LCCP of industrial-grade LLM.
Extending the effective context length of large language models (LLMs) remains a central challenge for real-world applications. While recent post-training methods have made progress in long-context scaling, they either rely on high-quality supervision data or sparse sequence-level rewards, leading to unstable and inefficient optimization. We propose OPSDL, an On-Policy Self-Distillation method for enhancing the Long-context capabilities of LLMs. Unlike other recent self-distillation methods that inject privileged information and rely on the model's in-context learning ability to act as a teacher, OPSDL leverages the model's own inherently strong short-context capability as a self-teacher to supervise its own generation in long-context scenarios. The model first generates responses conditioned on the full long-context, then the self-teacher provides per-token supervision signals via point-wise reverse KL divergence under the relevant extracted short-context. This dense token-level signal encourages faithful use of relevant evidence and mitigates hallucinations induced by irrelevant context. We evaluate OPSDL on long-context benchmarks across a range of models from 7B to 32B parameters. Results show consistent and substantial improvements across varying context lengths, outperforming standard post-training approaches such as SFT and DPO with higher sample efficiency. Notably, these gains are achieved without degrading general short-context performance. These findings highlight the effectiveness of OPSDL as a scalable and stable approach for long-context learning.
Extending the context window of large language models typically requires training on sequences at the target length, incurring quadratic memory and computational costs that make long-context adaptation expensive and difficult to reproduce. We propose EndPrompt, a method that achieves effective context extension using only short training sequences. The core insight is that exposing a model to long-range relative positional distances does not require constructing full-length inputs: we preserve the original short context as an intact first segment and append a brief terminal prompt as a second segment, assigning it positional indices near the target context length. This two-segment construction introduces both local and long-range relative distances within a short physical sequence while maintaining the semantic continuity of the training text--a property absent in chunk-based simulation approaches that split contiguous context. We provide a theoretical analysis grounded in Rotary Position Embedding and the Bernstein inequality, showing that position interpolation induces a rigorous smoothness constraint over the attention function, with shared Transformer parameters further suppressing unstable extrapolation to unobserved intermediate distances. Applied to LLaMA-family models extending the context window from 8K to 64K, EndPrompt achieves an average RULER score of 76.03 and the highest average on LongBench, surpassing LCEG (72.24), LongLoRA (72.95), and full-length fine-tuning (69.23) while requiring substantially less computation. These results demonstrate that long-context generalization can be induced from sparse positional supervision, challenging the prevailing assumption that dense long-sequence training is necessary for reliable context-window extension. The code is available at https://github.com/clx1415926/EndPrompt.
Han Tian, Luxuan Chen, Xinran Chen +10
1Nankai University · 2Baidu Inc. · 3Shanghai Jiao Tong University +1