Exploring Continual Learning for Code Generation Models

Prateek Yadav, Qing Sun, Hantian Ding, Xiaopeng Li, Dejiao Zhang, Ming Tan, Parminder Bhatia, Xiaofei Ma, Ramesh Nallapati, Murali Krishna Ramanathan, Mohit Bansal, Bing Xiang

Abstract

Large Language Models (LLMs) for code face significant challenges in dynamic software environments where new languages and frameworks emerge frequently. This paper introduces CODETASK-CL, a comprehensive benchmark for evaluating continual learning (CL) in code generation. We identify a critical failure in standard "Prompt Pooling" methods—unstable prompt selection—and propose Prompt Pooling with Teacher Forcing (PP-TF). Our method improves performance by over 21% by stabilizing the association between tasks and prompts, effectively mitigating catastrophic forgetting without requiring a memory buffer of previous data.

Introduction

Large Language Models (LLMs) specialized for code, such as CodeT5 and Codex, have revolutionized software development. However, these models are often "brittle" when faced with a changing environment. Software development is inherently dynamic: new libraries are released, programming languages evolve, and coding styles shift. Re-training massive models from scratch for every update is computationally prohibitive.

The ideal solution is Continual Learning (CL)—the ability of a model to learn new tasks sequentially while retaining knowledge of previous ones. While CL is well-studied in computer vision and natural language processing, it remains underexplored in the code domain. The authors find that standard CL methods often fail when applied to code due to catastrophic forgetting (CF), where learning a new language or task effectively erases the model's memory of prior knowledge.

The CODETASK-CL Benchmark

To systematically study this problem, the authors introduced the CODETASK-CL benchmark. It sequences four distinct tasks using established datasets to force the model to adapt to different input/output modalities and programming languages:

  1. Code Generation: CONCODE (Natural Language $\rightarrow$ Java)
  2. Code Translation: CodeTrans (Java $\rightarrow$ C#)
  3. Code Summarization: CodeSearchNet (Ruby $\rightarrow$ English)
  4. Code Refinement: BFP (Faulty Java $\rightarrow$ Correct Java)

Methodology: Prompt Pooling with Teacher Forcing

The primary focus of this research is Prompt Pooling (PP). In standard PP, a model maintains a "pool" of learnable prompt vectors. For any input, a query-key mechanism selects the most relevant prompts to prepend to the input. This is typically framed as an Expectation-Maximization (EM) process: selecting the top-k keys based on similarity (E-Step) and optimizing those prompts to minimize task loss (M-Step).

However, the authors identified a fatal flaw: in code tasks, this selection is highly unstable. During training, the model might "hijack" prompts intended for an earlier task to solve a new one, leading to a total collapse of previous performance. To address this, they propose Prompt Pooling with Teacher Forcing (PP-TF).

The PP-TF process: prompts are assigned to tasks during training to ensure stability, then selected via similarity during inference.

As illustrated in the figure above, instead of allowing the model to choose prompts freely during training, PP-TF assigns specific prompts to specific tasks. This "Teacher Forcing" prevents keys from drifting and ensures each task has a stable set of dedicated parameters.

Analysis: The "Key Drift" Phenomenon

Using Principal Component Analysis (PCA), the authors visualized how prompt "keys" move in representation space during training. In standard Prompt Pooling, after the first task (CodeGen), almost all keys cluster around that task's queries. When the second task (CodeTrans) arrives, there are no "free" keys left, forcing the model to overwrite the keys used for Task 1.

PCA plots showing how keys (red crosses) drift and cluster around specific task queries over time, leading to conflicts in standard Prompt Pooling.

The visualization above confirms that the failure of prompting-based CL in code isn't because the prompts lack capacity, but because the selection mechanism is too unconstrained for the sharp distribution shifts found in programming data. Stability in the key-query association is essential for retaining knowledge.

Key Results

Experimental results on the CODETASK-CL benchmark highlight the effectiveness of the proposed approach:

  • Performance Gains: PP-TF achieved an average BLEU score of 44.33, compared to 22.79 for standard Prompt Pooling—a massive 21.54% absolute improvement.
  • Retention: The "Forgetting" metric for PP-TF was a low 1.68, while standard PP suffered a forgetting score of 27.43, confirming that Teacher Forcing successfully stabilized the model's memory.
  • Comparison to Experience Replay (ER): While CodeT5 + ER (which uses a small memory buffer of old examples) remains the strongest baseline at 50.26 BLEU, PP-TF offers a powerful alternative for privacy-sensitive environments where storing user data is forbidden.

Limitations and Future Work

While PP-TF shows great promise, it currently requires knowing the task identity during training to assign prompts. Future research could explore task-agnostic versions of this mechanism. Additionally, while CODETASK-CL is a significant step forward, real-world software evolution involves hundreds of libraries and versions, suggesting a need for even larger-scale longitudinal benchmarks. Finally, exploring how these dynamics scale to multi-billion parameter models like StarCoder or Llama-3 remains a critical next step for the field.

Summary updated

BibTeX
@inproceedings{yadav2023exploring,
  author = {Prateek Yadav and Qing Sun and Hantian Ding and Xiaopeng Li and Dejiao Zhang and Ming Tan and Parminder Bhatia and Xiaofei Ma and Ramesh Nallapati and Murali Krishna Ramanathan and Mohit Bansal and Bing Xiang},
  title = {{Exploring Continual Learning for Code Generation Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-short.68},
}
Figure