arXiv(opens in a new tab)cs.SEJan 2024Cited by 19 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2401.03065

CRUXEval: A Benchmark for Code Reasoning, Understanding and Execution

Alex Gu, Baptiste Rozière, Hugh Leather, Armando Solar-Lezama, Gabriel Synnaeve, Sida I. Wang

Alex Gu ∗^{*}

MIT CSAIL

Baptiste Rozière

Meta AI

Hugh Leather

Meta AI

Armando Solar-Lezama

MIT CSAIL

Gabriel Synnaeve

Meta AI

Sida I. Wang

Meta AI

gua@mit.edu

broz@meta.com

hleather@meta.com

asolar@csail.mit.edu

gab@meta.com

sida@meta.com

Abstract

We present CRUXEval (Code Reasoning, Understanding, and eExecution Evaluation), a benchmark consisting of 800 Python functions (3-13 lines). Each function comes with an input-output pair, leading to two natural tasks: input prediction and output prediction. First, we propose a generic recipe for generating our execution benchmark which can be used to create future variation of the benchmark. Second, we evaluate twenty code models on our benchmark and discover that many recent high-scoring models on HumanEval do not show the same improvements on our benchmark. Third, we show that simple CoT and fine-tuning schemes can improve performance on our benchmark but remain far from solving it. The best setup, GPT-4 with chain of thought (CoT), achieves a pass@1 of 75% and 81% on input and output prediction, respectively. In contrast, Code Llama 34B achieves a pass@1 of 50% and 46% on input and output prediction, highlighting the gap between open and closed source models. As no model is close to acing CRUXEval, we provide examples of consistent GPT-4 failures on simple programs as a lens into its code reasoning capabilities and areas for improvement.

1 Introduction

In recent months, software engineering and programming have become increasingly mainstream domains for language models (LMs) as they attempt to conquer a potpourri of tasks including

  • Work primarily done during an internship at Meta AI

code completion, program repair, debugging, test case generation, and code optimization (see Zan et al. (2023) and Fan et al. (2023) for surveys). Recent models including Code Llama (Roziere et al., 2023), GPT-3.5 (Brown et al., 2020; Ouyang et al., 2022), and GPT-4 (OpenAI, 2023) have shown promise in code-related tasks and are being used to develop tools to help programmers write code more efficiently.

The primary way that the community has been evaluating code LMs is via benchmarks such as HumanEval (Chen et al., 2021) and MBPP (Austin et al., 2021), which test the ability to generate short code snippets from natural language specifications. While HumanEval and MBPP capture code generation abilities on simple and fundamental tasks, there is an absence of benchmarks capturing other fundamental dimensions of code LMs such as code understanding and execution.

Motivated by this, we contribute a new benchmark, CRUXEVAL (Code Reasoning, Understanding, and eXecution Evaluation) with two tasks: 1) output prediction, CRUXEVAL-O to measure code execution following and 2) input prediction, CRUXEVAL-I to measure code reasoning and understanding. An example of a sample in CRUXEVAL is shown in Listings 1 and 2 (modified for readability). CRUXEVAL examines the abilities of code LMs to reason about the execution behaviour of simple Python programs. While LMs shouldn’t be expected to replace an interpreter on arbitrarily complex problems, we ensure the samples in our benchmark are simple (maximum 13 lines, no complex arithmetic) and solvable by a university-level CS graduate without needing more memory (in our opinion). CRUXEVAL provides a useful and important probe for better understanding the capabilities of code LMs, as following a few simple steps of code execution should be a basic requirement for these models. The ability to reason about the execution behavior of code also paves the way to tackling more difficult tasks such as code repair with execution feedback and code summarization.

Listing 1: Sample problem

def f(string): string_x = string.rstrip("a") string = string_x.rstrip("e") return string

References (98)