CodeShell Technical Report

Rui Xie, Zhengran Zeng, Zhuohao Yu, Chang Gao, Shikun Zhang, Wei YearXiv 2024

Abstract

Code large language models mark a pivotal breakthrough in artificial intelligence. They are specifically crafted to understand and generate programming languages, significantly boosting the efficiency of coding development workflows. In this technical report, we present CodeShell-Base, a seven billion-parameter foundation model with 8K context length, showcasing exceptional proficiency in code comprehension. By incorporating Grouped-Query Attention and Rotary Positional Embedding into GPT-2, CodeShell-Base integrates the structural merits of StarCoder and CodeLlama and forms its unique architectural design. We then carefully built a comprehensive data pre-processing process, including similar data deduplication, perplexity-based data filtering, and model-based data filtering. Through this process, We have curated 100 billion high-quality pre-training data from GitHub. Benefiting from the high-quality data, CodeShell-Base outperforms CodeLlama in Humaneval after training on just 500 billion tokens (5 epochs). We have conducted extensive experiments across multiple language datasets, including Python, Java, and C++, and the results indicate that our model possesses robust foundational capabilities in code comprehension and generation.

Introduction

While Large Language Models (LLMs) have revolutionized coding, most "CodeLLMs" suffer from a "garbage in, garbage out" problem. They are typically trained on massive, uncurated scrapes of GitHub that include buggy, redundant, or poorly documented code. Furthermore, many existing models struggle with limited context lengths and localization issues, particularly in vocabularies optimized for English that fail to efficiently process non-English documentation. CodeShell-Base addresses these challenges through an architecturally efficient design and a sophisticated data-quality pipeline.

Architecture and Tokenization

CodeShell-Base is a 7-billion parameter model that builds on the GPT-2 architecture while incorporating modern enhancements for performance and efficiency:

  • Grouped-Query Attention (GQA): This feature enhances inference speed and reduces memory overhead compared to standard multi-head attention.
  • Rotary Positional Embedding (RoPE): RoPE allows for superior handling of long sequences and facilitates easier context expansion.
  • Staged Context Expansion: The model was initially trained on a 2K context window and expanded to 8K during the final 50 billion tokens of training, optimizing compute resources while maintaining high performance on long-form tasks.

To address localization, the authors expanded the StarCoder vocabulary by adding 40,000 high-frequency Chinese tokens. This significantly improved the compression rate for Chinese text from 1.22 to 1.50, making the model more efficient for developers working in multilingual environments.

Tokenizer efficiency comparison

The Data Quality Pipeline

The core innovation of CodeShell lies in its multi-stage data pre-processing pipeline. The authors curated a 100-billion token dataset from a 15TB crawl of GitHub using three primary layers:

  1. Standard Cleaning: Deduplication (MD5 and MinHash) and language filtering.
  2. Rule-Based Filtering: Analysis of Abstract Syntax Trees (AST) to ensure logical complexity and adherence to coding standards.
  3. Learning-Based Filtering: The "secret sauce" involves using GPT-4 to score a subset of code for correctness and readability. A BERT-based model was then trained on these scores to act as a high-speed quality judge for the full 100 billion tokens.

This rigorous filtering ensures that the model learns from "gold-standard" code rather than average-quality scrapes.

Ablation study: Random vs. Filtered data

Key Results and Insights

CodeShell-Base demonstrates that data quality can outweigh raw volume. Despite being trained on significantly fewer unique tokens than some competitors, it achieves superior results on major benchmarks:

  • HumanEval (Zero-shot): CodeShell-7B scored 34.3%, significantly surpassing CodeLlama-7B (10.5%) and StarCoderBase-15B (30.4%).
  • Multilingual Performance: The model achieved top-tier results in mainstream languages like JavaScript, Java, and PHP on the MultiPL-E benchmark.
  • Code Completion: In "Fill-In-the-Middle" (FIM) tasks, CodeShell-7B outperformed both StarCoder and CodeLlama with a mean score of 74.3% across Python, Java, and JavaScript.

An ablation study confirmed the impact of the filtering pipeline: a model trained on filtered high-quality data showed a 100% performance improvement over a model trained on a random sample of the same size.

Conclusion

CodeShell-Base represents a significant step forward in open-source CodeLLMs. By prioritizing high-quality, curated data and efficient architectural choices like GQA and expanded tokenization, it achieves state-of-the-art performance with a relatively modest parameter count. Future work will focus on refining data selection for complex, multi-file logical tasks and further expanding the model's reasoning capabilities in niche programming languages.

Summary updated

BibTeX
@misc{xie2024codeshell,
  author = {Rui Xie and Zhengran Zeng and Zhuohao Yu and Chang Gao and Shikun Zhang and Wei Ye},
  title = {{CodeShell Technical Report}},
  year = {2024},
  eprint = {2403.15747},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.15747},
}
Figure