Jintao Huang commited on
Commit
d38f5d1
1 Parent(s): bd5b613

first commit

Browse files
.gitattributes CHANGED
@@ -1,35 +1,34 @@
1
  *.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
 
4
  *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
  *.ftz filter=lfs diff=lfs merge=lfs -text
7
  *.gz filter=lfs diff=lfs merge=lfs -text
8
  *.h5 filter=lfs diff=lfs merge=lfs -text
9
  *.joblib filter=lfs diff=lfs merge=lfs -text
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
  *.model filter=lfs diff=lfs merge=lfs -text
13
  *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
  *.onnx filter=lfs diff=lfs merge=lfs -text
17
  *.ot filter=lfs diff=lfs merge=lfs -text
18
  *.parquet filter=lfs diff=lfs merge=lfs -text
19
  *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
  *.pt filter=lfs diff=lfs merge=lfs -text
23
  *.pth filter=lfs diff=lfs merge=lfs -text
24
  *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
  *.xz filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
1
  *.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
  *.bz2 filter=lfs diff=lfs merge=lfs -text
 
6
  *.ftz filter=lfs diff=lfs merge=lfs -text
7
  *.gz filter=lfs diff=lfs merge=lfs -text
8
  *.h5 filter=lfs diff=lfs merge=lfs -text
9
  *.joblib filter=lfs diff=lfs merge=lfs -text
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
 
11
  *.model filter=lfs diff=lfs merge=lfs -text
12
  *.msgpack filter=lfs diff=lfs merge=lfs -text
 
 
13
  *.onnx filter=lfs diff=lfs merge=lfs -text
14
  *.ot filter=lfs diff=lfs merge=lfs -text
15
  *.parquet filter=lfs diff=lfs merge=lfs -text
16
  *.pb filter=lfs diff=lfs merge=lfs -text
 
 
17
  *.pt filter=lfs diff=lfs merge=lfs -text
18
  *.pth filter=lfs diff=lfs merge=lfs -text
19
  *.rar filter=lfs diff=lfs merge=lfs -text
 
20
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
  *.tar.* filter=lfs diff=lfs merge=lfs -text
 
22
  *.tflite filter=lfs diff=lfs merge=lfs -text
23
  *.tgz filter=lfs diff=lfs merge=lfs -text
 
24
  *.xz filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *.tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ *.db* filter=lfs diff=lfs merge=lfs -text
