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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: codellama/CodeLlama-70b-Instruct-hf
|
3 |
+
inference: false
|
4 |
+
language:
|
5 |
+
- code
|
6 |
+
license: llama2
|
7 |
+
model_creator: Code Llama
|
8 |
+
model_name: Codellama 70B Instruct
|
9 |
+
model_type: llama
|
10 |
+
pipeline_tag: text-generation
|
11 |
+
prompt_template: "Source: system\n\n {system_message}<step> Source: user\n\n {prompt}\
|
12 |
+
\ <step> Source: assistant\n \n"
|
13 |
+
quantized_by: TheBloke
|
14 |
+
tags:
|
15 |
+
- llama-2
|
16 |
+
---
|
17 |
+
<!-- markdownlint-disable MD041 -->
|
18 |
+
|
19 |
+
<!-- header start -->
|
20 |
+
<!-- 200823 -->
|
21 |
+
<div style="width: auto; margin-left: auto; margin-right: auto">
|
22 |
+
<img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
|
23 |
+
</div>
|
24 |
+
<div style="display: flex; justify-content: space-between; width: 100%;">
|
25 |
+
<div style="display: flex; flex-direction: column; align-items: flex-start;">
|
26 |
+
<p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
|
27 |
+
</div>
|
28 |
+
<div style="display: flex; flex-direction: column; align-items: flex-end;">
|
29 |
+
<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>
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
<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>
|
33 |
+
<hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
|
34 |
+
<!-- header end -->
|
35 |
+
|
36 |
+
# Codellama 70B Instruct - AWQ
|
37 |
+
- Model creator: [Code Llama](https://huggingface.co/codellama)
|
38 |
+
- Original model: [Codellama 70B Instruct](https://huggingface.co/codellama/CodeLlama-70b-Instruct-hf)
|
39 |
+
|
40 |
+
<!-- description start -->
|
41 |
+
## Description
|
42 |
+
|
43 |
+
This repo contains AWQ model files for [Code Llama's Codellama 70B Instruct](https://huggingface.co/codellama/CodeLlama-70b-Instruct-hf).
|
44 |
+
|
45 |
+
These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
|
46 |
+
|
47 |
+
|
48 |
+
### About AWQ
|
49 |
+
|
50 |
+
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 with equivalent or better quality compared to the most commonly used GPTQ settings.
|
51 |
+
|
52 |
+
AWQ models are currently supported on Linux and Windows, with NVidia GPUs only. macOS users: please use GGUF models instead.
|
53 |
+
|
54 |
+
It is supported by:
|
55 |
+
|
56 |
+
- [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
|
57 |
+
- [vLLM](https://github.com/vllm-project/vllm) - version 0.2.2 or later for support for all model types.
|
58 |
+
- [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
|
59 |
+
- [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
|
60 |
+
- [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
|
61 |
+
|
62 |
+
<!-- description end -->
|
63 |
+
<!-- repositories-available start -->
|
64 |
+
## Repositories available
|
65 |
+
|
66 |
+
* [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/CodeLlama-70B-Instruct-AWQ)
|
67 |
+
* [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/CodeLlama-70B-Instruct-GPTQ)
|
68 |
+
* [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/CodeLlama-70B-Instruct-GGUF)
|
69 |
+
* [Code Llama's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/codellama/CodeLlama-70b-Instruct-hf)
|
70 |
+
<!-- repositories-available end -->
|
71 |
+
|
72 |
+
<!-- prompt-template start -->
|
73 |
+
## Prompt template: CodeLlama-70B-Instruct
|
74 |
+
|
75 |
+
```
|
76 |
+
Source: system
|
77 |
+
|
78 |
+
{system_message}<step> Source: user
|
79 |
+
|
80 |
+
{prompt} <step> Source: assistant
|
81 |
+
|
82 |
+
|
83 |
+
```
|
84 |
+
|
85 |
+
<!-- prompt-template end -->
|
86 |
+
|
87 |
+
|
88 |
+
<!-- README_AWQ.md-provided-files start -->
|
89 |
+
## Provided files, and AWQ parameters
|
90 |
+
|
91 |
+
I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
|
92 |
+
|
93 |
+
Models are released as sharded safetensors files.
|
94 |
+
|
95 |
+
| Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
|
96 |
+
| ------ | ---- | -- | ----------- | ------- | ---- |
|
97 |
+
| [main](https://huggingface.co/TheBloke/CodeLlama-70B-Instruct-AWQ/tree/main) | 4 | 128 | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1/viewer/) | 4096 | 36.61 GB
|
98 |
+
|
99 |
+
<!-- README_AWQ.md-provided-files end -->
|
100 |
+
|
101 |
+
<!-- README_AWQ.md-text-generation-webui start -->
|
102 |
+
## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
|
103 |
+
|
104 |
+
Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
|
105 |
+
|
106 |
+
It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
|
107 |
+
|
108 |
+
1. Click the **Model tab**.
|
109 |
+
2. Under **Download custom model or LoRA**, enter `TheBloke/CodeLlama-70B-Instruct-AWQ`.
|
110 |
+
3. Click **Download**.
|
111 |
+
4. The model will start downloading. Once it's finished it will say "Done".
|
112 |
+
5. In the top left, click the refresh icon next to **Model**.
|
113 |
+
6. In the **Model** dropdown, choose the model you just downloaded: `CodeLlama-70B-Instruct-AWQ`
|
114 |
+
7. Select **Loader: AutoAWQ**.
|
115 |
+
8. Click Load, and the model will load and is now ready for use.
|
116 |
+
9. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
|
117 |
+
10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
|
118 |
+
<!-- README_AWQ.md-text-generation-webui end -->
|
119 |
+
|
120 |
+
<!-- README_AWQ.md-use-from-vllm start -->
|
121 |
+
## Multi-user inference server: vLLM
|
122 |
+
|
123 |
+
Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
|
124 |
+
|
125 |
+
- Please ensure you are using vLLM version 0.2 or later.
|
126 |
+
- When using vLLM as a server, pass the `--quantization awq` parameter.
|
127 |
+
|
128 |
+
For example:
|
129 |
+
|
130 |
+
```shell
|
131 |
+
python3 -m vllm.entrypoints.api_server --model TheBloke/CodeLlama-70B-Instruct-AWQ --quantization awq --dtype auto
|
132 |
+
```
|
133 |
+
|
134 |
+
- When using vLLM from Python code, again set `quantization=awq`.
|
135 |
+
|
136 |
+
For example:
|
137 |
+
|
138 |
+
```python
|
139 |
+
from vllm import LLM, SamplingParams
|
140 |
+
|
141 |
+
prompts = [
|
142 |
+
"Tell me about AI",
|
143 |
+
"Write a story about llamas",
|
144 |
+
"What is 291 - 150?",
|
145 |
+
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
146 |
+
]
|
147 |
+
prompt_template=f'''Source: system
|
148 |
+
|
149 |
+
{system_message}<step> Source: user
|
150 |
+
|
151 |
+
{prompt} <step> Source: assistant
|
152 |
+
|
153 |
+
'''
|
154 |
+
|
155 |
+
prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
|
156 |
+
|
157 |
+
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
158 |
+
|
159 |
+
llm = LLM(model="TheBloke/CodeLlama-70B-Instruct-AWQ", quantization="awq", dtype="auto")
|
160 |
+
|
161 |
+
outputs = llm.generate(prompts, sampling_params)
|
162 |
+
|
163 |
+
# Print the outputs.
|
164 |
+
for output in outputs:
|
165 |
+
prompt = output.prompt
|
166 |
+
generated_text = output.outputs[0].text
|
167 |
+
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
|
168 |
+
```
|
169 |
+
<!-- README_AWQ.md-use-from-vllm start -->
|
170 |
+
|
171 |
+
<!-- README_AWQ.md-use-from-tgi start -->
|
172 |
+
## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
|
173 |
+
|
174 |
+
Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
|
175 |
+
|
176 |
+
Example Docker parameters:
|
177 |
+
|
178 |
+
```shell
|
179 |
+
--model-id TheBloke/CodeLlama-70B-Instruct-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
|
180 |
+
```
|
181 |
+
|
182 |
+
Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
|
183 |
+
|
184 |
+
```shell
|
185 |
+
pip3 install huggingface-hub
|
186 |
+
```
|
187 |
+
|
188 |
+
```python
|
189 |
+
from huggingface_hub import InferenceClient
|
190 |
+
|
191 |
+
endpoint_url = "https://your-endpoint-url-here"
|
192 |
+
|
193 |
+
prompt = "Tell me about AI"
|
194 |
+
prompt_template=f'''Source: system
|
195 |
+
|
196 |
+
{system_message}<step> Source: user
|
197 |
+
|
198 |
+
{prompt} <step> Source: assistant
|
199 |
+
|
200 |
+
'''
|
201 |
+
|
202 |
+
client = InferenceClient(endpoint_url)
|
203 |
+
response = client.text_generation(prompt,
|
204 |
+
max_new_tokens=128,
|
205 |
+
do_sample=True,
|
206 |
+
temperature=0.7,
|
207 |
+
top_p=0.95,
|
208 |
+
top_k=40,
|
209 |
+
repetition_penalty=1.1)
|
210 |
+
|
211 |
+
print(f"Model output: ", response)
|
212 |
+
```
|
213 |
+
<!-- README_AWQ.md-use-from-tgi end -->
|
214 |
+
|
215 |
+
<!-- README_AWQ.md-use-from-python start -->
|
216 |
+
## Inference from Python code using Transformers
|
217 |
+
|
218 |
+
### Install the necessary packages
|
219 |
+
|
220 |
+
- Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
|
221 |
+
- Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
|
222 |
+
|
223 |
+
```shell
|
224 |
+
pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
|
225 |
+
```
|
226 |
+
|
227 |
+
Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
|
228 |
+
|
229 |
+
If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
|
230 |
+
|
231 |
+
```shell
|
232 |
+
pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
|
233 |
+
```
|
234 |
+
|
235 |
+
If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
|
236 |
+
|
237 |
+
```shell
|
238 |
+
pip3 uninstall -y autoawq
|
239 |
+
git clone https://github.com/casper-hansen/AutoAWQ
|
240 |
+
cd AutoAWQ
|
241 |
+
pip3 install .
|
242 |
+
```
|
243 |
+
|
244 |
+
### Transformers example code (requires Transformers 4.35.0 and later)
|
245 |
+
|
246 |
+
```python
|
247 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
|
248 |
+
|
249 |
+
model_name_or_path = "TheBloke/CodeLlama-70B-Instruct-AWQ"
|
250 |
+
|
251 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
252 |
+
model = AutoModelForCausalLM.from_pretrained(
|
253 |
+
model_name_or_path,
|
254 |
+
low_cpu_mem_usage=True,
|
255 |
+
device_map="cuda:0"
|
256 |
+
)
|
257 |
+
|
258 |
+
# Using the text streamer to stream output one token at a time
|
259 |
+
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
260 |
+
|
261 |
+
prompt = "Tell me about AI"
|
262 |
+
prompt_template=f'''Source: system
|
263 |
+
|
264 |
+
{system_message}<step> Source: user
|
265 |
+
|
266 |
+
{prompt} <step> Source: assistant
|
267 |
+
|
268 |
+
'''
|
269 |
+
|
270 |
+
# Convert prompt to tokens
|
271 |
+
tokens = tokenizer(
|
272 |
+
prompt_template,
|
273 |
+
return_tensors='pt'
|
274 |
+
).input_ids.cuda()
|
275 |
+
|
276 |
+
generation_params = {
|
277 |
+
"do_sample": True,
|
278 |
+
"temperature": 0.7,
|
279 |
+
"top_p": 0.95,
|
280 |
+
"top_k": 40,
|
281 |
+
"max_new_tokens": 512,
|
282 |
+
"repetition_penalty": 1.1
|
283 |
+
}
|
284 |
+
|
285 |
+
# Generate streamed output, visible one token at a time
|
286 |
+
generation_output = model.generate(
|
287 |
+
tokens,
|
288 |
+
streamer=streamer,
|
289 |
+
**generation_params
|
290 |
+
)
|
291 |
+
|
292 |
+
# Generation without a streamer, which will include the prompt in the output
|
293 |
+
generation_output = model.generate(
|
294 |
+
tokens,
|
295 |
+
**generation_params
|
296 |
+
)
|
297 |
+
|
298 |
+
# Get the tokens from the output, decode them, print them
|
299 |
+
token_output = generation_output[0]
|
300 |
+
text_output = tokenizer.decode(token_output)
|
301 |
+
print("model.generate output: ", text_output)
|
302 |
+
|
303 |
+
# Inference is also possible via Transformers' pipeline
|
304 |
+
from transformers import pipeline
|
305 |
+
|
306 |
+
pipe = pipeline(
|
307 |
+
"text-generation",
|
308 |
+
model=model,
|
309 |
+
tokenizer=tokenizer,
|
310 |
+
**generation_params
|
311 |
+
)
|
312 |
+
|
313 |
+
pipe_output = pipe(prompt_template)[0]['generated_text']
|
314 |
+
print("pipeline output: ", pipe_output)
|
315 |
+
|
316 |
+
```
|
317 |
+
<!-- README_AWQ.md-use-from-python end -->
|
318 |
+
|
319 |
+
<!-- README_AWQ.md-compatibility start -->
|
320 |
+
## Compatibility
|
321 |
+
|
322 |
+
The files provided are tested to work with:
|
323 |
+
|
324 |
+
- [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
|
325 |
+
- [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
|
326 |
+
- [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
|
327 |
+
- [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
|
328 |
+
- [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
|
329 |
+
|
330 |
+
<!-- README_AWQ.md-compatibility end -->
|
331 |
+
|
332 |
+
<!-- footer start -->
|
333 |
+
<!-- 200823 -->
|
334 |
+
## Discord
|
335 |
+
|
336 |
+
For further support, and discussions on these models and AI in general, join us at:
|
337 |
+
|
338 |
+
[TheBloke AI's Discord server](https://discord.gg/theblokeai)
|
339 |
+
|
340 |
+
## Thanks, and how to contribute
|
341 |
+
|
342 |
+
Thanks to the [chirper.ai](https://chirper.ai) team!
|
343 |
+
|
344 |
+
Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
|
345 |
+
|
346 |
+
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.
|
347 |
+
|
348 |
+
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.
|
349 |
+
|
350 |
+
Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
|
351 |
+
|
352 |
+
* Patreon: https://patreon.com/TheBlokeAI
|
353 |
+
* Ko-Fi: https://ko-fi.com/TheBlokeAI
|
354 |
+
|
355 |
+
**Special thanks to**: Aemon Algiz.
|
356 |
+
|
357 |
+
**Patreon special mentions**: Michael Levine, 阿明, Trailburnt, Nikolai Manek, John Detwiler, Randy H, Will Dee, Sebastain Graf, NimbleBox.ai, Eugene Pentland, Emad Mostaque, Ai Maven, Jim Angel, Jeff Scroggin, Michael Davis, Manuel Alberto Morcote, Stephen Murray, Robert, Justin Joy, Luke @flexchar, Brandon Frisco, Elijah Stavena, S_X, Dan Guido, Undi ., Komninos Chatzipapas, Shadi, theTransient, Lone Striker, Raven Klaugh, jjj, Cap'n Zoog, Michel-Marie MAUDET (LINAGORA), Matthew Berman, David, Fen Risland, Omer Bin Jawed, Luke Pendergrass, Kalila, OG, Erik Bjäreholt, Rooh Singh, Joseph William Delisle, Dan Lewis, TL, John Villwock, AzureBlack, Brad, Pedro Madruga, Caitlyn Gatomon, K, jinyuan sun, Mano Prime, Alex, Jeffrey Morgan, Alicia Loh, Illia Dulskyi, Chadd, transmissions 11, fincy, Rainer Wilmers, ReadyPlayerEmma, knownsqashed, Mandus, biorpg, Deo Leter, Brandon Phillips, SuperWojo, Sean Connelly, Iucharbius, Jack West, Harry Royden McLaughlin, Nicholas, terasurfer, Vitor Caleffi, Duane Dunston, Johann-Peter Hartmann, David Ziegler, Olakabola, Ken Nordquist, Trenton Dambrowitz, Tom X Nguyen, Vadim, Ajan Kanaga, Leonard Tan, Clay Pascal, Alexandros Triantafyllidis, JM33133, Xule, vamX, ya boyyy, subjectnull, Talal Aujan, Alps Aficionado, wassieverse, Ari Malik, James Bentley, Woland, Spencer Kim, Michael Dempsey, Fred von Graf, Elle, zynix, William Richards, Stanislav Ovsiannikov, Edmond Seymore, Jonathan Leane, Martin Kemka, usrbinkat, Enrico Ros
|
358 |
+
|
359 |
+
|
360 |
+
Thank you to all my generous patrons and donaters!
|
361 |
+
|
362 |
+
And thank you again to a16z for their generous grant.
|
363 |
+
|
364 |
+
<!-- footer end -->
|
365 |
+
|
366 |
+
# Original model card: Code Llama's Codellama 70B Instruct
|
367 |
+
|
368 |
+
# **Code Llama**
|
369 |
+
Code Llama is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters. This is the repository for the 70B instruct-tuned version in the Hugging Face Transformers format. This model is designed for general code synthesis and understanding. Links to other models can be found in the index at the bottom.
|
370 |
+
|
371 |
+
| | Base Model | Python | Instruct |
|
372 |
+
| --- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
373 |
+
| 7B | [codellama/CodeLlama-7b-hf](https://huggingface.co/codellama/CodeLlama-7b-hf) | [codellama/CodeLlama-7b-Python-hf](https://huggingface.co/codellama/CodeLlama-7b-Python-hf) | [codellama/CodeLlama-7b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7b-Instruct-hf) |
|
374 |
+
| 13B | [codellama/CodeLlama-13b-hf](https://huggingface.co/codellama/CodeLlama-13b-hf) | [codellama/CodeLlama-13b-Python-hf](https://huggingface.co/codellama/CodeLlama-13b-Python-hf) | [codellama/CodeLlama-13b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-13b-Instruct-hf) |
|
375 |
+
| 34B | [codellama/CodeLlama-34b-hf](https://huggingface.co/codellama/CodeLlama-34b-hf) | [codellama/CodeLlama-34b-Python-hf](https://huggingface.co/codellama/CodeLlama-34b-Python-hf) | [codellama/CodeLlama-34b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-34b-Instruct-hf) |
|
376 |
+
| 70B | [codellama/CodeLlama-70b-hf](https://huggingface.co/codellama/CodeLlama-70b-hf) | [codellama/CodeLlama-70b-Python-hf](https://huggingface.co/codellama/CodeLlama-70b-Python-hf) | [codellama/CodeLlama-70b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-70b-Instruct-hf) |
|
377 |
+
|
378 |
+
Model capabilities:
|
379 |
+
|
380 |
+
- [x] Code completion.
|
381 |
+
- [ ] Infilling.
|
382 |
+
- [x] Instructions / chat.
|
383 |
+
- [ ] Python specialist.
|
384 |
+
|
385 |
+
## Model Use
|
386 |
+
|
387 |
+
Install `transformers`
|
388 |
+
|
389 |
+
```bash
|
390 |
+
pip install transformers accelerate
|
391 |
+
```
|
392 |
+
|
393 |
+
**Chat use:** The 70B Instruct model uses a [different prompt template](#chat_prompt) than the smaller versions. To use it with `transformers`, we recommend you use the built-in chat template:
|
394 |
+
|
395 |
+
```py
|
396 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
397 |
+
import transformers
|
398 |
+
import torch
|
399 |
+
|
400 |
+
model_id = "codellama/CodeLlama-70b-Instruct-hf"
|
401 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
402 |
+
model = AutoModelForCausalLM.from_pretrained(
|
403 |
+
model_id,
|
404 |
+
torch_dtype=torch.float16,
|
405 |
+
device_map="auto",
|
406 |
+
)
|
407 |
+
|
408 |
+
chat = [
|
409 |
+
{"role": "system", "content": "You are a helpful and honest code assistant expert in JavaScript. Please, provide all answers to programming questions in JavaScript"},
|
410 |
+
{"role": "user", "content": "Write a function that computes the set of sums of all contiguous sublists of a given list."},
|
411 |
+
]
|
412 |
+
inputs = tokenizer.apply_chat_template(chat, return_tensors="pt").to("cuda")
|
413 |
+
|
414 |
+
output = model.generate(input_ids=inputs, max_new_tokens=200)
|
415 |
+
output = output[0].to("cpu")
|
416 |
+
print(tokenizer.decode(output))
|
417 |
+
```
|
418 |
+
|
419 |
+
You can also use the model for **text or code completion**. This examples uses transformers' `pipeline` interface:
|
420 |
+
|
421 |
+
```py
|
422 |
+
from transformers import AutoTokenizer
|
423 |
+
import transformers
|
424 |
+
import torch
|
425 |
+
|
426 |
+
model_id = "codellama/CodeLlama-70b-hf"
|
427 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
428 |
+
pipeline = transformers.pipeline(
|
429 |
+
"text-generation",
|
430 |
+
model=model_id,
|
431 |
+
torch_dtype=torch.float16,
|
432 |
+
device_map="auto",
|
433 |
+
)
|
434 |
+
|
435 |
+
sequences = pipeline(
|
436 |
+
'def fibonacci(',
|
437 |
+
do_sample=True,
|
438 |
+
temperature=0.2,
|
439 |
+
top_p=0.9,
|
440 |
+
num_return_sequences=1,
|
441 |
+
eos_token_id=tokenizer.eos_token_id,
|
442 |
+
max_length=100,
|
443 |
+
)
|
444 |
+
for seq in sequences:
|
445 |
+
print(f"Result: {seq['generated_text']}")
|
446 |
+
```
|
447 |
+
|
448 |
+
<a name="chat_prompt"></a>
|
449 |
+
## Chat prompt
|
450 |
+
|
451 |
+
CodeLlama 70B Instruct uses a different format for the chat prompt than previous Llama 2 or CodeLlama models. As mentioned above, the easiest way to use it is with the help of the tokenizer's chat template. If you need to build the string or tokens, manually, here's how to do it.
|
452 |
+
|
453 |
+
We'll do our tests with the following made-up dialog:
|
454 |
+
|
455 |
+
```py
|
456 |
+
chat = [
|
457 |
+
{"role": "system", "content": "System prompt "},
|
458 |
+
{"role": "user", "content": "First user query"},
|
459 |
+
{"role": "assistant", "content": "Model response to first query"},
|
460 |
+
{"role": "user", "content": "Second user query"},
|
461 |
+
]
|
462 |
+
```
|
463 |
+
|
464 |
+
First, let's see what the prompt looks like if we use the chat template:
|
465 |
+
|
466 |
+
```py
|
467 |
+
tokenizer.apply_chat_template(chat, tokenize=False)
|
468 |
+
```
|
469 |
+
|
470 |
+
```
|
471 |
+
'<s>Source: system\n\n System prompt <step> Source: user\n\n First user query <step> Source: assistant\n\n Model response to first query <step> Source: user\n\n Second user query <step> Source: assistant\nDestination: user\n\n '
|
472 |
+
```
|
473 |
+
|
474 |
+
So each turn of the conversation has a `Source` (`system`, `user`, or `assistant`), and then the content appears after two newlines and a space. Turns are separated with the special token ` <step> `. After the last turn (which must necessarily come from the `user`), we invite the model to respond by using the special syntax `Source: assistant\nDestination: user\n\n `. Let's see how we can build the same string ourselves:
|
475 |
+
|
476 |
+
```py
|
477 |
+
output = "<s>"
|
478 |
+
for m in chat:
|
479 |
+
output += f"Source: {m['role']}\n\n {m['content'].strip()}"
|
480 |
+
output += " <step> "
|
481 |
+
output += "Source: assistant\nDestination: user\n\n "
|
482 |
+
output
|
483 |
+
```
|
484 |
+
|
485 |
+
```
|
486 |
+
'<s>Source: system\n\n System prompt <step> Source: user\n\n First user query <step> Source: assistant\n\n Model response to first query <step> Source: user\n\n Second user query <step> Source: assistant\nDestination: user\n\n '
|
487 |
+
```
|
488 |
+
|
489 |
+
To verify that we got it right, we'll compare against the [reference code in the original GitHub repo](https://github.com/facebookresearch/codellama/blob/1af62e1f43db1fa5140fa43cb828465a603a48f3/llama/generation.py#L506). We used the same dialog and tokenized it with the `dialog_prompt_tokens` function and got the following tokens:
|
490 |
+
|
491 |
+
```py
|
492 |
+
reference_tokens = [1, 7562, 29901, 1788, 13, 13, 2184, 9508, 32015, 7562, 29901, 1404, 13, 13, 3824, 1404, 2346, 32015, 7562, 29901, 20255, 13, 13, 8125, 2933, 304, 937, 2346, 32015, 7562, 29901, 1404, 13, 13, 6440, 1404, 2346, 32015, 7562, 29901, 20255, 13, 14994, 3381, 29901, 1404, 13, 13, 29871]
|
493 |
+
```
|
494 |
+
|
495 |
+
Let's see what we get with the string we built using our Python loop. Note that we don't add "special tokens" because the string already starts with `<s>`, the beginning of sentence token:
|
496 |
+
|
497 |
+
```py
|
498 |
+
tokens = tokenizer.encode(output, add_special_tokens=False)
|
499 |
+
assert reference_tokens == tokens
|
500 |
+
```
|
501 |
+
|
502 |
+
Similarly, let's verify that the chat template produces the same token sequence:
|
503 |
+
|
504 |
+
```py
|
505 |
+
assert reference_tokens == tokenizer.apply_chat_template(chat)
|
506 |
+
```
|
507 |
+
|
508 |
+
As a final detail, please note that if the dialog does not start with a `system` turn, the [original code will insert one with an empty content string](https://github.com/facebookresearch/codellama/blob/1af62e1f43db1fa5140fa43cb828465a603a48f3/llama/generation.py#L418).
|
509 |
+
|
510 |
+
|
511 |
+
## Model Details
|
512 |
+
*Note: Use of this model is governed by the Meta license. Meta developed and publicly released the Code Llama family of large language models (LLMs).
|
513 |
+
|
514 |
+
**Model Developers** Meta
|
515 |
+
|
516 |
+
**Variations** Code Llama comes in four model sizes, and three variants:
|
517 |
+
|
518 |
+
* Code Llama: base models designed for general code synthesis and understanding
|
519 |
+
* Code Llama - Python: designed specifically for Python
|
520 |
+
* Code Llama - Instruct: for instruction following and safer deployment
|
521 |
+
|
522 |
+
All variants are available in sizes of 7B, 13B, 34B, and 70B parameters.
|
523 |
+
|
524 |
+
**This repository contains the Instruct version of the 70B parameters model.**
|
525 |
+
|
526 |
+
**Input** Models input text only.
|
527 |
+
|
528 |
+
**Output** Models generate text only.
|
529 |
+
|
530 |
+
**Model Architecture** Code Llama is an auto-regressive language model that uses an optimized transformer architecture. It was fine-tuned with up to 16k tokens. This variant **does not** support long context of up to 100k tokens.
|
531 |
+
|
532 |
+
**Model Dates** Code Llama and its variants have been trained between January 2023 and January 2024.
|
533 |
+
|
534 |
+
**Status** This is a static model trained on an offline dataset. Future versions of Code Llama - Instruct will be released as we improve model safety with community feedback.
|
535 |
+
|
536 |
+
**License** A custom commercial license is available at: [https://ai.meta.com/resources/models-and-libraries/llama-downloads/](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
|
537 |
+
|
538 |
+
**Research Paper** More information can be found in the paper "[Code Llama: Open Foundation Models for Code](https://ai.meta.com/research/publications/code-llama-open-foundation-models-for-code/)" or its [arXiv page](https://arxiv.org/abs/2308.12950).
|
539 |
+
|
540 |
+
## Intended Use
|
541 |
+
**Intended Use Cases** Code Llama and its variants are intended for commercial and research use in English and relevant programming languages. The base model Code Llama can be adapted for a variety of code synthesis and understanding tasks, Code Llama - Python is designed specifically to handle the Python programming language, and Code Llama - Instruct is intended to be safer to use for code assistant and generation applications.
|
542 |
+
|
543 |
+
**Out-of-Scope Uses** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English. Use in any other way that is prohibited by the Acceptable Use Policy and Licensing Agreement for Code Llama and its variants.
|
544 |
+
|
545 |
+
## Hardware and Software
|
546 |
+
**Training Factors** We used custom training libraries. The training and fine-tuning of the released models have been performed Meta’s Research Super Cluster.
|
547 |
+
**Carbon Footprint** In aggregate, training all 12 Code Llama models required 1400K GPU hours of computation on hardware of type A100-80GB (TDP of 350-400W). Estimated total emissions were 228.55 tCO2eq, 100% of which were offset by Meta’s sustainability program.
|
548 |
+
|
549 |
+
## Evaluation Results
|
550 |
+
|
551 |
+
See evaluations for the main models and detailed ablations in Section 3 and safety evaluations in Section 4 of the research paper.
|
552 |
+
|
553 |
+
|
554 |
+
## Ethical Considerations and Limitations
|
555 |
+
|
556 |
+
Code Llama and its variants are a new technology that carries risks with use. Testing conducted to date has been in English, and has not covered, nor could it cover all scenarios. For these reasons, as with all LLMs, Code Llama’s potential outputs cannot be predicted in advance, and the model may in some instances produce inaccurate or objectionable responses to user prompts. Therefore, before deploying any applications of Code Llama, developers should perform safety testing and tuning tailored to their specific applications of the model.
|
557 |
+
|
558 |
+
Please see the Responsible Use Guide available available at [https://ai.meta.com/llama/responsible-use-guide](https://ai.meta.com/llama/responsible-use-guide).
|