codefuse-ai/CodeFuse-CodeGeeX2-6B
421
1---2license: other3license_name: license.md4license_link: LICENSE5---6# Model Card for CodeFuse-CodeGeeX2-6B7<p align="center">8 <img src="https://modelscope.cn/api/v1/models/codefuse-ai/CodeFuse-CodeGeeX2-6B/repo?Revision=master&FilePath=LOGO.jpg&View=true" width="800"/>9<p>10 11[[中文]](#chinese) [[English]](#english)12 13 14<a id="english"></a>15 16## Model Description17 18CodeFuse-CodeGeeX2-6B is a 6B Code-LLM finetuned by LoRA of multiple code tasks on the base model CodeGeeX2. 19 20<br>21 22## News and Updates23 24 🔥🔥 2023-11-10 CodeFuse-CodeGeeX2-6B has been released, achieving a pass@1 (greedy decoding) score of 45.12% on HumanEval, which is a 9.22% increase compared to CodeGeeX2 35.9%.25 26 🔥🔥 2023-10-20 CodeFuse-QWen-14B technical documentation has been released. For those interested, please refer to the CodeFuse article on our WeChat official account via the provided link.(https://mp.weixin.qq.com/s/PCQPkvbvfxSPzsqjOILCDw)27 28 🔥🔥 2023-10-16 CodeFuse-QWen-14B has been released, achieving a pass@1 (greedy decoding) score of 48.78% on HumanEval, which is a 16% increase compared to Qwen-14b's 32.3%.29 30 🔥🔥 2023-09-27 CodeFuse-StarCoder-15B has been released, achieving a pass@1 (greedy decoding) score of 54.9% on HumanEval, which is a 21% increase compared to StarCoder's 33.6%.31 32🔥🔥🔥 2023-09-26 We are pleased to announce the release of the [4-bit quantized version](https://modelscope.cn/models/codefuse-ai/CodeFuse-CodeLlama-34B-4bits/summary) of [CodeFuse-CodeLlama-34B](https://modelscope.cn/models/codefuse-ai/CodeFuse-CodeLlama-34B/summary). Despite the quantization process, the model still achieves a remarkable 73.8% accuracy (greedy decoding) on the HumanEval pass@1 metric.33 34🔥🔥🔥 2023-09-11 [CodeFuse-CodeLlama34B](https://modelscope.cn/models/codefuse-ai/CodeFuse-CodeLlama-34B/summary) has achived 74.4% of pass@1 (greedy decoding) on HumanEval, which is SOTA results for openspurced LLMs at present.35 36<br>37 38## Code Community39 40**Homepage**: 🏡 https://github.com/codefuse-ai (**Please give us your support with a Star🌟 + Fork🚀 + Watch👀**)41 42+ If you wish to fine-tune the model yourself, you can visit ✨[MFTCoder](https://github.com/codefuse-ai/MFTCoder)✨✨43 44+ If you wish to deploy the model yourself, you can visit ✨[FasterTransformer4CodeFuse](https://github.com/codefuse-ai/FasterTransformer4CodeFuse)✨✨45 46+ If you wish to see a demo of the model, you can visit ✨[CodeFuse Demo](https://github.com/codefuse-ai/codefuse)✨✨47 48<br>49 50## Performance51 52 53| Model | HumanEval(pass@1) | Date |54|:----------------------------|:-----------------:|:-------:|55| **CodeFuse-CodeLlama-34B** | **74.4%** | 2023.9 |56|**CodeFuse-CodeLlama-34B-4bits** | **73.8%** | 2023.9 |57| WizardCoder-Python-34B-V1.0 | 73.2% | 2023.8 |58| GPT-4(zero-shot) | 67.0% | 2023.3 |59| PanGu-Coder2 15B | 61.6% | 2023.8 |60| CodeLlama-34b-Python | 53.7% | 2023.8 |61| CodeLlama-34b | 48.8% | 2023.8 |62| GPT-3.5(zero-shot) | 48.1% | 2022.11 |63| OctoCoder | 46.2% | 2023.8 |64| StarCoder-15B | 33.6% | 2023.5 |65| Qwen-14b | 32.3% | 2023.10 |66| **CodeFuse-StarCoder-15B** | **54.9%** | 2023.9 |67| **CodeFuse-QWen-14B** | **48.78%** | 2023.10 |68| **CodeFuse-CodeGeeX2-6B** | **45.12%** | 2023.11 |69 70 71<br>72 73## Requirements74 75* python>=3.8 76* pytorch>=2.0.077* transformers==4.33.278* Sentencepiece79* CUDA 11.480 <br>81 82## Inference String Format83 84The inference string is a concatenated string formed by combining conversation data(system, human and bot contents) in the training data format. It is used as input during the inference process.85Here is an example format of the concatenated string:86 87```python88"""89<s>system90System instruction91<s>human92Human 1st round input93<s>bot94Bot 1st round output<|endoftext|>95<s>human96Human 2nd round input97<s>bot98Bot 2nd round output<|endoftext|>99...100...101...102<s>human103Human nth round input104<s>bot105{Bot output to be genreated}<|endoftext|>106"""107```108 109When applying inference, you always make your input string end with "\<s\>bot" to ask the model generating answers.110 111 112## Quickstart113 114 115```bash116pip install transformers cpm_kernels -U117pip install -r requirements.txt118```119 120```python121import torch122from transformers import (123 AutoTokenizer, 124 AutoModel,125)126tokenizer = AutoTokenizer.from_pretrained('codefuse-ai/CodeFuse-CodeGeeX2-6B', trust_remote_code=True)127tokenizer.padding_side = "left"128# try 4bit loading if cuda memory not enough129model = AutoModel.from_pretrained(model_dir,130 trust_remote_code=True,131 load_in_4bit=False,132 device_map="auto",133 torch_dtype=torch.bfloat16)134model.eval()135 136HUMAN_ROLE_START_TAG = "<s>human\n"137BOT_ROLE_START_TAG = "<s>bot\n"138 139text = f"{HUMAN_ROLE_START_TAG}write a python function of quick sort.\n{BOT_ROLE_START_TAG}" 140inputs = tokenizer(text, return_tensors='pt', padding=True, add_special_tokens=False).to("cuda")141outputs = model.generate(142 inputs=inputs["input_ids"],143 attention_mask=inputs["attention_mask"],144 max_new_tokens=512,145 top_p=0.95,146 temperature=0.1,147 do_sample=True,148 eos_token_id=tokenizer.eos_token_id,149 pad_token_id=tokenizer.pad_token_id150 )151 152gen_text = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)153print(gen_text[0])154```155 156 157 158 159 160 161 162 163<a id="chinese"></a>164 165## 模型简介166 167CodeFuse-CodeGeeX2-6B 是一个通过LoRA对基座模型CodeGeeeX2进行多代码任务微调的代码大模型。168<br>169 170## 新闻171 172 🔥🔥 2023-11-10 开源了CodeFuse-CodeGeeX2-6B模型,在HumanEval pass@1(greedy decoding)上可以达到48.12%, 比CodeGeeX2提高了9.22%的代码能力(HumanEval)173 174 🔥🔥 2023-10-20 公布了CodeFuse-QWen-14B技术文档,感兴趣详见微信公众号CodeFuse文章:https://mp.weixin.qq.com/s/PCQPkvbvfxSPzsqjOILCDw175 176 🔥🔥 2023-10-16开源了CodeFuse-QWen-14B模型,在HumanEval pass@1(greedy decoding)上可以达到48.78%, 比Qwen-14b提高了16%的代码能力(HumanEval)177 178 🔥🔥 2023-09-27开源了CodeFuse-StarCoder-15B模型,在HumanEval pass@1(greedy decoding)上可以达到54.9%, 比StarCoder提高了21%的代码能力(HumanEval)179 180🔥🔥🔥 2023-09-26 [CodeFuse-CodeLlama-34B 4bits](https://modelscope.cn/models/codefuse-ai/CodeFuse-CodeLlama-34B-4bits/summary)量化版本发布,量化后模型在HumanEval pass@1指标为73.8% (贪婪解码)。181 182🔥🔥🔥 2023-09-11 [CodeFuse-CodeLlama-34B](https://modelscope.cn/models/codefuse-ai/CodeFuse-CodeLlama-34B/summary)发布,HumanEval pass@1指标达到74.4% (贪婪解码), 为当前开源SOTA。183 184<br>185 186## 代码社区187**大本营**: 🏡 https://github.com/codefuse-ai (**请支持我们的项目Star🌟 + Fork🚀 + Watch👀**)188 189+ 如果您想自己微调该模型,可以访问 ✨[MFTCoder](https://github.com/codefuse-ai/MFTCoder)✨✨190 191+ 如果您想自己部署该模型,可以访问 ✨[FasterTransformer4CodeFuse](https://github.com/codefuse-ai/FasterTransformer4CodeFuse)✨✨192 193+ 如果您想观看该模型示例,可以访问 ✨[CodeFuse Demo](https://github.com/codefuse-ai/codefuse)✨✨194 195<br>196 197 198## 评测表现199 200### 代码201 202 203| 模型 | HumanEval(pass@1) | 日期 |204|:----------------------------|:-----------------:|:-------:|205| **CodeFuse-CodeLlama-34B** | **74.4%** | 2023.9 |206|**CodeFuse-CodeLlama-34B-4bits** | **73.8%** | 2023.9 |207| WizardCoder-Python-34B-V1.0 | 73.2% | 2023.8 |208| GPT-4(zero-shot) | 67.0% | 2023.3 |209| PanGu-Coder2 15B | 61.6% | 2023.8 |210| CodeLlama-34b-Python | 53.7% | 2023.8 |211| CodeLlama-34b | 48.8% | 2023.8 |212| GPT-3.5(zero-shot) | 48.1% | 2022.11 |213| OctoCoder | 46.2% | 2023.8 |214| StarCoder-15B | 33.6% | 2023.5 |215| Qwen-14b | 32.3% | 2023.10 |216| **CodeFuse-StarCoder-15B** | **54.9%** | 2023.9 |217| **CodeFuse-QWen-14B** | **48.78%** | 2023.8 |218| **CodeFuse-CodeGeeX2-6B** | **45.12%** | 2023.11 |219 220 221## Requirements222 223* python>=3.8 224* pytorch>=2.0.0225* transformers==4.33.2226* Sentencepiece227* CUDA 11.4228<br>229 230## 推理数据格式231 232推理数据为模型在训练数据格式下拼接的字符串形式,它也是推理时输入prompt拼接的方式:233 234```python235"""236<s>system237这是System指令238<s>human239这是第1轮用户输入的问题240<s>bot241这是第1轮模型生成的内容<|endoftext|>242<s>human243这是第2轮用户输入的问题244<s>bot245这是第2轮模型生成的内容<|endoftext|>246...247...248...249<s>human250这是第n轮用户输入的问题251<s>bot252{模型现在要生成的内容}<|endoftext|>253"""254```255 256推理时,请确保拼接的prompt字符串以"\<s\>bot\n"结尾,引导模型生成回答。257 258## 快速使用259 260 261```bash262pip install transformers cpm_kernels -U263pip install -r requirements.txt264```265 266```python267import torch268from transformers import (269 AutoTokenizer, 270 AutoModel,271)272tokenizer = AutoTokenizer.from_pretrained('codefuse-ai/CodeFuse-CodeGeeX2-6B', trust_remote_code=True)273tokenizer.padding_side = "left"274# try 4bit loading if cuda memory not enough275model = AutoModel.from_pretrained(model_dir,276 trust_remote_code=True,277 load_in_4bit=False,278 device_map="auto",279 torch_dtype=torch.bfloat16)280model.eval()281 282HUMAN_ROLE_START_TAG = "<s>human\n"283BOT_ROLE_START_TAG = "<s>bot\n"284 285text = f"{HUMAN_ROLE_START_TAG}write a python function of quick sort.\n{BOT_ROLE_START_TAG}" 286inputs = tokenizer(text, return_tensors='pt', padding=True, add_special_tokens=False).to("cuda")287outputs = model.generate(288 inputs=inputs["input_ids"],289 attention_mask=inputs["attention_mask"],290 max_new_tokens=512,291 top_p=0.95,292 temperature=0.1,293 do_sample=True,294 eos_token_id=tokenizer.eos_token_id,295 pad_token_id=tokenizer.pad_token_id296 )297 298gen_text = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)299print(gen_text[0])300```