3 Star 1 Fork 0

codefuse-ai / codefuse-evaluation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

CodeFuseEval: 代码大语言模型的多任务评估基准

CodeFuseEval在HumanEval-x、MBPP的基准上,结合CodeFuse大模型多任务场景,开发的编程领域多任务的评测基准, 可用于评估模型在代码补全,自然语言生成代码,测试用例生成、跨语言代码翻译,中文指令生成代码等多类任务的性能。持续开放中,敬请期待!

🌐 English

img

推理环境:

CodeFuse-13B: python 3.8及以上版本,pytorch 2.0及以上版本,transformers 4.24.0及以上版本,CUDA 11.4及以上;

CodeFuse-CodeLlama-34B: python 3.8及以上版本,pytorch2.0及以上版本,transformers==4.32.0 ,Sentencepiece,CUDA 11.4及以上。

处理器:

我们设计了一个名为Processor的基础结构,用户可以自己根据推理模型的情况创建自己需要的处理器, 主要目的是为了处理不同模型的区别情况进行处理,主要需要完成3个抽象函数:

load_model_tokenizer: 由于模型加载参数的区别以及tokenizer的终止符的区别,模型需要使用不同的参数进行适配加载,当前函数主要是为了帮助用户加载适配不同的模型
process_before:由于prompt根据用户不同的选择评测任务的类型或不同模型来适配不同的prompt样式,因此抽取出process_before函数主要用来帮助用户处理prompt
process_after:由于模型生成结果多样性,为了适配评测框架,方便生成结果数据可以拼接成合适的用例进行自动化运行,当前函数主要是根据任务类型和数据集情况,处理生成结果适配评测数据集和结果进行评测

为了支持处理器结构,我们同时修改了ckpt_config保存评测的相关配置。例如:

