Papers
Topics
Authors
Recent
Gemini 2.5 Flash
Gemini 2.5 Flash
119 tokens/sec
GPT-4o
56 tokens/sec
Gemini 2.5 Pro Pro
43 tokens/sec
o3 Pro
6 tokens/sec
GPT-4.1 Pro
47 tokens/sec
DeepSeek R1 via Azure Pro
28 tokens/sec
2000 character limit reached

Horizon-Length Prediction: Advancing Fill-in-the-Middle Capabilities for Code Generation with Lookahead Planning (2410.03103v1)

Published 4 Oct 2024 in cs.LG, cs.CL, and cs.SE

Abstract: Fill-in-the-Middle (FIM) has become integral to code LLMs, enabling generation of missing code given both left and right contexts. However, the current FIM training paradigm, which reorders original training sequences and then performs regular next-token prediction (NTP), often leads to models struggling to generate content that aligns smoothly with the surrounding context. Crucially, while existing works rely on rule-based post-processing to circumvent this weakness, such methods are not practically usable in open-domain code completion tasks as they depend on restrictive, dataset-specific assumptions (e.g., generating the same number of lines as in the ground truth). Moreover, model performance on FIM tasks deteriorates significantly without these unrealistic assumptions. We hypothesize that NTP alone is insufficient for models to learn effective planning conditioned on the distant right context, a critical factor for successful code infilling. To overcome this, we propose Horizon-Length Prediction (HLP), a novel training objective that teaches models to predict the number of remaining middle tokens (i.e., horizon length) at each step. HLP advances FIM with lookahead planning, enabling models to inherently learn infilling boundaries for arbitrary left and right contexts without relying on dataset-specific post-processing. Our evaluation across different models and sizes shows that HLP significantly improves FIM performance by up to 24% relatively on diverse benchmarks, across file-level and repository-level, and without resorting to unrealistic post-processing methods. Furthermore, the enhanced planning capability gained through HLP boosts model performance on code reasoning. Importantly, HLP only incurs negligible training overhead and no additional inference cost, ensuring its practicality for real-world scenarios.

User Edit Pencil Streamline Icon: https://streamlinehq.com
Authors (6)
  1. Yifeng Ding (22 papers)
  2. Hantian Ding (11 papers)
  3. Shiqi Wang (163 papers)
  4. Qing Sun (44 papers)
  5. Varun Kumar (35 papers)
  6. Zijian Wang (99 papers)

Summary

Horizon-Length Prediction: Advancing Fill-in-the-Middle Capabilities for Code Generation with Lookahead Planning

The paper introduces Horizon-Length Prediction (HLP) as an innovative approach to enhance Fill-in-the-Middle (FIM) capabilities in code LLMs. Traditionally, FIM tasks in code generation have relied on the reordering of code sequences, enabling models to generate missing code portions based on both preceding and succeeding context. However, such models often fall short in aligning their output seamlessly with the provided context, necessitating post-processing methods that depend on dataset-specific assumptions. This paper posits that these traditional approaches inadequately prepare models for effective long-horizon planning.

Methodology and Contributions

The authors propose Horizon-Length Prediction (HLP) as an auxiliary training objective to address these limitations. Unlike conventional next-token prediction (NTP), where the model forecasts the immediate next token, HLP requires models to predict the remaining number of tokens needed to complete the middle section, effectively teaching models to plan for a longer horizon. This lookahead planning empowers models to determine infilling boundaries without relying on restrictive post-processing methods. HLP introduces minimal training overhead and incurs no additional inference costs, making it practical for real-world applications.

Key contributions include:

  • Demonstration that current post-processing methods overestimate FIM performance, obscuring the models' long-horizon planning deficiencies.
  • Introduction of HLP, which enhances infilling capabilities by encouraging models to anticipate future tokens required for completion.
  • Empirical evidence showing that HLP improves model performance by up to 24% on diverse benchmarks without dataset-specific post-processing.

Evaluation and Numerical Results

The evaluation conducted across various model architectures and sizes, such as DeepSeek-Coder and StarCoder2, indicates that incorporating HLP results in substantial improvements in FIM tasks, as measured by diverse benchmarks, including SAFIM and RepoEval. Notably, the addition of HLP achieves up to 24% relative performance improvement across several benchmarks. Furthermore, the enhanced planning capabilities from HLP training also bolster model performance in code reasoning tasks, such as those in CRUXEval, suggesting broadened reasoning capabilities of LMs.

Implications and Future Directions

The findings imply a significant shift in how planning and prediction horizons are approached in code generation tasks, moving beyond narrow next-token predictions to broader context-aware planning mechanisms. This can potentially inform future developments in AI, particularly within domains requiring advanced reasoning and planning.

Speculating on future developments, the integration of horizon-length prediction strategies could extend to other language processing tasks, enhancing long-context understanding and prediction accuracy. Moreover, exploring hybrid models that combine techniques like multitoken prediction or tree search with HLP could offer deeper insights into holistic model improvements.

The paper establishes Horizon-Length Prediction as a pivotal method to address current shortcomings in code infilling. By training models to look ahead and plan with the end goal in sight, HLP sets a foundation for more coherent and contextually aware code generation in machine learning.