TheBloke commited on
Commit
b090b1d
1 Parent(s): 288acf3

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +511 -0
README.md ADDED
@@ -0,0 +1,511 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: https://huggingface.co/codefuse-ai/CodeFuse-CodeLlama-34B
3
+ inference: false
4
+ license: other
5
+ model_creator: CodeFuse AI
6
+ model_name: CodeFuse CodeLlama 34B
7
+ model_type: llama
8
+ prompt_template: '<|role_start|>system<|role_end|>{system_message}
9
+
10
+ <|role_start|>human<|role_end|>{prompt}
11
+
12
+ <|role_start|>bot<|role_end|>
13
+
14
+ '
15
+ quantized_by: TheBloke
16
+ tasks:
17
+ - code-generation
18
+ ---
19
+
20
+ <!-- header start -->
21
+ <!-- 200823 -->
22
+ <div style="width: auto; margin-left: auto; margin-right: auto">
23
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
24
+ </div>
25
+ <div style="display: flex; justify-content: space-between; width: 100%;">
26
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
27
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
28
+ </div>
29
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
30
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
31
+ </div>
32
+ </div>
33
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
34
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
35
+ <!-- header end -->
36
+
37
+ # CodeFuse CodeLlama 34B - AWQ
38
+ - Model creator: [CodeFuse AI](https://huggingface.co/codefuse-ai)
39
+ - Original model: [CodeFuse CodeLlama 34B](https://huggingface.co/codefuse-ai/CodeFuse-CodeLlama-34B)
40
+
41
+ <!-- description start -->
42
+ ## Description
43
+
44
+ This repo contains AWQ model files for [CodeFuse AI's CodeFuse CodeLlama 34B](https://huggingface.co/codefuse-ai/CodeFuse-CodeLlama-34B).
45
+
46
+
47
+ ### About AWQ
48
+
49
+ AWQ is an efficient, accurate and blazing-fast low-bit weight quantization method, currently supporting 4-bit quantization. Compared to GPTQ, it offers faster Transformers-based inference.
50
+
51
+ It is also now supported by continuous batching server [vLLM](https://github.com/vllm-project/vllm), allowing use of AWQ models for high-throughput concurrent inference in multi-user server scenarios. Note that, at the time of writing, overall throughput is still lower than running vLLM with unquantised models, however using AWQ enables using much smaller GPUs which can lead to easier deployment and overall cost savings. For example, a 70B model can be run on 1 x 48GB GPU instead of 2 x 80GB.
52
+ <!-- description end -->
53
+ <!-- repositories-available start -->
54
+ ## Repositories available
55
+
56
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/CodeFuse-CodeLlama-34B-AWQ)
57
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/CodeFuse-CodeLlama-34B-GPTQ)
58
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/CodeFuse-CodeLlama-34B-GGUF)
59
+ * [CodeFuse AI's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/codefuse-ai/CodeFuse-CodeLlama-34B)
60
+ <!-- repositories-available end -->
61
+
62
+ <!-- prompt-template start -->
63
+ ## Prompt template: CodeFuse
64
+
65
+ ```
66
+ <|role_start|>system<|role_end|>{system_message}
67
+ <|role_start|>human<|role_end|>{prompt}
68
+ <|role_start|>bot<|role_end|>
69
+
70
+ ```
71
+
72
+ <!-- prompt-template end -->
73
+ <!-- licensing start -->
74
+ ## Licensing
75
+
76
+ The creator of the source model has listed its license as `other`, and this quantization has therefore used that same license.
77
+
78
+ As this model is based on Llama 2, it is also subject to the Meta Llama 2 license terms, and the license files for that are additionally included. It should therefore be considered as being claimed to be licensed under both licenses. I contacted Hugging Face for clarification on dual licensing but they do not yet have an official position. Should this change, or should Meta provide any feedback on this situation, I will update this section accordingly.
79
+
80
+ In the meantime, any questions regarding licensing, and in particular how these two licenses might interact, should be directed to the original model repository: [CodeFuse AI's CodeFuse CodeLlama 34B](https://huggingface.co/codefuse-ai/CodeFuse-CodeLlama-34B).
81
+ <!-- licensing end -->
82
+ <!-- README_AWQ.md-provided-files start -->
83
+ ## Provided files and AWQ parameters
84
+
85
+ For my first release of AWQ models, I am releasing 128g models only. I will consider adding 32g as well if there is interest, and once I have done perplexity and evaluation comparisons, but at this time 32g models are still not fully tested with AutoAWQ and vLLM.
86
+
87
+ Models are released as sharded safetensors files.
88
+
89
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
90
+ | ------ | ---- | -- | ----------- | ------- | ---- |
91
+ | [main](https://huggingface.co/TheBloke/CodeFuse-CodeLlama-34B-AWQ/tree/main) | 4 | 128 | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 4096 | 18.31 GB
92
+
93
+ <!-- README_AWQ.md-provided-files end -->
94
+
95
+ <!-- README_AWQ.md-use-from-vllm start -->
96
+ ## Serving this model from vLLM
97
+
98
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
99
+
100
+ - When using vLLM as a server, pass the `--quantization awq` parameter, for example:
101
+
102
+ ```shell
103
+ python3 python -m vllm.entrypoints.api_server --model TheBloke/CodeFuse-CodeLlama-34B-AWQ --quantization awq
104
+ ```
105
+
106
+ When using vLLM from Python code, pass the `quantization=awq` parameter, for example:
107
+
108
+ ```python
109
+ from vllm import LLM, SamplingParams
110
+
111
+ prompts = [
112
+ "Hello, my name is",
113
+ "The president of the United States is",
114
+ "The capital of France is",
115
+ "The future of AI is",
116
+ ]
117
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
118
+
119
+ llm = LLM(model="TheBloke/CodeFuse-CodeLlama-34B-AWQ", quantization="awq")
120
+
121
+ outputs = llm.generate(prompts, sampling_params)
122
+
123
+ # Print the outputs.
124
+ for output in outputs:
125
+ prompt = output.prompt
126
+ generated_text = output.outputs[0].text
127
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
128
+ ```
129
+ <!-- README_AWQ.md-use-from-vllm start -->
130
+
131
+ <!-- README_AWQ.md-use-from-python start -->
132
+ ## How to use this AWQ model from Python code
133
+
134
+ ### Install the necessary packages
135
+
136
+ Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.0.2 or later
137
+
138
+ ```shell
139
+ pip3 install autoawq
140
+ ```
141
+
142
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
143
+
144
+ ```shell
145
+ pip3 uninstall -y autoawq
146
+ git clone https://github.com/casper-hansen/AutoAWQ
147
+ cd AutoAWQ
148
+ pip3 install .
149
+ ```
150
+
151
+ ### You can then try the following example code
152
+
153
+ ```python
154
+ from awq import AutoAWQForCausalLM
155
+ from transformers import AutoTokenizer
156
+
157
+ model_name_or_path = "TheBloke/CodeFuse-CodeLlama-34B-AWQ"
158
+
159
+ # Load model
160
+ model = AutoAWQForCausalLM.from_quantized(model_name_or_path, fuse_layers=True,
161
+ trust_remote_code=False, safetensors=True)
162
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=False)
163
+
164
+ prompt = "Tell me about AI"
165
+ prompt_template=f'''<|role_start|>system<|role_end|>{system_message}
166
+ <|role_start|>human<|role_end|>{prompt}
167
+ <|role_start|>bot<|role_end|>
168
+
169
+ '''
170
+
171
+ print("\n\n*** Generate:")
172
+
173
+ tokens = tokenizer(
174
+ prompt_template,
175
+ return_tensors='pt'
176
+ ).input_ids.cuda()
177
+
178
+ # Generate output
179
+ generation_output = model.generate(
180
+ tokens,
181
+ do_sample=True,
182
+ temperature=0.7,
183
+ top_p=0.95,
184
+ top_k=40,
185
+ max_new_tokens=512
186
+ )
187
+
188
+ print("Output: ", tokenizer.decode(generation_output[0]))
189
+
190
+ # Inference can also be done using transformers' pipeline
191
+ from transformers import pipeline
192
+
193
+ print("*** Pipeline:")
194
+ pipe = pipeline(
195
+ "text-generation",
196
+ model=model,
197
+ tokenizer=tokenizer,
198
+ max_new_tokens=512,
199
+ do_sample=True,
200
+ temperature=0.7,
201
+ top_p=0.95,
202
+ top_k=40,
203
+ repetition_penalty=1.1
204
+ )
205
+
206
+ print(pipe(prompt_template)[0]['generated_text'])
207
+ ```
208
+ <!-- README_AWQ.md-use-from-python end -->
209
+
210
+ <!-- README_AWQ.md-compatibility start -->
211
+ ## Compatibility
212
+
213
+ The files provided are tested to work with [AutoAWQ](https://github.com/casper-hansen/AutoAWQ), and [vLLM](https://github.com/vllm-project/vllm).
214
+
215
+ [Huggingface Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) is not yet compatible with AWQ, but a PR is open which should bring support soon: [TGI PR #781](https://github.com/huggingface/text-generation-inference/issues/781).
216
+ <!-- README_AWQ.md-compatibility end -->
217
+
218
+ <!-- footer start -->
219
+ <!-- 200823 -->
220
+ ## Discord
221
+
222
+ For further support, and discussions on these models and AI in general, join us at:
223
+
224
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
225
+
226
+ ## Thanks, and how to contribute
227
+
228
+ Thanks to the [chirper.ai](https://chirper.ai) team!
229
+
230
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
231
+
232
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
233
+
234
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
235
+
236
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
237
+
238
+ * Patreon: https://patreon.com/TheBlokeAI
239
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
240
+
241
+ **Special thanks to**: Aemon Algiz.
242
+
243
+ **Patreon special mentions**: Alicia Loh, Stephen Murray, K, Ajan Kanaga, RoA, Magnesian, Deo Leter, Olakabola, Eugene Pentland, zynix, Deep Realms, Raymond Fosdick, Elijah Stavena, Iucharbius, Erik Bjäreholt, Luis Javier Navarrete Lozano, Nicholas, theTransient, John Detwiler, alfie_i, knownsqashed, Mano Prime, Willem Michiel, Enrico Ros, LangChain4j, OG, Michael Dempsey, Pierre Kircher, Pedro Madruga, James Bentley, Thomas Belote, Luke @flexchar, Leonard Tan, Johann-Peter Hartmann, Illia Dulskyi, Fen Risland, Chadd, S_X, Jeff Scroggin, Ken Nordquist, Sean Connelly, Artur Olbinski, Swaroop Kallakuri, Jack West, Ai Maven, David Ziegler, Russ Johnson, transmissions 11, John Villwock, Alps Aficionado, Clay Pascal, Viktor Bowallius, Subspace Studios, Rainer Wilmers, Trenton Dambrowitz, vamX, Michael Levine, 준교 김, Brandon Frisco, Kalila, Trailburnt, Randy H, Talal Aujan, Nathan Dryer, Vadim, 阿明, ReadyPlayerEmma, Tiffany J. Kim, George Stoitzev, Spencer Kim, Jerry Meng, Gabriel Tamborski, Cory Kujawski, Jeffrey Morgan, Spiking Neurons AB, Edmond Seymore, Alexandros Triantafyllidis, Lone Striker, Cap'n Zoog, Nikolai Manek, danny, ya boyyy, Derek Yates, usrbinkat, Mandus, TL, Nathan LeClaire, subjectnull, Imad Khwaja, webtim, Raven Klaugh, Asp the Wyvern, Gabriel Puliatti, Caitlyn Gatomon, Joseph William Delisle, Jonathan Leane, Luke Pendergrass, SuperWojo, Sebastain Graf, Will Dee, Fred von Graf, Andrey, Dan Guido, Daniel P. Andersen, Nitin Borwankar, Elle, Vitor Caleffi, biorpg, jjj, NimbleBox.ai, Pieter, Matthew Berman, terasurfer, Michael Davis, Alex, Stanislav Ovsiannikov
244
+
245
+
246
+ Thank you to all my generous patrons and donaters!
247
+
248
+ And thank you again to a16z for their generous grant.
249
+
250
+ <!-- footer end -->
251
+
252
+ # Original model card: CodeFuse AI's CodeFuse CodeLlama 34B
253
+
254
+ # Model Card for CodeFuse-CodeLlama-34B
255
+ ![logo](LOGO.png)
256
+
257
+ [[中文]](#chinese) [[English]](#english)
258
+
259
+
260
+
261
+ <a id="english"></a>
262
+
263
+ ## Model Description
264
+
265
+ CodeFuse-CodeLlama-34B is a 34B Code-LLM finetuned by QLoRA of multiple code tasks(600k instrunctions/answers) on the base model CodeLlama-34b-Python.
266
+ The context length of finetuning is 4K while it is able to be finetuned by 16k context if necessary.
267
+ <br>
268
+
269
+ ## News and Updates
270
+
271
+ 🔥🔥🔥 CodeFuse-CodeLlama34B-MFT has achived 74.4% of pass@1 on HumanEval, which is SOTA at present.
272
+
273
+ <br>
274
+
275
+ ## Code Community
276
+
277
+ **Homepage**: 🏡 https://github.com/codefuse-ai (**Please give us your support with a Star🌟 + Fork🚀 + Watch👀**)
278
+
279
+ + If you wish to fine-tune the model yourself, you can visit ✨[MFTCoder](https://github.com/codefuse-ai/MFTCoder)✨✨
280
+
281
+ + If you wish to deploy the model yourself, you can visit ✨[FasterTransformer4CodeFuse](https://github.com/codefuse-ai/FasterTransformer4CodeFuse)✨✨
282
+
283
+ + If you wish to see a demo of the model, you can visit ✨[CodeFuse Demo](https://github.com/codefuse-ai/codefuse)✨✨
284
+
285
+
286
+ ## Performance
287
+
288
+
289
+ | Model | HumanEval(pass@1) | Date |
290
+ |:----------------------------|:-----------------:|:-------:|
291
+ | **CodeFuse-CodeLlama-34B** | **74.4%** | 2023.9 |
292
+ | WizardCoder-Python-34B-V1.0 | 73.2% | 2023.8 |
293
+ | GPT-4(zero-shot) | 67.0% | 2023.3 |
294
+ | PanGu-Coder2 15B | 61.6% | 2023.8 |
295
+ | CodeLlama-34b-Python | 53.7% | 2023.8 |
296
+ | CodeLlama-34b | 48.8% | 2023.8 |
297
+ | GPT-3.5(zero-shot) | 48.1% | 2022.11 |
298
+ | OctoCoder | 46.2% | 2023.8 |
299
+ | StarCoder-15B | 33.6% | 2023.5 |
300
+ | LLaMA 2 70B(zero-shot) | 29.9% | 2023.7 |
301
+
302
+ <br>
303
+
304
+ ## Requirements
305
+
306
+ * python>=3.8
307
+ * pytorch>=2.0.0
308
+ * transformers==4.32.0
309
+ * Sentencepiece
310
+ * CUDA 11.4
311
+ <br>
312
+
313
+ ## Inference String Format
314
+
315
+ The 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.
316
+ Here is an example format of the concatenated string:
317
+
318
+ ```python
319
+ """
320
+ <|role_start|>system<|role_end|>System instruction
321
+ <|role_start|>human<|role_end|>Human 1st round input
322
+ <|role_start|>bot<|role_end|>Bot 1st round output</s>
323
+ <|role_start|>human<|role_end|>Human 2nd round input
324
+ <|role_start|>bot<|role_end|>Bot 2nd round output</s>
325
+ ...
326
+ ...
327
+ ...
328
+ <|role_start|>human<|role_end|>Human nth round input
329
+ <|role_start|>bot<|role_end|>{Bot output to be genreated}</s>
330
+ """
331
+ ```
332
+
333
+ When applying inference, you always make your input string end with "<|role_start|>bot<|role_end|>" to ask the model generating answers.
334
+
335
+ ## Quickstart
336
+
337
+ ```bash
338
+ pip install -r requirements.txt
339
+ ```
340
+
341
+ ```python
342
+ import torch
343
+ from transformers import (
344
+ AutoTokenizer,
345
+ AutoModelForCausalLM,
346
+ )
347
+ tokenizer = AutoTokenizer.from_pretrained(mode_name_or_path, trust_remote_code=True, use_fast=False, legacy=False)
348
+ tokenizer.padding_side = "left"
349
+ tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("<unk>")
350
+ tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids("</s>")
351
+ # try 4bit loading if cuda memory not enough
352
+ model = AutoModelForCausalLM.from_pretrained(mode_name_or_path,
353
+ trust_remote_code=True,
354
+ load_in_4bit=False,
355
+ device_map="auto",
356
+ torch_dtype=torch.bfloat16)
357
+ model.eval()
358
+
359
+ HUMAN_ROLE_START_TAG = "<|role_start|>human<|role_end|>"
360
+ BOT_ROLE_START_TAG = "<|role_start|>bot<|role_end|>"
361
+
362
+ text = f"{HUMAN_ROLE_START_TAG}write a python function of quick sort.{BOT_ROLE_START_TAG}"
363
+ inputs = tokenizer(text, return_tensors='pt', padding=True, add_special_tokens=False).to("cuda")
364
+ outputs = model.generate(
365
+ inputs=inputs["input_ids"],
366
+ attention_mask=inputs["attention_mask"],
367
+ max_new_tokens=512,
368
+ top_p=0.95,
369
+ temperature=0.1,
370
+ do_sample=True,
371
+ eos_token_id=tokenizer.eos_token_id,
372
+ pad_token_id=tokenizer.pad_token_id
373
+ )
374
+ gen_text = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
375
+ print(gen_text)
376
+ ```
377
+
378
+ ## MD5
379
+ We notice that the file may be corrupted during transfer process. Please check MD5 value before use.
380
+
381
+ | Model File | MD5 Value |
382
+ |:---------------------------------|:--------------------------------:|
383
+ | pytorch_model-00001-of-00007.bin | 8d544b1bcb3449934184d4141137329c |
384
+ | pytorch_model-00002-of-00007.bin | 9d5dbb30911e48a42fb6d0fcabb322a4 |
385
+ | pytorch_model-00003-of-00007.bin | b0d4aecee0457d9332005a187e1fffed |
386
+ | pytorch_model-00004-of-00007.bin | 5c7e002de5eab77d0194a2b0f6de0c24 |
387
+ | pytorch_model-00005-of-00007.bin | d22a511aa26b5b17117b665a877490ab |
388
+ | pytorch_model-00006-of-00007.bin | a5c28ac277fac07d16dd66537e54d109 |
389
+ | pytorch_model-00007-of-00007.bin | a967e2c6195477b7407089c0bffa2d53 |
390
+
391
+
392
+ <a id="chinese"></a>
393
+
394
+ ## 模型简介
395
+
396
+ CodeFuse-CodeLlama34B-MFT 是一个通过QLoRA对基座模型CodeLlama-34b-Python进行多代码任务微调的代码大模型。模型微调采用了4k上下文。如果有必要,可以扩展到16k。
397
+ <br>
398
+
399
+ ## 新闻
400
+
401
+ 🔥🔥🔥 CodeFuse-CodeLlama34B-MFT模型在HumanEval pass@1上可以达到74.4%, 为当前开源SOTA。
402
+
403
+ <br>
404
+
405
+ ## 代码社区
406
+ **大本营**: 🏡 https://github.com/codefuse-ai (**欢迎为我们的项目一键三连 Star🌟 + Fork🚀 + Watch👀**)
407
+
408
+ + 如果您想自己微调该模型,可以访问 ✨[MFTCoder](https://github.com/codefuse-ai/MFTCoder)✨✨
409
+
410
+ + 如果您想自己部署该模型,可以访问 ✨[FasterTransformer4CodeFuse](https://github.com/codefuse-ai/FasterTransformer4CodeFuse)✨✨
411
+
412
+ + 如果您想观看该模型示例,可以访问 ✨[CodeFuse Demo](https://github.com/codefuse-ai/codefuse)✨✨
413
+
414
+
415
+ ## 评测表现(代码)
416
+
417
+ | 模型 | HumanEval(pass@1) | 日期 |
418
+ |:----------------------------|:-----------------:|:-------:|
419
+ | **CodeFuse-CodeLlama-34B** | **74.4%** | 2023.9 |
420
+ | WizardCoder-Python-34B-V1.0 | 73.2% | 2023.8 |
421
+ | GPT-4(zero-shot) | 67.0% | 2023.3 |
422
+ | PanGu-Coder2 15B | 61.6% | 2023.8 |
423
+ | CodeLlama-34b-Python | 53.7% | 2023.8 |
424
+ | CodeLlama-34b | 48.8% | 2023.8 |
425
+ | GPT-3.5(zero-shot) | 48.1% | 2022.11 |
426
+ | OctoCoder | 46.2% | 2023.8 |
427
+ | StarCoder-15B | 33.6% | 2023.5 |
428
+ | LLaMA 2 70B(zero-shot) | 29.9% | 2023.7 |
429
+
430
+ <br>
431
+
432
+ ## Requirements
433
+
434
+ * python>=3.8
435
+ * pytorch>=2.0.0
436
+ * transformers==4.32.0
437
+ * CUDA 11.4
438
+ <br>
439
+
440
+ ## 推理数据格式
441
+
442
+ 推理数据为模型在训练数据格式下拼接的字符串形式,它也是推理时输入prompt拼接的方式:
443
+
444
+ ```python
445
+ """
446
+ <|role_start|>system<|role_end|>这是System指令
447
+ <|role_start|>human<|role_end|>这是第1轮用户输入的问题
448
+ <|role_start|>bot<|role_end|>这是第1轮模型生成的内容</s>
449
+ <|role_start|>human<|role_end|>这是第2轮用户输入的问题
450
+ <|role_start|>bot<|role_end|>这是第2轮模型生成的内容</s>
451
+ ...
452
+ ...
453
+ ...
454
+ <|role_start|>human<|role_end|>这是第n轮用户输入的问题
455
+ <|role_start|>bot<|role_end|>{模型现在要生成的内容}</s>
456
+ """
457
+ ```
458
+
459
+ 推理时,请确保拼接的prompt字符串以"<|role_start|>bot<|role_end|>"结尾,引导模型生成回答。
460
+
461
+ ## 快速使用
462
+
463
+ ```python
464
+ from transformers import (
465
+ AutoTokenizer,
466
+ AutoModelForCausalLM,
467
+ )
468
+ tokenizer = AutoTokenizer.from_pretrained(mode_name_or_path, trust_remote_code=True, use_fast=False, legacy=False)
469
+ tokenizer.padding_side = "left"
470
+ tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("<unk>")
471
+ tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids("</s>")
472
+ # 如果显存不够,可以考虑量化加载
473
+ model = AutoModelForCausalLM.from_pretrained(mode_name_or_path,
474
+ trust_remote_code=True,
475
+ load_in_4bit=False,
476
+ device_map="auto",
477
+ torch_dtype=torch.bfloat16)
478
+ model.eval()
479
+
480
+ HUMAN_ROLE_START_TAG = "<|role_start|>human<|role_end|>"
481
+ BOT_ROLE_START_TAG = "<|role_start|>bot<|role_end|>"
482
+
483
+ text = f"{HUMAN_ROLE_START_TAG}请用C++实现求解第n个斐波那契数{BOT_ROLE_START_TAG}"
484
+ inputs = tokenizer(text, return_tensors='pt', padding=True, add_special_tokens=False).to("cuda")
485
+ outputs = model.generate(
486
+ inputs=inputs["input_ids"],
487
+ attention_mask=inputs["attention_mask"],
488
+ max_new_tokens=512,
489
+ top_p=0.95,
490
+ temperature=0.1,
491
+ do_sample=True,
492
+ eos_token_id=tokenizer.eos_token_id,
493
+ pad_token_id=tokenizer.pad_token_id
494
+ )
495
+ gen_text = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
496
+ print(gen_text)
497
+ ```
498
+
499
+
500
+ ## MD5
501
+ 我们发现模型文件可能会在传输过程中损坏,使用前请检查文件MD5值。
502
+
503
+ | 模型文件 | MD5值 |
504
+ |:---------------------------------|:--------------------------------:|
505
+ | pytorch_model-00001-of-00007.bin | 8d544b1bcb3449934184d4141137329c |
506
+ | pytorch_model-00002-of-00007.bin | 9d5dbb30911e48a42fb6d0fcabb322a4 |
507
+ | pytorch_model-00003-of-00007.bin | b0d4aecee0457d9332005a187e1fffed |
508
+ | pytorch_model-00004-of-00007.bin | 5c7e002de5eab77d0194a2b0f6de0c24 |
509
+ | pytorch_model-00005-of-00007.bin | d22a511aa26b5b17117b665a877490ab |
510
+ | pytorch_model-00006-of-00007.bin | a5c28ac277fac07d16dd66537e54d109 |
511
+ | pytorch_model-00007-of-00007.bin | a967e2c6195477b7407089c0bffa2d53 |