{
  "CodeFuse-13B": {
    "path": "/mnt/user/294761/bigcode/CodeFuse13B-evol-instruction-4K/", // 模型路径
    "processor_class": "codefuseEval.process.codefuse13b.Codefuse13BProcessor", // 处理器路径 (请把处理器类文件放在codefuseEval/process/下,否则会读取失败)
    "dataset": "humaneval_python", // 评测数据集
    "language": "python",
    "tokenizer": {
      "truncation": true,
      "padding": true,
      "max_length": 600
    },                           // 用于token化prompt的tokenizer参数
    "generation_config": {       // 生成配置,你可以结合下面的「decode_mode」参数设置自己的解码策略,请使用json对象设置不同解码配置,非json对象会直接读取到默认生成配置中
      "greedy": {
        "do_sample": false,
        "num_beams": 1,
        "max_new_tokens": 512
      },
      "beams": {
        "do_sample": false,
        "num_beams": 5,
        "max_new_tokens": 600,
        "num_return_sequences": 1
      },
      "dosample": {
        "do_sample": true
      },
      "temperature": 0.2,
      "max_new_tokens": 600,
      "num_return_sequences": 1,
      "top_p": 0.9,
      "num_beams": 1,
      "do_sample": true
    },
    "task_mode": "code_completion",//目前支持 [code_completion,nl2code,code_trans,codescience] 4种任务类型,如果你评测的数据集支持多个task_mode,建议你设置task_mode来获取合适的任务处理方式
    "batch_size": 1,
    "sample_num": 1,
    "decode_mode": "beams" //解码策略,对应的解码策略的配置会设置到生成配置中
  }

推理命令:

bash codefuseEval/script/generation.sh MODELNAME EVALDATASET OUTFILE LANGUAGE
eg:
bash codefuseEval/script/generation.sh CodeFuse-13B humaneval_python result/test.jsonl python

如果你想进行代码翻译评测,传入的语言参数为当前待翻译的代码语言,例如: 如果你想将C++代码翻译为Python代码,传入代码语言为CPP,如

bash codefuseEval/script/generation.sh CodeFuse-CodeLlama-34B codeTrans_cpp_to_python result/test.jsonl cpp

如何使用CodeFuseEval

评测数据集

样本使用JSON列表格式存储在codefuseEval/data中,根据用户所需的下游任务情况,每条样本包含

  • task_id: 题目的目标语言与ID。语言为["Python", "Java", "JavaScript", "CPP", "Go"]中之一。
  • prompt: 函数声明与描述,用于代码生成。
  • declaration: 仅有函数声明,用于代码翻译。
  • canonical_solution: 手写的示例解答。
  • test: 隐藏测例,用于评测。
  • example_test: 公共测试样本,用于评估生成代码。
  • prompt_text: prompt文本情况。
  • prompt_explain: prompt信息说明。
  • func_title: 生成函数头信息。
  • prompt_text_chinese: 中文prompt信息。

评测执行环境

评测生成的代码需要使用多种语言编译、运行。我们使用的各编程语言依赖及所用包的版本如下:

依赖 版本
Python 3.10.9
JDK 18.0.2.1
Node.js 16.14.0
js-md5 0.7.3
C++ 11
g++ 7.5.0
Boost 1.75.0
OpenSSL 3.0.0
go 1.18.4
cargo 1.71.1

为了省去使用者配置这些语言环境的麻烦,我们构建了一个Docker镜像,并在其中配置了所需要的环境,你可以按照下面的指令拉取使用

docker pull registry.cn-hangzhou.aliyuncs.com/codefuse/codefuseeval:latest

如果您熟悉Dockerfile,也可以从codefuseEval/docker/Dockerfile构建镜像,或者修改之以定制自己的配置:

cd codefuseEval/docker
docker build [OPTIONS] .

获取镜像后,使用如下命令创建容器:

docker run -it --gpus all --mount type=bind,source=<LOCAL PATH>,target=<PATH IN CONTAINER> [OPTIONS] <IMAGE NAME:TAG>

评测指标

除了目前提供的Codex 中提出的无偏 pass@k 指标之外,我们还将huggingface开源的相关指标与CodeBLEU提出的相似性指标进行集成。 目前建议用户主要使用的指标如下:

  • codebleu: codebleu相似性评测指标。
  • pass@k: 无偏pass@k的评测指标。
  • bleu: 文本相似性指标bleu
  • bleurt: 文本语义相似性指标bleurt

其它的相关指标情况用户可以查看metric的使用情况与代码情况进行调整使用。

评测

我们推荐使用给定的评测环境进行评测。在评测前,将生成的代码以如下JSON列表形式存储:

{"task_id": "../..", "generation: "..."}
{"task_id": "../..", "generation: "..."}
...

评测命令:

bash codefuseEval/script/evaluation.sh <RESULT_FILE> <METRIC> <PROBLEM_FILE> <TEST_GROUDTRUTH>
eg: 
bash codefuseEval/script/evaluation.sh codefuseEval/result/test.jsonl pass@k humaneval_python 

并在本仓库的根目录下使用如下指令(请谨慎执行,生成的代码可能有极低概率产生意外行为。在execution.py中查看警告并取消执行代码的注释,风险自负):

同时我们当前提供如下的标志位,可以直接将测试数据集中的示例解答作为生成答案带入进行测试。

  • TEST_GROUDTRUTH 取值为True或False

当TEST_GROUDTRUTH为True时,开启self-test模式,将读取PROBLEM_FILE,将示例解答作为生成答案代入进行测试。 TEST_GROUDTRUTH为False时,开启评测模式,读取RESULT_FILE和将读取PROBLEM_FILE,将生成答案代入进行测试

检查推理结果指令

我们提供脚本来检查所提供代码 LLM 的结果。请使用以下脚本检查相应的推理结果。

bash codefuseEval/script/check_reference.sh codefuseEval/result/CodeFuse-CodeLlama-34B/humaneval_result_python.jsonl humaneval_python
bash codefuseEval/script/check_reference.sh codefuseEval/result/CodeFuse-13B/humaneval_result_python.jsonl humaneval_python 

检查数据集及环境:

代码补全

bash codefuseEval/script/check_dataset.sh humaneval_python

bash codefuseEval/script/check_dataset.sh humaneval_java

bash codefuseEval/script/check_dataset.sh humaneval_js

bash codefuseEval/script/check_dataset.sh humaneval_rust

bash codefuseEval/script/check_dataset.sh humaneval_go

bash codefuseEval/script/check_dataset.sh humaneval_cpp

自然语言生成代码

bash codefuseEval/script/check_dataset.sh mbpp

代码翻译

bash codefuseEval/script/check_dataset.sh codeTrans_python_to_java

bash codefuseEval/script/check_dataset.sh codeTrans_python_to_cpp

bash codefuseEval/script/check_dataset.sh codeTrans_cpp_to_java

bash codefuseEval/script/check_dataset.sh codeTrans_cpp_to_python

bash codefuseEval/script/check_dataset.sh codeTrans_java_to_python

bash codefuseEval/script/check_dataset.sh codeTrans_java_to_cpp

科学计算

bash codefuseEval/script/check_dataset.sh codeCompletion_matplotlib

bash codefuseEval/script/check_dataset.sh codeCompletion_numpy

bash codefuseEval/script/check_dataset.sh codeCompletion_pandas

bash codefuseEval/script/check_dataset.sh codeCompletion_pytorch

bash codefuseEval/script/check_dataset.sh codeCompletion_scipy

bash codefuseEval/script/check_dataset.sh codeCompletion_sklearn

bash codefuseEval/script/check_dataset.sh codeCompletion_tensorflow

bash codefuseEval/script/check_dataset.sh codeInsertion_matplotlib

bash codefuseEval/script/check_dataset.sh codeInsertion_numpy

bash codefuseEval/script/check_dataset.sh codeInsertion_pandas

bash codefuseEval/script/check_dataset.sh codeInsertion_pytorch

bash codefuseEval/script/check_dataset.sh codeInsertion_scipy

bash codefuseEval/script/check_dataset.sh codeInsertion_sklearn

bash codefuseEval/script/check_dataset.sh codeInsertion_tensorflow
Copyright [2023] [Ant Group] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

CodeFuseEval is a Code Generation benchmark that combines the multi-tasking scenarios of CodeFuse Model with the benchmarks of HumanEval-x and MBPP. 展开 收起
Python 等 3 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/codefuse-ai/codefuse-evaluation.git
git@gitee.com:codefuse-ai/codefuse-evaluation.git
codefuse-ai
codefuse-evaluation
codefuse-evaluation
master

搜索帮助