Turbulence: Systematically and Automatically Testing Instruction-Tuned Large Language Models for Code

Shahin Honarvar, Mark van der Wilk, Alastair F. DonaldsonICST 2023

TL;DR

This paper introduces "Turbulence," a novel benchmark for systematically evaluating the correctness and robustness of instruction-tuned Large Language Models (LLMs) for code generation. By testing LLMs on "neighborhoods" of similar but distinct programming problems, Turbulence reveals subtle reasoning gaps and inconsistencies that traditional benchmarks miss, highlighting LLMs' limitations in generalizing their code-writing abilities.

What Problem Does This Paper Address?

The increasing use of LLMs for code generation, while promising, is hampered by a lack of trust due to concerns about correctness and robustness. Existing evaluation methods often test LLMs on isolated programming problems. However, this doesn't fully capture how well an LLM can generalize its understanding and apply it to slightly varied scenarios. The authors argue that true reasoning capability should extend to solving a range of similar problems, and failures in specific, closely related instances point to deeper issues than just occasional incorrect code. They aim to identify these "discontinuities" in an LLM's ability to solve a neighborhood of problems, offering a more nuanced understanding of their limitations.

Methods

The core innovation is the concept of "question neighborhoods." Instead of single prompts, the authors define "question templates" that are parameterized programming problems. By instantiating these templates with different parameter values, they create a "neighborhood" of related question instances. For each template, an "oracle template" is provided, which includes parameterized unit tests and a model solution to automatically verify the correctness of the LLM's generated code.

The evaluation process involves:

  1. Parameterization: Creating parameterized question templates.
  2. Instantiation: Generating a set of question instances from a template by varying parameters.
  3. LLM Querying: Sending these instances to the LLM multiple times (to account for stochasticity) to generate code solutions.
  4. Automated Verification: Using the instantiated oracle templates (test suites and model solutions) to check the correctness of each generated code snippet.
  5. Scoring: Calculating a "Correctness Score" (CorrSc) for each question template, representing the proportion of correct solutions across all instances and runs.

This approach allows for the identification of "consistent failures," where an LLM consistently fails on specific parameter instantiations within a neighborhood, even if it solves most others.

Datasets

The paper introduces a new benchmark called Turbulence. It comprises:

  • 60 question and oracle templates: Curated from scratch to avoid training data bias, covering fundamental programming concepts and data structures.
  • Parameter sets: Each template is equipped with a parameter set (e.g., 100 parameter valuations) to generate a neighborhood of instances.
  • Automated testing infrastructure: To facilitate the evaluation process.

Turbulence differs from existing benchmarks like HumanEval or APPS by focusing on the neighborhood of problems rather than isolated tasks, specifically aiming to uncover robustness issues and reasoning gaps.

Key Insights and Ideas

  • Neighborhoods reveal subtle reasoning gaps: Traditional benchmarks might show an LLM can solve a problem, but Turbulence can reveal it fails on very similar, slightly modified versions, indicating a lack of true generalization.
  • Consistent failure is a critical indicator: When an LLM consistently fails on specific parameter instantiations within a neighborhood, it points to a deeper reasoning flaw rather than random error.
  • Temperature matters for determinism vs. creativity: Lowering the LLM temperature (towards zero) increases determinism, leading to more consistent successes or failures, while higher temperatures allow for more creative but potentially less reliable outputs.
  • LLMs struggle with robustness to value variations: Even state-of-the-art models show a significant lack of robustness when faced with variations in numerical values or string characters within prompts.
  • Edge cases are important: The benchmark includes deliberately crafted edge cases to test LLMs' ability to handle nuanced instructions, which are becoming more relevant as prompts can be auto-generated.

Key Results

  • GPT-4 outperforms others: GPT-4 consistently achieved the highest Correctness Scores (CorrSc) across the evaluated LLMs.
  • Lack of robustness is widespread: All evaluated LLMs exhibited a lack of robustness, with many question templates falling into the "consistent failure" category. CodeLlama-13 (default temperature) showed the highest count of consistent failures (50 templates), while GPT-4 (default temperature) had the lowest (21 templates).
  • Temperature reduction improves consistency: Lowering the temperature to zero generally reduced the number of "consistent failure" and "random failure" categories for most LLMs (except Command), pushing their performance towards either perfect success or perfect failure.
  • Common error types: The most frequent errors included incorrect ranges, redundant code, incorrect logical order, misunderstanding the question, and missing specific input cases. Syntax errors and runtime errors were also observed.
  • Specific patterns in errors: For certain LLMs, errors were observed with specific parameter values related to indices or number ranges (e.g., bounds being identical, or differences of 1).

Limitations and Future Work

  • Resource constraints: The experiments were limited to 5 runs per instance and 100 parameter settings per template due to computational costs. More extensive testing could provide stronger evidence.
  • LLM-specific findings: The specific results are tied to the evaluated LLMs and might not generalize directly to all LLMs or programming languages. However, the approach is generalizable.
  • Future work: The authors suggest extending Turbulence to other LLMs, programming languages, and code-infilling models. They also propose investigating the impact of quantization on LLM performance. The benchmark's code and templates are publicly available.

Summary updated

BibTeX
@inproceedings{honarvar2023turbulence,
  author = {Shahin Honarvar and Mark van der Wilk and Alastair F. Donaldson},
  title = {{Turbulence: Systematically and Automatically Testing Instruction-Tuned Large Language Models for Code}},
  booktitle = {ICST},
  year = {2023},
}
Figure