Skip to main content
QUICK REVIEW

[Paper Review] An Evaluation of Context Length Extrapolation in Long Code via Positional Embeddings and Efficient Attention

Madhusudan Ghosh, Rishabh Gupta|arXiv (Cornell University)|Feb 25, 2026
Software Engineering ResearchComputer Science0 citations
TL;DR

The paper compares training-free, inference-only methods for long code context extrapolation, evaluating positional encodings (RoPE/ReRoPE) and efficient attention (Paged Attention, Flash Attention, StreamingLLM) on long code completion across Python, Csharp, and Java. It analyzes EM and Edit Sim outcomes to identify strengths and trade-offs for code context extrapolation.

ABSTRACT

The rapid advancement of large language models (LLMs) has led to a significant increase in automated tools in the software engineering, capable of performing various code-related tasks such as code generation, completion, and translation. Despite these advancements, its effectiveness is constrained by fixed context lengths, limiting its ability to generalize across long, domain-specific code sequences. To address this challenge, we investigate zero-shot, inference-only methods aimed at improving position encodings and optimizing attention mechanisms. Our goal is to provide a thorough analysis of current approaches that facilitate context length extrapolation in code, particularly in the context of long code completion tasks.

Motivation & Objective

  • Assess how inference-only methods handle long code sequences in zero-shot code completion tasks.
  • Compare positional encoding based extrapolation with efficient attention mechanisms for long code through empirical evaluation.
  • Identify which approaches preserve syntax and structure in long code contexts across multiple programming languages.

Proposed method

  • Classify context length extrapolation methods into positional encoding based and efficient attention based approaches.
  • Evaluate RoPE, ReRoPE, and several efficient attention techniques (StreamingLLM, Paged Attention, Flash Attention) on long code completion tasks.
  • Use zero-shot inference and greedy decoding to generate 100 tokens on long code sequences.
  • Measure performance with Exact Match (EM) and Edit Similarity (Edit Sim) metrics.
  • Analyze results across Python, Csharp, and Java datasets derived from Guo et al. (2023).
  • Discuss limitations and propose directions for hybrid approaches and new evaluation metrics.
Figure 1. Comparison of length extrapolation techniques for code completion, categorized into Positional Encoding Based (e.g., RoPE, ReRoPE) and Efficient Attention Based methods (e.g., StreamingLLM, Paged Attention, Flash Attention). These approaches address the challenges of handling long code seq
Figure 1. Comparison of length extrapolation techniques for code completion, categorized into Positional Encoding Based (e.g., RoPE, ReRoPE) and Efficient Attention Based methods (e.g., StreamingLLM, Paged Attention, Flash Attention). These approaches address the challenges of handling long code seq

Experimental results

Research questions

  • RQ1RQ-1: How do efficient attention mechanisms impact long code length extrapolation performance across programming languages?
  • RQ2RQ-2: How does positional extrapolation (RoPE, ReRoPE) compare to efficient attention methods for long code extrapolation?
  • RQ3RQ-3: How do language syntax and structure (Python, Csharp, Java) affect zero-shot long code completion performance?

Key findings

  • Efficient attention (Paged Attention) generally achieves higher Exact Match (EM) scores than positional extrapolation methods across languages (e.g., Python EM 0.377 for Paged Attn vs RoPE 0.013).
  • Positional extrapolation methods (especially ReRoPE) yield higher Edit Sim scores and better structural coherence across long code sequences.
  • StreamingLLM and Flash Attention show strong speed gains but struggle with long-context extrapolation in zero-shot code tasks, reflected in lower EM and Edit Sim in some cases.
  • ReRoPE maintains higher Edit Sim consistently across languages, suggesting better preservation of syntactical and hierarchical structure in long code completion.
  • There is a notable gap between EM and Edit Sim performance, highlighting the need for metrics that capture functional correctness and code quality beyond exact token-level matches.
  • Language-specific trends show Python often yielding higher Edit Sim than Java or Csharp, likely due to syntax flexibility vs. rigidity in Java/Csharp.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.