Introduction
IBM Research has recently expanded the capabilities of the Granite code model family by scaling the context window of its 3B and 8B parameter models from 2K/4K tokens to 128K tokens. This advancement addresses a critical limitation in open-source code models: the "context wall" that prevents them from effectively reasoning over entire software repositories. By enabling a 128K context, these models can now function as more capable coding agents, bridging the gap with proprietary models like GPT-4.
Methodology
The scaling process involved a multi-stage approach designed to extend context without sacrificing performance on standard coding tasks.
RoPE Scaling and Progressive Training
To accommodate longer sequences, the researchers adjusted the base frequency of Rotary Positional Embeddings (RoPE). The models were trained progressively, doubling the context window at each stage (from 8K up to 128K) with 500 training steps per increment.
Repository-Level File Packing
A key innovation is the "repository-level file packing" strategy. Instead of random code snippets, the training data was organized by analyzing repository dependencies using a Directed Acyclic Graph (DAG) and performing a topological sort. This ensures that semantically related files (e.g., a file and its dependencies) appear in close proximity, mimicking a developer's workflow.
Instruction Tuning
To handle long-context instructions, the team generated synthetic multi-turn Q&A pairs using the Granite-8B-Code-Instruct model itself, based on the repository-packed documents.
Evaluation and Results
Long-Context Performance
The impact of scaling is most evident in long-context retrieval tasks. In "needle-in-a-haystack" tests, which measure a model's ability to retrieve specific information buried in a large context, the 128K models demonstrated near-perfect accuracy across the entire window.
On the RepoQA benchmark, the 128K models showed massive improvements. For instance, the 3B model's retrieval accuracy jumped from near 0% to over 60% on 16K context tasks. Similarly, in Long Code Completion (LCC) at 32K context, the 8B model's Exact Match (EM) score increased from 15.0 to 57.4.
Short-Context Stability
A common challenge in context scaling is "catastrophic forgetting," where the model loses its ability to perform well on short-context tasks. IBM mitigated this by mixing short and long data during instruction tuning.
As shown in the evaluation of short-context benchmarks, the Instruct versions of the models often maintained or even improved their performance after being scaled to 128K, while the base models saw only negligible degradation.
Conclusion
The scaling of Granite code models to 128K tokens represents a significant step forward for open-source AI in software engineering. By combining lightweight continual pretraining with semantic file packing, IBM has created models that can navigate complex codebases while remaining highly effective at day-to-day coding tasks. These models are available under the Apache 2.0 license.
Summary updated