TL;DR
This paper introduces REval, a novel framework for evaluating the code reasoning capabilities of Large Language Models (LLMs), focusing on their ability to predict runtime program behavior and maintain logical consistency. The study reveals that even state-of-the-art LLMs, including GPT-4, exhibit significant limitations in these areas, highlighting the urgent need for improved code reasoning in AI for software development.
What Problem Does This Paper Address?
Large Language Models (LLMs) are increasingly being used for code-related tasks, but their ability to truly reason about code execution remains a critical, yet underexplored, area. Existing benchmarks often focus on predicting program input/output or code generation correctness, neglecting the crucial intermediate steps of program execution. This gap is problematic because understanding runtime behavior (like execution paths and variable states) is fundamental for debugging, program comprehension, and building reliable AI-powered software tools. Without evaluating these dynamic aspects, we can't fully trust LLMs to assist in complex software engineering tasks.
Methods
The authors propose a new framework called REval to address this gap. REval comprises two main evaluation components:
- Runtime Behavior Reasoning: This component assesses an LLM's ability to predict intermediate program states. It breaks down reasoning into four specific tasks:
- Code Coverage Prediction (CCP): Whether a given statement is executed.
- Program State Prediction (PSP): The value and type of a variable after a statement executes.
- Execution Path Prediction (EPP): Which statement will be executed next.
- Output Prediction (OP): The final output of the program.
- Incremental Consistency Evaluation (IC): This novel metric measures how well an LLM maintains logical consistency across the sequentially related tasks in Runtime Behavior Reasoning. The idea is that if an LLM correctly predicts a statement's execution (CCP), it should then be able to correctly predict the resulting program state (PSP), and so on. Inconsistency arises if an LLM gets a later task right but fails on an earlier, prerequisite task.
REval adapts existing code generation benchmarks (HumanEval and ClassEval) by extracting runtime behavior information and constructing new evaluation problems.
Datasets
The paper utilizes existing code generation benchmarks as the foundation for REval:
- HumanEval: A collection of 164 competitive programming problems for standalone functions.
- ClassEval: A class-level benchmark designed for more complex programming scenarios, including incremental generation and dependencies.
These benchmarks were adapted by extracting runtime behavior data (execution paths, variable states) to create the REval dataset.
Key Insights and Ideas
- Runtime behavior is key: The paper strongly argues that evaluating LLMs on intermediate execution states (beyond just input/output) is essential for a comprehensive understanding of their code reasoning abilities.
- Consistency matters: Logical consistency across sequential reasoning steps is a crucial but often overlooked aspect of LLM evaluation. An LLM that can't maintain consistency is less trustworthy.
- Current LLMs struggle: Despite advancements, most LLMs perform poorly on REval's tasks, indicating a significant gap in their code reasoning capabilities.
- EPP is particularly challenging: Execution Path Prediction (EPP) appears to be the most difficult task among the four Runtime Behavior Reasoning dimensions, while Output Prediction (OP) is relatively easier.
- Code-specific LLMs don't always outperform general LLMs: The study found that specialized code LLMs don't consistently outperform general-purpose LLMs of similar size on these reasoning tasks.
- CoT prompting helps, but not universally: Chain-of-Thought (CoT) prompting showed improvements in some reasoning tasks but could also lead to worse performance in others, suggesting careful prompt design is still critical.
Key Results
- Overall Performance: Most LLMs showed "unsatisfactory performance." The average accuracy across all models for Runtime Behavior Reasoning was 44.4%, and the average Incremental Consistency (IC) score was 10.3.
- Top Performer: GPT-4-Turbo achieved the highest average accuracy (75.0%) for Runtime Behavior Reasoning and the highest IC score (42.5), significantly outperforming other models.
- Open-Source LLMs: The best-performing open-source model, CodeLlama-34B-Instruct, achieved an average accuracy of 51.0%, which is comparable to GPT-3.5-Turbo (55.7%).
- Incremental Consistency: The majority of LLMs scored below 20 on the IC metric, indicating widespread inconsistency. GPT-4-Turbo's IC score of 42.5 was more than double that of the next best model.
- Task Difficulty: Average accuracy for Output Prediction (OP) was high (61.8%), while Execution Path Prediction (EPP) was significantly lower (19.4%).
Limitations and Future Work
- Limitations:
- The manual rule-based selection of statements and variables for evaluation might not perfectly represent all runtime scenarios.
- The evaluation currently focuses on a limited set of dynamic program features (coverage, state, path, output) and may not cover others like memory management or exception handling.
- The study's results are based on a specific set of LLMs and base benchmarks, and may not generalize to all possible models or scenarios.
- Future Work:
- Training with Execution Behavior: The authors suggest that incorporating actual program execution data into LLM training could significantly improve reasoning capabilities.
- Improving Prompting Strategies: Exploring advanced prompting techniques (e.g., Tree-of-Thoughts) tailored for code reasoning and program execution could yield better results.
- Expanding REval: Extending REval to cover more dynamic program features and a wider range of programming scenarios is recommended.
- Investigating Correlation: Further research into the correlation between code generation and code reasoning abilities is needed.
Summary updated