29
+ *.ark* filter=lfs diff=lfs merge=lfs -text
30
+ **/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
31
+ **/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
32
+ **/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
33
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
34
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
LOGO.png ADDED
MODEL_LICENSE.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CodeFuse COMMUNITY LICENSE AGREEMENT
2
+ CodeFuse Release Date: September 8, 2023
3
+
4
+ By clicking to agree or by using or distributing any portion or element of the Materials, you will be deemed to have recognized and accepted the content of this Agreement, which is effective immediately.
5
+
6
+ 1. Definitions.
7
+ a. This CodeFuse COMMUNITY LICENSE AGREEMENT (this "Agreement") shall mean the terms and conditions for use, reproduction, distribution and modification of the Materials as defined by this Agreement.
8
+ b. "Ant" or "We" (or "Us") shall mean Ant Group.
9
+ c. "CodeFuse" shall mean the large language models (including CodeFuse-13B and CodeFuse-CodeLlaMa-34B), and software and algorithms, consisting of trained model weights, parameters (including optimizer states), machine-learning model code, and other elements of the foregoing distributed by Us.
10
+ d. "Documentation" shall mean the specifications, manuals and documentation accompanying CodeFuse distributed by Us.
11
+ e. "Materials" shall mean, collectively, Ant's proprietary CodeFuse and Documentation (and any portion thereof) made available under this Agreement.
12
+ f. "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.
13
+ g. "Source" form shall mean the preferred form for making modifications, including but not limited to model source code, documentation source, and configuration files.
14
+ h. "Third Parties" (or "Third Party") shall mean individuals or legal entities that are not controlling, controlled by Us or You, or under common control with Us or You.
15
+ i. "You" (or "Your") shall mean a natural person or legal entity exercising the rights granted by this Agreement and/or using the Materials for any purpose and in any field of use.
16
+
17
+ 2. Grant of Rights.
18
+ You are granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Ant's intellectual property or other rights owned by Ant embodied in the Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the Materials.
19
+
20
+ 3. Redistribution.
21
+ You may distribute or make the Materials or derivative works thereof available to a Third Party in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
22
+ a. You shall provide a copy of this Agreement to such Third Party;
23
+ b. if You modify the CodeFuse model, You shall provide a prominent notice, stating how You have modified the CodeFuse model, to such Third Party; and
24
+ c. You shall retain in all copies of the Materials that You distribute the following attribution notices within a "Notice" text file distributed as a part of such copies: "CodeFuse is licensed under the CodeFuse COMMUNITY LICENSE AGREEMENT, Copyright (c) Ant Group. All Rights Reserved."
25
+ 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 terms and conditions of this Agreement.
26
+
27
+ 4. Rules of Use.
28
+ You shall comply with applicable laws and regulations (including without limitation export controls or restrictions) in Your use of the Materials.
29
+
30
+ 5. Intellectual Property.
31
+ a. Ant retains ownership of all intellectual property rights in and to the Materials and derivatives made by or for Ant. Conditioned upon compliance with the terms and conditions of this Agreement, with respect to any derivative works and modifications of the Materials that are made by You, You are and will be the owner of such derivative works and modifications.
32
+ b. No trademark license is granted to use the trade names, trademarks, service marks, or product names of Ant, except as required to fulfill notice requirements under this Agreement or as required for reasonable and customary use in describing and redistributing the Materials.
33
+ c. If You commence a lawsuit or other proceedings (including a cross-claim or counterclaim in a lawsuit) against Ant or any entity alleging that the Materials or any output therefrom, or any part of the foregoing, infringe any intellectual property or other right owned or licensable by You, then all licences granted to You under this Agreement shall terminate as of the date such lawsuit or other proceeding is commenced or brought.
34
+
35
+ 6. Disclaimer of Warranty and Limitation of Liability.
36
+ a. Ant is not obligated to support, update, provide training for, or develop any further version of the Materials or to grant any license thereto.
37
+ b. THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. WE MAKE NO WARRANTY AND ASSUME NO RESPONSIBILITY FOR THE SAFETY OR STABILITY OF THE MATERIALS AND ANY OUTPUT THEREFROM.
38
+ c. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE MATERIALS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE MATERIALS AND ANY OUTPUT AND RESULTS. IN NO EVENT SHALL WE BE LIABLE TO YOU FOR ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT OR ARISING FROM YOUR USE OR INABILITY TO USE THE MATERIALS OR ANY OUTPUT OF IT, FOR ANY DIRECT, OR INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, NO MATTER HOW IT'S CAUSED OR EVEN IF ANT OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
39
+ d. You will defend, indemnify and hold harmless Ant from and against any claim by any Third Party arising out of or related to Your use or distribution of the Materials.
40
+
41
+ 7. Survival and Termination.
42
+ a. The term of this Agreement shall commence upon Your acceptance of this Agreement or access to the Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein.
43
+ b. We may terminate this Agreement if You breach any of the terms or conditions of this Agreement. Upon termination of this Agreement, You must delete and cease use of the Materials. Sections 6 and 8 shall survive the termination of this Agreement.
44
+
45
+ 8. Governing Law and Jurisdiction.
46
+ a. This Agreement and any dispute arising out of or relating to it, whether in contract, tort, negligence, products liability, or otherwise, will be governed by the laws of China, without regard to conflict of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement.
47
+ b. The People's Courts in Hangzhou City shall have exclusive jurisdiction over any dispute arising out of this Agreement.
README.md CHANGED
@@ -1,3 +1,405 @@
1
  ---
 
 
2
  license: other
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ frameworks:
3
+ - Pytorch
4
  license: other
5
+ tasks:
6
+ - text-generation
7
  ---
