Overlapping Context with Variable-Length Stride Increases Diversity when Training Large Language Model for Code

Geonmo Gu, J.g. Kwak, H. P. Moon, Hyungbo Shim, Yu Jin Kim, Byoungjip Kim, Moontae Lee, Hongyoung Jeon2025

Abstract

Domain-specific fine-tuning of Large Language Models (LLMs) for code often faces severe data scarcity, where traditional multi-epoch training leads to rapid overfitting. This paper introduces a novel approach using overlapping contexts and variable-length strides to increase the diversity of training examples from a fixed dataset. By shifting the "stride" of the context window, we generate unique next-token prediction tasks, significantly improving model performance on coding benchmarks without requiring additional raw data.

Introduction

Adapting open-source LLMs to private, in-house codebases is a common industrial requirement. However, these internal repositories are often small. Standard training involves "packing" code into non-overlapping blocks. When data is limited, researchers typically increase the number of training epochs, but this often results in diminishing returns and memorization after approximately four rounds. This research explores how to squeeze more learning value out of limited tokens by reframing how they are presented to the model.

Methodology: Beyond Standard Packing

The core challenge is to extract more unique learning signals from a limited token pool. The authors propose two primary modifications to the data preparation pipeline.

Overlapping Contexts

In standard packing, the stride (the distance the window moves) equals the context length. By reducing the stride, the model encounters the same tokens but within different local contexts. For instance, a token $t_i$ that was previously at the end of a window might now appear in the middle or beginning. This change in "history" alters the prediction task for the model, effectively creating new training examples from the same raw data.

Variable-Length Stride

A fixed stride can inadvertently merge unrelated files, creating noisy training signals. The proposed variable-length stride mechanism detects end-of-file (EOF) tokens. If a window spans a file boundary, the stride is adjusted to align the next window with the start of the subsequent file. This ensures the model primarily learns from logically coherent, within-file contexts.

Comparison of context windowing strategies: (A) standard non-overlapping packing, (B-C) overlapping with fixed strides, and (D) multiple overlapping windows illustrating increased sample density.

Implementation and Efficiency

To avoid the storage overhead of redundant overlapping text, the researchers implemented a pointer-based system. Only the start indices of the windows are stored, and the actual context is reconstructed dynamically during training. This keeps the storage complexity $O(N)$ while allowing for a massive increase in training examples.

Experimental Results

The method was evaluated using an 8.8B parameter model (EXACODE) on private C/C++ datasets and public Swift code.

  • Benchmark Performance: On the U100 benchmark (100 functions from internal code), the overlapping context model (OC) achieved a 29% pass@1 rate, a significant jump from the 21% baseline.
  • Overcoming the "Epoch Wall": For a CodeLlama-7B model, heavy overlap (stride of 512) reached a 31% pass@1, whereas the standard multi-epoch baseline stalled at 7%, demonstrating that recontextualization is far superior to simple repetition.
  • Diversity Metrics: Mathematical analysis confirmed that even with significant overlap, over 99% of next-token prediction pairs remain unique due to the shifted context windows.

Conclusion

Training Code LLMs on small datasets requires maximizing the utility of every byte. By employing overlapping contexts and variable-length strides, we can simulate a larger, more diverse dataset. While this increases training time, the gains in model generalization and performance on downstream coding tasks make it a highly effective strategy for domain-specific adaptation.

Summary based on "Overlapping Context with Variable-Length Stride Increases Diversity when Training Large Language Model for Code" (ACL 2025).

Summary updated

BibTeX
@misc{gu2025overlapping,
  author = {Geonmo Gu and J.G. Kwak and H. P. Moon and Hyungbo Shim and Yu Jin Kim and Byoungjip Kim and Moontae Lee and Hongyoung Jeon},
  title = {{Overlapping Context with Variable-Length Stride Increases Diversity when Training Large Language Model for Code}},
  year = {2025},
  doi = {10.18653/v1/2025.acl-industry.32},
}
Figure