PanGu-Coder2: Boosting Large Language Models for Code with Ranking Feedback

Bo Shen, Jiaxin Zhang, Taihong Chen, Daoguang Zan, Bing Geng, An Fu, Muhan Zeng, Ailun Yu, Jichuan Ji, Jingyang Zhao, Yuenan Guo, Qianxiang WangarXiv 2023 · DOI

Introduction

The landscape of Large Language Models (LLMs) for code generation is rapidly evolving, yet a significant performance gap remains between open-source models and state-of-the-art commercial systems like GPT-4. While Reinforcement Learning (RL) has been proposed as a solution to bridge this gap, it often suffers from sparse rewards, implementation complexity (e.g., PPO), and computational inefficiency due to frequent unit test execution during the training loop.

To address these challenges, PanGu-Coder2 introduces the RRTF (Rank Responses to align Test & Teacher Feedback) framework. This approach simplifies the alignment process by using ranking-based optimization instead of complex RL algorithms, leading to a 15B parameter model that achieves a state-of-the-art 62.20% pass@1 on the HumanEval benchmark.

The RRTF Framework

The core innovation of PanGu-Coder2 is the RRTF framework, designed to align model outputs with both functional correctness (test feedback) and high-quality coding styles (teacher feedback).

The RRTF framework pipeline: Sampling, Ranking, and Training.

The framework operates in three distinct stages:

  1. Sampling: Using prompts evolved via the Evol-Instruct method, multiple code responses are generated from both the "student" model (PanGu-Coder2) and a more capable "teacher" model.
  2. Ranking: Responses are categorized into four hierarchical levels based on unit test results: Compile Error, Runtime Error, Pass Partial Tests, and Pass All Tests. Crucially, if both the student and teacher pass all tests, the teacher's response is ranked higher to encourage the student to adopt superior coding patterns.
  3. Training: The model is optimized using a dual-loss objective. A Ranking Loss pushes the model toward higher-ranked responses, while a Cross-Entropy Loss (standard supervised fine-tuning) ensures it learns directly from successful teacher examples.

Experimental Results

PanGu-Coder2 was evaluated across several rigorous benchmarks, including HumanEval, CoderEval, and a "leakage-free" LeetCode set. The results demonstrate that RRTF significantly elevates the capabilities of the base StarCoder model.

Performance comparison of PanGu-Coder2 against leading open-source and closed-source models.

As shown in the evaluation table, PanGu-Coder2 (15B) achieves a 61.64% - 62.20% pass@1 on HumanEval, outperforming previous open-source leaders like WizardCoder (57.3%) and even surpassing the reported performance of GPT-3.5 (48.1%). On the LeetCode "Hard" problems, PanGu-Coder2 solved 10 out of 71 tasks, a substantial improvement over StarCoder's 2/71.

Key Insights

  • Teacher as a Tie-Breaker: By ranking teacher responses higher even when both models pass all tests, RRTF forces the student to learn idiomatic and efficient code rather than just functionally correct code.
  • Stability and Efficiency: Unlike PPO-based reinforcement learning, the ranking-based approach is more stable, less sensitive to hyperparameters, and requires only 3-4 epochs to converge.
  • Robustness to Quantization: Interestingly, quantizing the model to int8 using CTranslate2 resulted in a slight performance boost on HumanEval (up to 64.63%), suggesting the model's learned representations are highly robust.

Conclusion

PanGu-Coder2 demonstrates that complex RL is not always necessary to achieve top-tier performance in code generation. By leveraging the RRTF framework to combine unit test feedback with teacher model guidance, the authors have established a new benchmark for open-source Code LLMs, narrowing the gap with proprietary models like GPT-4.

Summary updated

BibTeX
@misc{shen2023pangu,
  author = {Bo Shen and Jiaxin Zhang and Taihong Chen and Daoguang Zan and Bing Geng and An Fu and Muhan Zeng and Ailun Yu and Jichuan Ji and Jingyang Zhao and Yuenan Guo and Qianxiang Wang},
  title = {{PanGu-Coder2: Boosting Large Language Models for Code with Ranking Feedback}},
  year = {2023},
  eprint = {2307.14936},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.14936},
}
Figure