8
+
9
+ # Model Card for CodeFuse-CodeLlama-34B-4bits
10
+ <p align="left">
11
+ <img src="./LOGO.png" width="100%" />
12
+ </p>
13
+
14
+ [[中文]](#chinese) [[English]](#english)
15
+
16
+
17
+
18
+ <a id="english"></a>
19
+
20
+ ## Model Description
21
+
22
+ CodeFuse-CodeLlama-34B-4bits is the 4-bit quantized version of CodeFuse-CodeLlama-34B, which is a 34B Code-LLM fine-tuned over multiple code tasks(600k instrunctions/answers)on the base model CodeLlama-34b-Python.
23
+
24
+ After undergoing 4-bit quantization, the CodeFuse-CodeLlama-34B-4bits model can be loaded on either a single A10 (24GB VRAM) or a RTX 4090 (24GB VRAM). Moreover, the quantized model still achives an impressive accuracy of 73.8% on the Humaneval pass@1 metric.
25
+
26
+
27
+ <br>
28
+
29
+ ## News and Updates
30
+
31
+
32
+ 🔥🔥🔥 2023-09-26 We are pleased to announce the release of the 4-bit quantized version of CodeFuse-CodeLlama-34B. 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 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 Community
39
+
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
+ ## Performance
51
+
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
+ | LLaMA 2 70B(zero-shot) | 29.9% | 2023.7 |
66
+
67
+ <br>
68
+
69
+ ## GPU Memory Usage
70
+ We measured the GPU memory usage after loading the model, as well as the memory usage when encoding 2048/1024 tokens and generating 1024/2048 tokens. The results are presented in the table below.
71
+
72
+ | Precision | Idle Model | Encoding 2048 tokens and Generating 1024 tokens | Encoding 1024 tokens and Generating 2048 tokens |
73
+ |:--------------------------------|:-------------------|:------------------------:|:------------:|
74
+ |bfloat16 | 64.89GB | 69.31GB | 66.41GB |
75
+ |int4 | 19.09GB | 22.19GB | 20.78GB |
76
+
77
+ <br>
78
+
79
+ ## Requirements
80
+
81
+ * python>=3.8
82
+ * pytorch>=2.0.0
83
+ * transformers==4.32.0
84
+ * auto_gptq==0.4.2
85
+ * Sentencepiece
86
+ * CUDA 11.4
87
+
88
+ <br>
89
+
90
+ ## Inference String Format
91
+
92
+ The inference string is a concatenated string formed by combining conversation data (human and bot contents) in the training data format. It is used as input during the inference process.
93
+ Here is an example format of the concatenated string:
94
+
95
+ ```python
96
+ """
97
+ <|role_start|>human<|role_end|>Human 1st round input
98
+ <|role_start|>bot<|role_end|>Bot 1st round output</s>
99
+ <|role_start|>human<|role_end|>Human 2nd round input
100
+ <|role_start|>bot<|role_end|>Bot 2nd round output</s>
101
+ ...
102
+ ...
103
+ ...
104
+ <|role_start|>human<|role_end|>Human nth round input
105
+ <|role_start|>bot<|role_end|>{Bot output to be genreated}</s>
106
+ """
107
+ ```
108
+
109
+ When applying inference, you always make your input string end with "<|role_start|>bot<|role_end|>" to ask the model generating answers.
110
+
111
+ <br>
112
+
113
+ ## Quickstart
114
+
115
+ ```bash
116
+ git clone https://www.modelscope.cn/codefuse-ai/CodeFuse-CodeLlama-34B-4bits.git
117
+ ```
118
+
119
+ ```bash
120
+ pip install -r requirements.txt
121
+ ```
122
+
123
+ ```python
124
+ import os
125
+ import torch
126
+ import time
127
+ from modelscope import AutoTokenizer, snapshot_download
128
+ from auto_gptq import AutoGPTQForCausalLM
129
+
130
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
131
+
132
+ def load_model_tokenizer(model_path):
133
+ """
134
+ Load model and tokenizer based on the given model name or local path of downloaded model.
135
+ """
136
+ tokenizer = AutoTokenizer.from_pretrained(model_path,
137
+ trust_remote_code=True,
138
+ use_fast=False,
139
+ lagecy=False)
140
+ tokenizer.padding_side = "left"
141
+ tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("<unk>")
142
+ tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids("</s>")
143
+
144
+ model = AutoGPTQForCausalLM.from_quantized(model_path,
145
+ inject_fused_attention=False,
146
+ inject_fused_mlp=False,
147
+ use_cuda_fp16=True,
148
+ disable_exllama=False,
149
+ device_map='auto' # Support multi-gpus
150
+ )
151
+ return model, tokenizer
152
+
153
+
154
+ def inference(model, tokenizer, prompt):
155
+ """
156
+ Uset the given model and tokenizer to generate an answer for the speicifed prompt.
157
+ """
158
+ st = time.time()
159
+ prompt = prompt if prompt.endswith('\n') else f'{prompt}\n'
160
+ inputs = f"<|role_start|>human<|role_end|>{prompt}<|role_start|>bot<|role_end|>"
161
+
162
+ input_ids = tokenizer.encode(inputs,
163
+ return_tensors="pt",
164
+ padding=True,
165
+ add_special_tokens=False).to("cuda")
166
+ with torch.no_grad():
167
+ generated_ids = model.generate(
168
+ input_ids=input_ids,
169
+ top_p=0.95,
170
+ temperature=0.1,
171
+ do_sample=True,
172
+ max_new_tokens=512,
173
+ eos_token_id=tokenizer.eos_token_id,
174
+ pad_token_id=tokenizer.pad_token_id
175
+ )
176
+ print(f'generated tokens num is {len(generated_ids[0][input_ids.size(1):])}')
177
+ outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
178
+ print(f'generate text is {outputs[0][len(inputs): ]}')
179
+ latency = time.time() - st
180
+ print('latency is {} seconds'.format(latency))
181
+
182
+
183
+ if __name__ == "__main__":
184
+ model_dir = snapshot_download('codefuse-ai/CodeFuse-CodeLlama-34B-4bits', revision='v1.0.0')
185
+
186
+ prompt = 'Please write a QuickSort program in Python'
187
+
188
+ model, tokenizer = load_model_tokenizer(model_dir)
189
+ inference(model, tokenizer, prompt)
190
+ ```
191
+
192
+ **The current inference example code is based on [AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ). If you want to achieve higher inference speed, it is recommended to combine it with [TensorRT-LLM (Early Access)](https://developer.nvidia.com/tensorrt-llm-early-access).**
193
+
194
+ <br>
195
+
196
+ ## Consistency Check
197
+ Here, SHA256 values are provided for the model-related files for consistency check during the download.
198
+
199
+ | File | SHA256 |
200
+ |-------------------------------:|:--------------------------------:|
201
+ |config.json | bd1b92f942549f76d7e02e65fd346b39903943912d6d6a2ff8ff345e43e1115b |
202
+ |generation_config.json | b625bd13a52d0685313c32919324b9bdc9e75a4f1338ca5c28226d1693e130a3 |
203
+ |gptq_model-4bit-64g.bin | 79441bad1d5ab852d0238ed7e113b9912f31189cf9181d7119dd297c4beb454a |
204
+ |pytorch_model.bin.index.json | 9a714170172282cfbcaa120af13c0df08b06d040ff24dab30229d8a010821d3d |
205
+ |quantize_config.json | 3c1744a928e9d6c3f9a2cbb1bb5a89539077e7d456948bf5aee0deed6a7b8028 |
206
+ |special_tokens_map.json | ff3b4a612c4e447acb02d40071bddd989fe0da87eb5b7fe0dbadfc4f74de7531 |
207
+ |tokenizer.json | f7b50bcf6d6672eade5e43514d48e9c1e4e63a56aef7b14acdaca94ce93436f7 |
208
+ |tokenizer.model | 9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 |
209
+ |tokenizer_config.json | c12441e82f2dce0baff87cf5948e82d6e9b51cc0b5266369c30c319fb771eeb2 |
210
+
211
+
212
+ <br>
213
+ <br>
214
+
215
+
216
+ <a id="chinese"></a>
217
+
218
+ ## 模型简介
219
+
220
+ CodeFuse-CodeLlama-34B-4bits是CodeFuse-CodeLlama-34B模型的4bits量化版本,后者是通过QLoRA对基座模型CodeLlama-34b-Python进行多代码任务微调而得到的代码大模型,模型输入长度为4K。
221
+
222
+ 经4bits量化后,CodeFuse-CodeLlama-34B-4bits可用单张A10 (24GB显存)或者RTX 4090 (24GB显存)加载,同时,量化后的模型在Humaneval pass@1指标上仍取得了73.8%的表现。
223
+
224
+ <br>
225
+
226
+ ## 新闻
227
+
228
+ 🔥🔥🔥 2023-09-26 CodeFuse-CodeLlama-34B 4bits量化版本发布,量化后模型在HumanEval pass@1指标为73.8% (贪婪解码)。
229
+
230
+ 🔥🔥🔥 2023-09-11 CodeFuse-CodeLlama-34B发布,HumanEval pass@1指标达到74.4% (贪婪解码), 为当前开源SOTA。
231
+
232
+ <br>
233
+
234
+ ## 代码社区
235
+ **大本营**: 🏡 https://github.com/codefuse-ai (**请支持我们的项目Star🌟 + Fork🚀 + Watch👀**)
236
+
237
+ + 如果您想自己微调该模型,可以访问 ✨[MFTCoder](https://github.com/codefuse-ai/MFTCoder)✨✨
238
+
239
+ + 如果您想自己部署该模型,可以访问 ✨[FasterTransformer4CodeFuse](https://github.com/codefuse-ai/FasterTransformer4CodeFuse)✨✨
240
+
241
+ + 如果您想观看该模型示例,可以访问 ✨[CodeFuse Demo](https://github.com/codefuse-ai/codefuse)✨✨
242
+
243
+ <br>
244
+
245
+ ## 评测表现(代码)
246
+
247
+
248
+ | 模型 | HumanEval(pass@1) | 日期 |
249
+ |:--------------------------------|:-----------------:|:-------:|
250
+ | **CodeFuse-CodeLlama-34B** | **74.4%** | 2023.9 |
251
+ |**CodeFuse-CodeLlama-34B-4bits** | **73.8%** | 2023.9 |
252
+ | WizardCoder-Python-34B-V1.0 | 73.2% | 2023.8 |
253
+ | GPT-4(zero-shot) | 67.0% | 2023.3 |
254
+ | PanGu-Coder2 15B | 61.6% | 2023.8 |
255
+ | CodeLlama-34b-Python | 53.7% | 2023.8 |
256
+ | CodeLlama-34b | 48.8% | 2023.8 |
257
+ | GPT-3.5(zero-shot) | 48.1% | 2022.11 |
258
+ | OctoCoder | 46.2% | 2023.8 |
259
+ | StarCoder-15B | 33.6% | 2023.5 |
260
+ | LLaMA 2 70B(zero-shot) | 29.9% | 2023.7 |
261
+ <br>
262
+
263
+ ## 显存使用
264
+ 我们测量了模型加载后占用的显存占用情况,以及输入2048/1024 tokens并输出1024/2048 tokens时的显存使用情况,如下表所示
265
+
266
+ | 精度 | 模型空载 | 输入2048 tokens + 输出1024 tokens | 输入1024 tokens + 输出2048 tokens |
267
+ |:--------------------------------|:-------------------|:------------------------:|:------------:|
268
+ |bfloat16 | 64.89GB | 69.31GB | 66.41GB |
269
+ |int4 | 19.09GB | 22.19GB | 20.78GB |
270
+
271
+ <br>
272
+
273
+ ## 依赖要求
274
+
275
+ * python>=3.8
276
+ * pytorch>=2.0.0
277
+ * transformers==4.32.0
278
+ * auto_gptq==0.4.2
279
+ * Sentencepiece
280
+ * CUDA 11.4
281
+
282
+ <br>
283
+
284
+ ## 推理数据格式
285
+
286
+ 推理数据为模型在训练数据格式下拼接的字符串形式,它也是推理时输入prompt拼接的方式:
287
+
288
+ ```python
289
+ """
290
+ <|role_start|>human<|role_end|>Human 1st round input
291
+ <|role_start|>bot<|role_end|>Bot 1st round output</s>
292
+ <|role_start|>human<|role_end|>Human 2nd round input
293
+ <|role_start|>bot<|role_end|>Bot 2nd round output</s>
294
+ ...
295
+ ...
296
+ ...
297
+ <|end|><|role_start|>human<|role_end|>Human nth round input
298
+ <|end|><|role_start|>bot<|role_end|>{Bot output to be genreated}</s>
299
+ """
300
+ ```
301
+
302
+ 推理时,请确保拼接的prompt字符串以"<|role_start|>bot<|role_end|>"结尾,引导模型生成回答。
303
+
304
+ <br>
305
+
306
+ ## 快速使用
307
+
308
+ ```bash
309
+ git clone https://www.modelscope.cn/codefuse-ai/CodeFuse-CodeLlama-34B-4bits.git
310
+ ```
311
+
312
+
313
+ ```bash
314
+ pip install -r requirements.txt
315
+ ```
316
+
317
+
318
+ ```python
319
+ import os
320
+ import torch
321
+ import time
322
+ from modelscope import AutoTokenizer, snapshot_download
323
+ from auto_gptq import AutoGPTQForCausalLM
324
+
325
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
326
+
327
+ def load_model_tokenizer(model_path):
328
+ """
329
+ Load model and tokenizer based on the given model name or local path of downloaded model.
330
+ """
331
+ tokenizer = AutoTokenizer.from_pretrained(model_path,
332
+ trust_remote_code=True,
333
+ use_fast=False,
334
+ lagecy=False)
335
+ tokenizer.padding_side = "left"
336
+ tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("<unk>")
337
+ tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids("</s>")
338
+
339
+ model = AutoGPTQForCausalLM.from_quantized(model_path,
340
+ inject_fused_attention=False,
341
+ inject_fused_mlp=False,
342
+ use_cuda_fp16=True,
343
+ disable_exllama=False,
344
+ device_map='auto' # 支持多卡
345
+ )
346
+ return model, tokenizer
347
+
348
+
349
+ def inference(model, tokenizer, prompt):
350
+ """
351
+ Uset the given model and tokenizer to generate an answer for the speicifed prompt.
352
+ """
353
+ st = time.time()
354
+ prompt = prompt if prompt.endswith('\n') else f'{prompt}\n'
355
+ inputs = f"<|role_start|>human<|role_end|>{prompt}<|role_start|>bot<|role_end|>"
356
+
357
+ input_ids = tokenizer.encode(inputs,
358
+ return_tensors="pt",
359
+ padding=True,
360
+ add_special_tokens=False).to("cuda")
361
+ with torch.no_grad():
362
+ generated_ids = model.generate(
363
+ input_ids=input_ids,
364
+ top_p=0.95,
365
+ temperature=0.1,
366
+ do_sample=True,
367
+ max_new_tokens=512,
368
+ eos_token_id=tokenizer.eos_token_id,
369
+ pad_token_id=tokenizer.pad_token_id
370
+ )
371
+ print(f'generated tokens num is {len(generated_ids[0][input_ids.size(1):])}')
372
+ outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
373
+ print(f'generate text is {outputs[0][len(inputs): ]}')
374
+ latency = time.time() - st
375
+ print('latency is {} seconds'.format(latency))
376
+
377
+
378
+ if __name__ == "__main__":
379
+ model_dir = snapshot_download('codefuse-ai/CodeFuse-CodeLlama-34B-4bits', revision='v1.0.0')
380
+
381
+ prompt = '请用Python实现一个快速排序算法'
382
+
383
+ model, tokenizer = load_model_tokenizer(model_dir)
384
+ inference(model, tokenizer, prompt)
385
+ ```
386
+
387
+ **目前的推理示例代码是基于[AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ)的,如果你想获取更高的推理速度,建议结合使用[TensorRT-LLM (Early Access)](https://developer.nvidia.com/tensorrt-llm-early-access)。**
388
+
389
+ <br>
390
+
391
+ ## 一致性校验
392
+ 这里提供了模型相关文件的SHA256值,用于下载一致性校验。
393
+
394
+ | 文件 | SHA256 |
395
+ |-------------------------------:|:--------------------------------:|
396
+ |config.json | bd1b92f942549f76d7e02e65fd346b39903943912d6d6a2ff8ff345e43e1115b |
397
+ |generation_config.json | b625bd13a52d0685313c32919324b9bdc9e75a4f1338ca5c28226d1693e130a3 |
398
+ |gptq_model-4bit-64g.bin | 79441bad1d5ab852d0238ed7e113b9912f31189cf9181d7119dd297c4beb454a |
399
+ |pytorch_model.bin.index.json | 9a714170172282cfbcaa120af13c0df08b06d040ff24dab30229d8a010821d3d |
400
+ |quantize_config.json | 3c1744a928e9d6c3f9a2cbb1bb5a89539077e7d456948bf5aee0deed6a7b8028 |
401
+ |special_tokens_map.json | ff3b4a612c4e447acb02d40071bddd989fe0da87eb5b7fe0dbadfc4f74de7531 |
402
+ |tokenizer.json | f7b50bcf6d6672eade5e43514d48e9c1e4e63a56aef7b14acdaca94ce93436f7 |
403
+ |tokenizer.model | 9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 |
404
+ |tokenizer_config.json | c12441e82f2dce0baff87cf5948e82d6e9b51cc0b5266369c30c319fb771eeb2 |
405
+
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/mnt/user/qumu/merged_models/codellama-34b-python-mft-qlora-v1-step22000-merged",
3
+ "architectures": [
4
+ "LlamaForCausalLM"
5
+ ],
6
+ "bos_token_id": 1,
7
+ "eos_token": "</s>",
8
+ "eos_token_id": 2,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 8192,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 22016,
13
+ "max_position_embeddings": 16384,
14
+ "model_type": "llama",
15
+ "num_attention_heads": 64,
16
+ "num_hidden_layers": 48,
17
+ "num_key_value_heads": 8,
18
+ "pad_token": "<unk>",
19
+ "pad_token_id": 0,
20
+ "pretraining_tp": 1,
21
+ "rms_norm_eps": 1e-05,
22
+ "rope_scaling": null,
23
+ "rope_theta": 10000,
24
+ "tie_word_embeddings": false,
25
+ "torch_dtype": "float16",
26
+ "transformers_version": "4.32.0",
27
+ "use_cache": true,
28
+ "vocab_size": 32000
29
+ }
configuration.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"framework":"Pytorch","task":"text-generation"}
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.32.0"
6
+ }
gptq_model-4bit-64g.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:79441bad1d5ab852d0238ed7e113b9912f31189cf9181d7119dd297c4beb454a
3
+ size 18978304722
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a714170172282cfbcaa120af13c0df08b06d040ff24dab30229d8a010821d3d
3
+ size 35838
quantize_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bits": 4,
3
+ "group_size": 64,
4
+ "damp_percent": 0.01,
5
+ "desc_act": false,
6
+ "sym": true,
7
+ "true_sequential": true,
8
+ "model_name_or_path": null,
9
+ "model_file_base_name": null
10
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "unk_token": {
17
+ "content": "<unk>",
18
+ "lstrip": false,
19
+ "normalized": true,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "__type": "AddedToken",
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": true,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "clean_up_tokenization_spaces": false,
11
+ "eos_token": {
12
+ "__type": "AddedToken",
13
+ "content": "</s>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false
18
+ },
19
+ "legacy": null,
20
+ "model_max_length": 1000000000000000019884624838656,
21
+ "pad_token": null,
22
+ "sp_model_kwargs": {},
23
+ "tokenizer_class": "LlamaTokenizer",
24
+ "unk_token": {
25
+ "__type": "AddedToken",
26
+ "content": "<unk>",
27
+ "lstrip": false,
28
+ "normalized": true,
29
+ "rstrip": false,
30
+ "single_word": false
31
+ },
32
+ "use_default_system_prompt": true
33
+ }