SimSCOOD: Systematic Analysis of Out-of-Distribution Generalization in Fine-tuned Source Code Models

Hossein Hajipour, Ning Yu, Cristian-Alexandru Staicu, Mario Fritz

TL;DR

SimSCOOD introduces a systematic framework to evaluate how fine-tuned source code models handle out-of-distribution (OOD) data across length, syntax, and semantic dimensions. The study reveals that while code LLMs suffer severe performance drops on OOD data due to fine-tuning, Parameter-Efficient Fine-Tuning (PEFT) via LoRA significantly mitigates this fragility compared to full fine-tuning.

What Problem Does This Paper Address?

Pre-trained Large Language Models (LLMs) specialized for code (like CodeT5 and Code Llama) have revolutionized automated software engineering tasks. However, when adapting these models to specific downstream tasks, developers must fine-tune them on specialized datasets. In practice, these fine-tuning datasets are often small and fail to capture the full complexity and distribution of real-world source code.

This mismatch leads to out-of-distribution (OOD) generalization issues. Furthermore, the process of fine-tuning can cause "catastrophic forgetting," where a model loses the broad programming knowledge it gained during its massive pre-training phase. Until now, there has been no systematic approach to simulate and analyze how fine-tuned code models behave when encountering OOD scenarios.

Methods

The authors introduce SimSCOOD, a systematic framework that uses rejection sampling to artificially create OOD scenarios by masking out specific sub-regions of a dataset's distribution.

SimSCOOD workflow: masking sub-regions, fine-tuning, and evaluating on OOD data.

They simulate OOD data across three distinct dimensions of source code:

  1. Length-based: Code is partitioned by token size to evaluate interpolation (handling gaps within known lengths) and extrapolation (handling longer or shorter code than seen during fine-tuning).
  2. Syntax-based: Specific language keywords or grammatical elements (e.g., removing all examples containing an else block or a while statement) are completely masked from the training set.
  3. Semantic-based: Programs are passed through a CodeT5+ encoder to generate continuous representation vectors. These embeddings are clustered using K-means, allowing the authors to mask out entire functional categories (e.g., removing all "property setter" functions).
Figure 2: Overview of different out-of-distribution scenarios. Part of the data that needs to be masked out from the training distribution is highlighted by the red rectangles.

Using these simulated environments, they evaluate four state-of-the-art code models, comparing Full Fine-Tuning (FT) against Low-Rank Adaptation (LoRA). They also analyze a "few-data regime" where a tiny sliver (1.5%) of the masked data is reintroduced to see how quickly models recover.

Datasets

The framework was evaluated using two prominent code generation and intelligence benchmarks from CodeXGLUE:

  • Text-to-Code Generation: Evaluated using the CONCODE dataset, where the model generates source code based on natural language descriptions.
  • Code Refinement (Bug Fixing): Evaluated using the Tufano et al. (2019) medium dataset, where the model attempts to automatically fix bugs in code.

Key Insights and Ideas

  • Catastrophic Forgetting in Code: The paper reveals a striking vulnerability: even if a model observed a keyword like else millions of times during pre-training, fully fine-tuning it on a downstream dataset lacking else causes it to completely forget how to generate that element.
  • LoRA Acts as an OOD Shield: Because LoRA freezes the original pre-trained weights and only updates a tiny fraction (<1%) of newly injected parameters, it effectively preserves the model's foundational knowledge. This architectural constraint allows LoRA to vastly outperform full fine-tuning on OOD data.
  • Syntax and Extrapolation are the Ultimate Hurdles: Syntax-based OOD and length extrapolation proved to be the most challenging scenarios, causing severe degradation in code correctness.
  • The Power of a Tiny Fraction: In the few-data regime, exposing the model to just 1.5% of the missing distribution data yielded massive performance recoveries, demonstrating that complete absence is far more damaging than data scarcity.

Key Results

The authors primarily used the strict Exact Match (EM) metric relative to a 100% baseline (a model trained on the full, unmasked dataset) to evaluate performance:

  • Length Extrapolation Failure: In the text-to-code task, fully fine-tuned CodeT5 dropped to a 0.0% relative exact match when forced to extrapolate to unseen lengths. In contrast, LoRA maintained a 24.99% relative exact match.
  • Syntax-Based Collapse: For the code refinement task, fully fine-tuning GraphCodeBERT (GCBERT) on data missing specific syntax elements resulted in a catastrophic drop to 1.30% relative exact match, while LoRA consistently retained higher generalization capabilities across all models.
Table 2: Overall results of the model performance for different scenarios in code refinement task. The results provide the relative exact match to the 100% baseline (without data mask-out) for dif- ferent OOD and few-data regime scenarios. Length Inter and Length Extra refer to length-based interpolation and extrapolation scenarios, respectively. FT denotes full fine-tuning, and LoRA refers to the LoRA fine-tuning method. OOD and Few refer to OOD and few-data regime scenarios, re- spectively. GCBERT denotes to the GraphCodeBERT model Guo et al. (2021).

Limitations and Future Work

While comprehensive, the study notes a few limitations:

  • Compute Constraints: Due to the immense hardware requirements of fully fine-tuning exceptionally large models, the authors could only evaluate LoRA for the 13-billion-parameter Code Llama model.
  • Semantic Approximation: The semantic-based OOD scenarios rely on embedding space clusters generated by CodeT5+, which serves as an effective proxy but may not perfectly map to exact program semantics.

The authors suggest that future research should leverage these insights to design more robust fine-tuning methodologies and benchmarks explicitly tailored to handle the OOD fragility of code intelligence models.

Summary updated

BibTeX
@inproceedings{hajipour2024simscood,
  author = {Hossein Hajipour and Ning Yu and Cristian-Alexandru Staicu and Mario Fritz},
  title = {{SimSCOOD: Systematic Analysis of Out-of-Distribution Generalization in Fine-tuned Source Code Models}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-naacl.90},
}
Figure