Package: evalplus
EvalPlus(📖) => 📚🔥Quick Start•💻LLM code•🔨Tools•📜Citation•🙏Acknowledgement[!Important]📢 Who is the best LLM coder? Take a look atthe EvalPlus leaderboard 🏆! 📢🤗 Request for independent model evaluation isopen!About[!Warning]🚨 Evaluating LLM-generated code over datasets with "3 test-cases" is **NOT** enough! 🚨To address this, we started the EvalPlus project -- a rigourous evaluation framework for LLM4Code that:✨ improves code benchmarks by adding up to thousands of new tests! (80xforHumanEvaland35xforMBPP!)✨ crafts a setutility toolsto sanitize, visualize and inspect LLM-generated code and evaluation results!✨ accelerates LLM4Code research by open-sourcingLLM-generated samplesfor 20+ models -- no need to re-run the expensive benchmarks!Want to know more details? Please read ourNeurIPS'23 paper!🔥 Quick StartTo get started, please first setup the environment:pipinstallevalplus--upgrade⏬ Install nightly version:: click to expand ::pipinstall"git+https://github.com/evalplus/evalplus.git"--upgrade⏬ Using EvalPlus as a local repo?:: click to expand ::gitclonehttps://github.com/evalplus/evalplus.gitcdevalplusexportPYTHONPATH=$PYTHONPATH:$(pwd)pipinstall-rrequirements.txtCode generationImplement theGEN_SOLUTIONfunction by calling the LLM to produce the complete solution (include the code) and save the samples tosamples.jsonl:fromevalplus.dataimportget_[human_eval|mbpp]_plus,write_jsonlsamples=[dict(task_id=task_id,solution=GEN_SOLUTION(problem["prompt"]))fortask_id,probleminget_[human_eval|mbpp]_plus().items()]write_jsonl("samples.jsonl",samples)🤔 Structure of `problem`?:: click to expand ::task_idis the identifier string for the taskentry_pointis name of the functionpromptis the function signature with docstringcanonical_solutionis the ground-truth implementation (re-implemented to fix bugs in HumanEval)base_inputis the test inputs in original HumanEvalplus_inputis the test inputs brought by EvalPlus[!Note]Expected Schema ofsamples.jsonltask_id: Task ID, which are the keys ofget_[human_eval|mbpp]_plus()solution(optional): Self-contained solution (usually including the prompt)Example:{"task_id": "HumanEval/?", "solution": "def f():\n    return 1"}completion(optional): Function body without promptExample:{"task_id": "HumanEval/?", "completion": "    return 1"}Only one ofsolutionandcompletionis required. If both are provided,solutionwill be used.
We also accept solutions in the form of directory, i.e.,--samples ${SAMPLE_DIR}where${SAMPLE_DIR}is organized as:${SAMPLE_DIR}/${TASK_ID}/{SAMPLE_ID}.py(${TASK_ID} = task_id.replace("/", "_")).Code evaluationYou are strongly recommended to use a sandbox such asdocker:dockerrun-v$(pwd):/appganler/evalplus:latest--dataset[humaneval|mbpp]--samplessamples.jsonl...Or if you want to try it locally regardless of the risks ⚠️:evalplus.evaluate--dataset[humaneval|mbpp]--samplessamples.jsonl[!Warning]Do you use a very slow machine?LLM solutions are regarded asfailedon timeout (and OOM etc.).
Specifically, we set the timeout $T=\max(T_{base}, T_{gt}\times k)$, where:$T_{base}$ is the minimal timeout (configurable by--min-time-limit; default to 0.2s);$T_{gt}$ is the runtime of the ground-truth solutions (achieved via profiling);$k$ is a configurable factor--gt-time-limit-factor(default to 4);If your machine is too slow and you are getting high-variance results, try to use larger $k$ and $T_{base}$.Additionally, you areNOTencouraged to make your test-bed over stressed while running evaluation.
For example, using--parallel 64on a 4-core machine or doing something else during evaluation are bad ideas...🤔 Evaluate with local GitHub repo?:: click to expand ::exportPYTHONPATH=$PYTHONPATH:$(pwd)pythonevalplus/evaluate.py--datasethumaneval--samplessamples.jsonl⌨️ More command-line flags:: click to expand ::--parallel: by default half of the cores--base-only(store_ture): only run base HumanEval tests--i-just-wanna-run: force a re-runThe output should be like (below is GPT-4 greedy decoding example):Computing expected output...
Expected outputs computed in 15.18s
Reading samples...
164it [00:04, 37.79it/s]
Evaluating samples...
100%|██████████████████████████████████████████| 164/164 [00:03<00:00, 44.75it/s]
Base
{'pass@1': 0.8841463414634146}
Base + Extra
{'pass@1': 0.768}Baseis thepass@kfor the original HumanEvalBase + Extrais thepass@kfor the ourHumanEval+(with extra tests)The "k" includes[1, 10, 100]where k values<=the sample size will be usedA cache file named likesamples_eval_results.jsonlwill be cached. Remove it to re-run the evaluation🤔 How long it would take?:: click to expand ::If you do greedy decoding where there is only one sample for each task, the evaluation should take just a few seconds.
When running 200 samples x 164 tasks x ~700+ tests, it can take around 2-10 minute by using--parallel 64and--test-details.
Here are some tips to speed up the evaluation:Use--parallel $(nproc)DoNOTuse--test-detailsif you just want to quickly get pass@k as--test-detailswill run all tests (700+ on average for each task), while without--test-detailsthe testing for a sample stops immediately when it fails the first test.Use our pre-evaluated results (seeLLM-generated code)Use HumanEval+ Mini[!Note]🚀Try outHumanEvalPlus-Mini!which selects aminimalset of additional tests with the highest quality, achieving almost the same effectiveness of the full version. Just add a--miniflag, it can run 23+% faster! (even faster if you evaluate all tests without fail-stop with--test-details).dockerrun-v$(pwd):/appganler/evalplus:latest--datasethumaneval--samplessamples.jsonl--mini# ...Or locally ⚠️# evalplus.evaluate --dataset humaneval --samples samples.jsonl --mini💻 LLM-generated codeWe also share pre-generated code samples from LLMs we haveevaluated:HumanEval+: See the attachment of ourv0.1.0 release.MBPP+: See the attachment of our v0.2.0 release (TBD).Each sample file is packaged in a zip file named like${model_name}_temp_${temperature}.zip.
You can unzip them to a folder named like${model_name}_temp_${temperature}and run the evaluation from scratch with:evalplus.evaluate--datasethumaneval--samples${model_name}_temp_${temperature}🔨 Useful toolsTo use these tools, please first install the repository from GitHub:gitclonehttps://github.com/evalplus/evalplus.gitcdevalplus
pipinstall-rrequirements-tools.txtSyntax checker for LLM-generated codeCheck LLM-produced code and answer the following questions:Is the generation entirely done for all samples / all problems in the dataset?Are LLM-generated code compilable? (if no, something could be wrong and you'd better check)pythontools/checker.py--folder/path/to/[model]-[??]b_temp_[??]--dataset[humaneval|mbpp]Post code sanitizerLLM-generated code may contain some syntax errors.
But some of them can be easily fixable by doing simple post-processing.
This tool will make the LLM-generated code more clean/compilable by doing certain post-processing such as trimming with more magical EOFs and some garbage non-code tokens.pythontools/sanitize.py--eof--folder/path/to/vicuna-[??]b_temp_[??]--dataset[humaneval|mbpp]# Sanitized code will be produced to `/path/to/vicuna-[??]b_temp_[??]-sanitized`Renderpass@kresults torichand LaTeX tablespythontools/render.py--type/path/to/[model]-[??]b# NOTE: no `_temp_[??]`Perform test input generation from scratch (TBD)Name conventionevalplusis the package name.${DATASET}_plusis the name of dataset applied withevalplus.📜 Citation@article{evalplus,title={Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation},author={Jiawei Liu and Chunqiu Steven Xia and Yuyao Wang and Lingming Zhang},journal={arXiv preprint arXiv:2305.01210},year={2023},}🙏 AcknowledgementHumanEvalMBPP