许可证:其他
许可证名称:codegeex4
许可证链接:https://huggingface.co/THUDM/codegeex4-all-9b/blob/main/LICENSE
语言:
- 中文
- 英文
标签:
- glm
- codegeex
- thudm
推理:false
任务标签:文本生成
CodeGeeX4:开源多语言代码生成模型
中文
GitHub
我们推出CodeGeeX4-ALL-9B,这是CodeGeeX4系列模型的最新开源版本。该模型基于GLM-4-9B持续训练,显著提升了代码生成能力。通过单一CodeGeeX4-ALL-9B模型,即可支持代码补全与生成、代码解释器、网络搜索、函数调用、仓库级代码问答等全面功能,覆盖软件开发的各种场景。CodeGeeX4-ALL-9B在BigCodeBench和NaturalCodeBench等公开基准测试中表现出色,是目前参数规模小于100亿的最强代码生成模型,甚至超越了许多更大规模的通用模型,在推理速度与模型性能之间实现了最佳平衡。
快速开始
使用4.39.0<=transformers<=4.40.2
快速启动codegeex4-all-9b:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained("THUDM/codegeex4-all-9b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"THUDM/codegeex4-all-9b",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).to(device).eval()
inputs = tokenizer.apply_chat_template([{"role": "user", "content": "写一个快速排序"}], add_generation_prompt=True, tokenize=True, return_tensors="pt", return_dict=True ).to(device)
with torch.no_grad():
outputs = model.generate(**inputs, max_length=256)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
如需手动构建对话提示,请确保遵循以下格式:
f"<|system|>\n{系统提示}\n<|user|>\n{用户输入}\n<|assistant|>\n"
默认系统提示:
你是一位智能编程助手,你叫CodeGeeX。你会为用户回答关于编程、代码、计算机方面的任何问题,并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。
英文版本:
You are an intelligent programming assistant named CodeGeeX. You will answer any questions users have about programming, coding, and computers, and provide code that is formatted correctly.
对于代码填充能力,请使用(无需系统提示):
f"<|user|>\n<|code_suffix|>{后缀代码}<|code_prefix|>{前缀代码}<|code_middle|><|assistant|>\n"
可添加额外信息(如文件路径、编程语言、模式)。示例:
<|user|>
###路径:src/example.py
###语言:Python
###模式:块状
<|code_suffix|>{后缀代码}<|code_prefix|>{前缀代码}<|code_middle|><|assistant|>
评估结果
模型 |
序列长度 |
HumanEval |
MBPP |
NCB |
LCB |
HumanEvalFIM |
CRUXEval-O |
Llama3-70B-intruct |
8K |
77.4 |
82.3 |
37.0 |
27.4 |
- |
- |
DeepSeek Coder 33B Instruct |
16K |
81.1 |
80.4 |
39.3 |
29.3 |
78.2 |
49.9 |
Codestral-22B |
32K |
81.1 |
78.2 |
46.0 |
35.3 |
91.6 |
51.3 |
CodeGeeX4-All-9B |
128K |
82.3 |
75.7 |
40.4 |
28.5 |
85.0 |
47.1 |
许可证
模型权重遵循以下许可证。
引用
如果您觉得我们的工作有帮助,请随时引用以下论文:
@inproceedings{zheng2023codegeex,
title={CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-X},
author={Qinkai Zheng and Xiao Xia and Xu Zou and Yuxiao Dong and Shan Wang and Yufei Xue and Zihan Wang and Lei Shen and Andi Wang and Yang Li and Teng Su and Zhilin Yang and Jie Tang},
booktitle={Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
pages={5673--5684},
year={2023}
}