Introduction
The rapid advancement of Large Language Models (LLMs) has significantly improved performance on code generation benchmarks like HumanEval and MBPP. However, proficiency in writing code does not necessarily imply a deep understanding of code execution. A robust "AI programmer" must be capable of tracing execution, debugging, and reasoning about how specific inputs are transformed into outputs. To address this, we introduce CRUXEval (Code Reasoning, Understanding, and eXecution Evaluation), a benchmark of 800 simple Python programs designed to evaluate the "mental interpreter" capabilities of LLMs.
Methodology
CRUXEval consists of 800 distinct Python functions, each between 3 and 13 lines long, utilizing common methods from the Python standard library (e.g., str, list, dict). The benchmark was constructed using a "generate-and-filter" pipeline:
- Generation: Code Llama 34B generated candidate functions.
- Filtering: Programs were filtered to ensure they were human-solvable within a minute, removing complex arithmetic or external dependencies.
- Tasks: Models are evaluated on two primary tasks:
- CRUXEval-O (Output Prediction): Predicting the output given a function and an input.
- CRUXEval-I (Input Prediction): Determining the required input to produce a specific output (reverse engineering).
Performance Analysis
We evaluated 20 models on CRUXEval. The results highlight a significant performance gap between proprietary and open-source models, as well as between code generation and code reasoning.
GPT-4, particularly when paired with Chain-of-Thought (CoT) prompting, remains the state-of-the-art, achieving 81.9% on output prediction and 75.0% on input prediction. In contrast, the best open-source model, Code Llama 34B, achieves only 46% and 50% respectively. Notably, input prediction (CRUXEval-I) proved consistently more challenging for nearly all models than output prediction (CRUXEval-O).
Key Insights
The Distillation Mirage
A critical finding is that models distilled from GPT-4, such as WizardCoder or Phind, show substantial improvements on generation benchmarks like HumanEval but fail to show corresponding gains on CRUXEval. This suggests that distillation may improve a model's ability to mimic high-quality code style without enhancing its underlying execution logic.
Scaling and Chain-of-Thought
The impact of model scaling and CoT prompting varies significantly. While CoT is highly beneficial for GPT-4, it can be detrimental to smaller models.
As shown in the figure above, increasing model size (e.g., from Code Llama 13B to 34B) generally improves performance. However, for smaller models, the intermediate reasoning steps in CoT often introduce errors, leading to a net decrease in accuracy.
The Tokenization Trap
Failures in top-tier models like GPT-4 often occur in tasks requiring precise character tracking or string slicing. This suggests that sub-word tokenization may hinder a model's ability to "see" and manipulate individual characters, a prerequisite for accurate code execution tracing.
Conclusion
CRUXEval reveals a substantial "reasoning gap" in current LLMs. High scores in code generation do not guarantee an understanding of code execution. Future work should focus on closing this gap, perhaps through fine-tuning on execution traces or developing architectures that better handle character-level reasoning. Expanding the benchmark to include more complex codebases and diverse programming languages will be essential for developing truly capable AI programmers.
Summary updated