YYhnit commited on
Commit
bca2576
·
verified ·
1 Parent(s): 6b66bd1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +142 -176
README.md CHANGED
@@ -1,199 +1,165 @@
1
  ---
2
  license: openrail
3
  pipeline_tag: text-classification
 
 
 
4
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
 
11
 
12
- ## Model Details
 
 
13
 
14
- ### Model Description
 
 
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
 
18
 
 
 
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
 
 
 
29
 
30
- <!-- Provide the basic links for the model. -->
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
 
 
 
 
 
 
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
  license: openrail
3
  pipeline_tag: text-classification
4
+ library_name: flair
5
+ tags:
6
+ - code
7
  ---
8
+ ![](resources/logo.jpeg)
9
+
10
+ <p align="center">
11
+ 🏠 <a href="https://codegeex.cn" target="_blank">Homepage</a>|🛠 Extensions <a href="https://marketplace.visualstudio.com/items?itemName=aminer.codegeex" target="_blank">VS Code</a>, <a href="https://plugins.jetbrains.com/plugin/20587-codegeex" target="_blank">Jetbrains</a>|🤗 <a href="https://huggingface.co/THUDM/codegeex4-all-9b" target="_blank">HF Repo</a> | 🪧 <a href="https://huggingface.co/spaces/THUDM/CodeGeeX" target="_blank">HF DEMO</a>
12
+ </p>
13
+
14
+ [English](./README.md) | [中文](./README_zh.md) | [日本語](./README_ja.md)
15
+
16
+ # CodeGeeX4: 全能的开源多语言代码生成模型
17
+
18
+ 我们推出了 CodeGeeX4-ALL-9B,这是最新的 CodeGeeX4 系列模型的开源版本。该模型是在 [GLM-4-9B](https://github.com/THUDM/GLM-4) 基础上持续训练的多语言代码生成模型,显著提升了代码生成能力。使用单个 CodeGeeX4-ALL-9B 模型,可以支持代码补全与生成、代码解释、联网搜索、函数调用、仓库级代码问答等多种功能,覆盖了软件开发的各个场景。CodeGeeX4-ALL-9B 在 [BigCodeBench](https://huggingface.co/datasets/bigcode/bigcodebench) 和 [NaturalCodeBench](https://github.com/THUDM/NaturalCodeBench) 等公开基准测试中取得了极具竞争力的表现。它是目前参数量少于 100 亿的最强代码生成模型,甚至超越了更大的通用模型,在推理速度和模型性能方面达到了最佳平衡。
19
+
20
+ ## 模型列表
21
+
22
+ | 模型 | 类型 | 上下文长度 | 下载地址 |
23
+ |-------------------|------|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
24
+ | codegeex4-all-9b | Chat | 128K | [🤗 Huggingface](https://huggingface.co/THUDM/codegeex4-all-9b) [🤖 ModelScope](https://modelscope.cn/models/ZhipuAI/codegeex4-all-9b) [🟣 WiseModel](https://wisemodel.cn/models/ZhipuAI/codegeex4-all-9b) |
25
 
26
+ ## 快速开始
27
 
28
+ ### Ollama
29
+ CodeGeeX4 正式上线[Ollama](https://ollama.com/library/codegeex4)!
30
+ 请安装[Ollama 0.2](https://github.com/ollama/ollama/releases/tag/v0.2.0)或更高版本,并运行以下命令:
31
+ ```bash
32
+ ollama run codegeex4
33
+ ```
34
+ 把本地模型接入[VS Code](https://marketplace.visualstudio.com/items?itemName=aminer.codegeex) / [Jetbrains](https://plugins.jetbrains.com/plugin/20587-codegeex)插件,请参考[本地模式教程](./guides/Local_mode_guideline_zh.md).
35
+
36
+ ### Huggingface transformers
37
+ 请使用 `4.39.0<=transformers<=4.40.2` 部署 [codegeex4-all-9b](https://huggingface.co/THUDM/codegeex4-all-9b):
38
+
39
+ ```python
40
+ from transformers import AutoTokenizer, AutoModelForCausalLM
41
+
42
+ device = "cuda" if torch.cuda.is_available() else "cpu"
43
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/codegeex4-all-9b", trust_remote_code=True)
44
+ model = AutoModelForCausalLM.from_pretrained(
45
+ "THUDM/codegeex4-all-9b",
46
+ torch_dtype=torch.bfloat16,
47
+ low_cpu_mem_usage=True,
48
+ trust_remote_code=True
49
+ ).to(device).eval()
50
+ inputs = tokenizer.apply_chat_template([{"role": "user", "content": "write a quick sort"}], add_generation_prompt=True, tokenize=True, return_tensors="pt", return_dict=True).to(device)
51
+ with torch.no_grad():
52
+ outputs = model.generate(**inputs)
53
+ outputs = outputs[:, inputs['input_ids'].shape[1]:]
54
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
55
+ ```
56
 
57
+ ### vLLM
58
+ 使用 `vllm==0.5.1` 快速启动 [codegeex4-all-9b](https://huggingface.co/THUDM/codegeex4-all-9b):
59
 
60
+ ```python
61
+ from transformers import AutoTokenizer
62
+ from vllm import LLM, SamplingParams
63
 
64
+ # CodeGeeX4-ALL-9B
65
+ # max_model_len, tp_size = 1048576, 4
66
+ # 如果出现内存不足(OOM),减少max_model_len,或增加tp_size
67
+ max_model_len, tp_size = 131072, 1
68
+ model_name = "codegeex4-all-9b"
69
+ prompt = [{"role": "user", "content": "Hello"}]
70
 
71
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
72
+ llm = LLM(
73
+ model=model_name,
74
+ tensor_parallel_size=tp_size,
75
+ max_model_len=max_model_len,
76
+ trust_remote_code=True,
77
+ enforce_eager=True,
78
+ # 如果出现OOM,尝试使用以下参数
79
+ # enable_chunked_prefill=True,
80
+ # max_num_batched_tokens=8192
81
+ )
82
+ stop_token_ids = [151329, 151336, 151338]
83
+ sampling_params = SamplingParams(temperature=0.95, max_tokens=1024, stop_token_ids=stop_token_ids)
84
 
85
+ inputs = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
86
+ outputs = llm.generate(prompts=inputs, sampling_params=sampling_params)
87
 
88
+ print(outputs[0].outputs[0].text)
89
+ ```
90
 
91
+ 通过 vllm 设置 OpenAI 兼容服务,详细信息请查看 [OpenAI 兼容服务器](https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html):
 
 
 
 
 
 
92
 
93
+ ```bash
94
+ python -m vllm.entrypoints.openai.api_server \
95
+ --model THUDM/codegeex4-all-9b \
96
+ --trust_remote_code
97
+ ```
98
 
99
+ ### Rust-candle
100
+ Codegeex4现已支持Candle框架 [Repo](https://github.com/huggingface/candle/blob/main/candle-examples/examples/codegeex4-9b/README.org)
101
 
102
+ Use Rust to launch [codegeex4-all-9b](https://huggingface.co/THUDM/codegeex4-all-9b):
103
+ ``` shell
104
+ cd candle_demo
105
+ cargo build -p codegeex4-cli --release --features cuda # for Cuda
106
+ cargo build -p codegeex4-cli --release # for cpu
107
+ ./target/release/codegeex4-cli --sample-len 512
108
+ ```
109
+ ## 用户指南
110
+ 我们为 CodeGeeX4-ALL-9B 提供了用户指南,帮助用户快速了解和使用该模型:
111
 
112
+ ![ALL Fuctions](./resources/all_functions_zh.jpg)
113
 
114
+ 1. **[系统提示指南](./guides/System_prompt_guideline_zh.md)**:本指南介绍了如何在 CodeGeeX4-ALL-9B 中使用系统提示,包括 VSCode 插件的官方系统提示、自定义系统提示以及维护多轮对话历史的一些技巧。
115
 
116
+ 2. **[上下文补全指南](./guides/Infilling_guideline_zh.md)**:本指南解释了 VSCode 插件的官方填充格式,涵盖一般补全、跨文件补全和在仓库中生成新文件。
117
+
118
+ 3. **[项目级代码生成指南](./guides/Repository_tasks_guideline_zh.md)**:本指南展示了如何在 CodeGeeX4-ALL-9B 中使用项目级任务,包括项目级别的问答任务,以及如何触发 CodeGeeX4-ALL-9B 的 aicommiter 功能以执行仓库级别任务中的删除、添加和更改文件操作。
119
+
120
+ 4. **[本地模式指南](./guides/Local_mode_guideline_zh.md)**:本指南展示了如果在本地部署 CodeGeeX4-ALL-9B 并接入 Visual Studio Code / Jetbrains 插件中使用。
121
+
122
+ 这些指南旨在帮助大家全面理解模型的用法并更好发挥模型的能力。
123
+
124
+ ## 评测指标
125
+
126
+ CodeGeeX4-ALL-9B 被评为参数量100 亿内的最强模型,甚至超越了参数量大几倍的通用模型,在推理性能和模型能力之间达到了最佳效果。
127
+
128
+ | **模型** | **序列长度** | **HumanEval** | **MBPP** | **NCB** | **LCB** | **HumanEvalFIM** | **CRUXEval-O** |
129
+ |-----------------------------|----------------|---------------|----------|---------|---------|------------------|----------------|
130
+ | Llama3-70B-intruct | 8K | 77.4 | 82.3 | 37.0 | 27.4 | - | - |
131
+ | DeepSeek Coder 33B Instruct | 16K | 81.1 | 80.4 | 39.3 | 29.3 | 78.2 | 49.9 |
132
+ | Codestral-22B | 32K | 81.1 | 78.2 | 46.0 | 35.3 | 91.6 | 51.3 |
133
+ | CodeGeeX4-All-9B | 128K | 82.3 | 75.7 | 40.4 | 28.5 | 85.0 | 47.1 |
134
+
135
+ 在 BigCodeBench 的 complete 和 instruct 任务中,CodeGeeX4-ALL-9B 分别取得了 `48.9` 和 `40.4` 的高分,这在参数量 200 亿内的模型中是最高的分数。
136
+ ![BigCodeBench Test Results](./metric/pics/Bigcodebench.png)
137
+ Crux-Eval 是测试代码推理、理解和执行能力的基准测试,借助于其强大的 COT 能力,CodeGeeX4-ALL-9B 展现出色的表现。在 HumanEval、MBPP 和 NaturalCodeBench 等代码生成任务中,CodeGeeX4-ALL-9B 也取得了出色的成绩。目前,它是唯一支持 Function Call 功能的代码模型,甚至取得了比 GPT-4 更高的分数。
138
+ ![Function Call Evaluation](./metric/pics/FunctionCall.png)
139
+ 此外,在“Code Needle In A Haystack” (NIAH) 评估中,CodeGeeX4-ALL-9B 模型展示了在 128K 范围内检索代码的能力,在python语言环境达到了 100% 的检索准确率,并在跨文件补全任务中表现出色。
140
+ <p align="center">
141
+ <img src=./metric/pics/NIAH_PYTHON.png alt="图片1描述" width="45%">
142
+ <img src="./metric/pics/NIAH_ALL.png" alt="图片2描述" width="45%">
143
+ </p>
144
+
145
+ 更详细的评估结果请看 **[评估结果](./metric/README_zh.md)** 。
146
+
147
+
148
+ ## 许可证
149
+
150
+ 本仓库中的代码是根据 [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) 许可证开源的。模型权重根据 [模型许可证](MODEL_LICENSE) 许可。CodeGeeX4-9B 权重对学术研究开放。对于希望将模型用于商业目的的用户,请填写 [登记表](https://bigmodel.cn/mla/form?mcode=CodeGeeX4-ALL-9B)。
151
 
 
152
 
153
+ ## 引用
154
 
155
+ 如果您觉得我们的工作对您有帮助,欢迎引用以下论文:
156
 
157
+ ```bibtex
158
+ @inproceedings{zheng2023codegeex,
159
+ title={CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-X},
160
+ 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},
161
+ booktitle={Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
162
+ pages={5673--5684},
163
+ year={2023}
164
+ }
165
+ ```