TheBloke commited on
Commit
d77d2a4
1 Parent(s): 2815355

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +377 -0
README.md ADDED
@@ -0,0 +1,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: https://huggingface.co/mrm8488/llama-2-coder-7b
3
+ datasets:
4
+ - HuggingFaceH4/CodeAlpaca_20K
5
+ inference: false
6
+ language:
7
+ - code
8
+ license: apache-2.0
9
+ model-index:
10
+ - name: FalCoder
11
+ results: []
12
+ model_creator: mrm8488
13
+ model_name: Llama 2 Coder 7B
14
+ model_type: llama
15
+ pipeline_tag: text-generation
16
+ quantized_by: TheBloke
17
+ tags:
18
+ - generated_from_trainer
19
+ - code
20
+ - coding
21
+ - llama
22
+ thumbnail: https://huggingface.co/mrm8488/llama-2-coder-7b/resolve/main/llama2-coder-logo-removebg-preview.png
23
+ ---
24
+
25
+ <!-- header start -->
26
+ <!-- 200823 -->
27
+ <div style="width: auto; margin-left: auto; margin-right: auto">
28
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
29
+ </div>
30
+ <div style="display: flex; justify-content: space-between; width: 100%;">
31
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
32
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
33
+ </div>
34
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
35
+ <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>
36
+ </div>
37
+ </div>
38
+ <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>
39
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
40
+ <!-- header end -->
41
+
42
+ # Llama 2 Coder 7B - GGUF
43
+ - Model creator: [mrm8488](https://huggingface.co/mrm8488)
44
+ - Original model: [Llama 2 Coder 7B](https://huggingface.co/mrm8488/llama-2-coder-7b)
45
+
46
+ <!-- description start -->
47
+ ## Description
48
+
49
+ This repo contains GGUF format model files for [mrm8488's Llama 2 Coder 7B](https://huggingface.co/mrm8488/llama-2-coder-7b).
50
+
51
+ <!-- description end -->
52
+ <!-- README_GGUF.md-about-gguf start -->
53
+ ### About GGUF
54
+
55
+ GGUF is a new format introduced by the llama.cpp team on August 21st 2023. It is a replacement for GGML, which is no longer supported by llama.cpp. GGUF offers numerous advantages over GGML, such as better tokenisation, and support for special tokens. It is also supports metadata, and is designed to be extensible.
56
+
57
+ Here is an incomplate list of clients and libraries that are known to support GGUF:
58
+
59
+ * [llama.cpp](https://github.com/ggerganov/llama.cpp). The source project for GGUF. Offers a CLI and a server option.
60
+ * [text-generation-webui](https://github.com/oobabooga/text-generation-webui), the most widely used web UI, with many features and powerful extensions. Supports GPU acceleration.
61
+ * [KoboldCpp](https://github.com/LostRuins/koboldcpp), a fully featured web UI, with GPU accel across all platforms and GPU architectures. Especially good for story telling.
62
+ * [LM Studio](https://lmstudio.ai/), an easy-to-use and powerful local GUI for Windows and macOS (Silicon), with GPU acceleration.
63
+ * [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui), a great web UI with many interesting and unique features, including a full model library for easy model selection.
64
+ * [Faraday.dev](https://faraday.dev/), an attractive and easy to use character-based chat GUI for Windows and macOS (both Silicon and Intel), with GPU acceleration.
65
+ * [ctransformers](https://github.com/marella/ctransformers), a Python library with GPU accel, LangChain support, and OpenAI-compatible AI server.
66
+ * [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), a Python library with GPU accel, LangChain support, and OpenAI-compatible API server.
67
+ * [candle](https://github.com/huggingface/candle), a Rust ML framework with a focus on performance, including GPU support, and ease of use.
68
+
69
+ <!-- README_GGUF.md-about-gguf end -->
70
+ <!-- repositories-available start -->
71
+ ## Repositories available
72
+
73
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GPTQ)
74
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF)
75
+ * [mrm8488's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/mrm8488/llama-2-coder-7b)
76
+ <!-- repositories-available end -->
77
+
78
+ <!-- prompt-template start -->
79
+ ## Prompt template: CodingAssistant
80
+
81
+ ```
82
+ You are a coding assistant that will help the user to resolve the following instruction:
83
+ ### Instruction: {prompt}
84
+
85
+ ### Solution:
86
+
87
+ ```
88
+
89
+ <!-- prompt-template end -->
90
+ <!-- licensing start -->
91
+ ## Licensing
92
+
93
+ The creator of the source model has listed its license as `apache-2.0`, and this quantization has therefore used that same license.
94
+
95
+ 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.
96
+
97
+ In the meantime, any questions regarding licensing, and in particular how these two licenses might interact, should be directed to the original model repository: [mrm8488's Llama 2 Coder 7B](https://huggingface.co/mrm8488/llama-2-coder-7b).
98
+ <!-- licensing end -->
99
+ <!-- compatibility_gguf start -->
100
+ ## Compatibility
101
+
102
+ These quantised GGUFv2 files are compatible with llama.cpp from August 27th onwards, as of commit [d0cee0d36d5be95a0d9088b674dbb27354107221](https://github.com/ggerganov/llama.cpp/commit/d0cee0d36d5be95a0d9088b674dbb27354107221)
103
+
104
+ They are also compatible with many third party UIs and libraries - please see the list at the top of this README.
105
+
106
+ ## Explanation of quantisation methods
107
+ <details>
108
+ <summary>Click to see details</summary>
109
+
110
+ The new methods available are:
111
+ * GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw)
112
+ * GGML_TYPE_Q3_K - "type-0" 3-bit quantization in super-blocks containing 16 blocks, each block having 16 weights. Scales are quantized with 6 bits. This end up using 3.4375 bpw.
113
+ * GGML_TYPE_Q4_K - "type-1" 4-bit quantization in super-blocks containing 8 blocks, each block having 32 weights. Scales and mins are quantized with 6 bits. This ends up using 4.5 bpw.
114
+ * GGML_TYPE_Q5_K - "type-1" 5-bit quantization. Same super-block structure as GGML_TYPE_Q4_K resulting in 5.5 bpw
115
+ * GGML_TYPE_Q6_K - "type-0" 6-bit quantization. Super-blocks with 16 blocks, each block having 16 weights. Scales are quantized with 8 bits. This ends up using 6.5625 bpw
116
+
117
+ Refer to the Provided Files table below to see what files use which methods, and how.
118
+ </details>
119
+ <!-- compatibility_gguf end -->
120
+
121
+ <!-- README_GGUF.md-provided-files start -->
122
+ ## Provided files
123
+
124
+ | Name | Quant method | Bits | Size | Max RAM required | Use case |
125
+ | ---- | ---- | ---- | ---- | ---- | ----- |
126
+ | [llama-2-coder-7b.Q2_K.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q2_K.gguf) | Q2_K | 2 | 2.83 GB| 5.33 GB | smallest, significant quality loss - not recommended for most purposes |
127
+ | [llama-2-coder-7b.Q3_K_S.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q3_K_S.gguf) | Q3_K_S | 3 | 2.95 GB| 5.45 GB | very small, high quality loss |
128
+ | [llama-2-coder-7b.Q3_K_M.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q3_K_M.gguf) | Q3_K_M | 3 | 3.30 GB| 5.80 GB | very small, high quality loss |
129
+ | [llama-2-coder-7b.Q3_K_L.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q3_K_L.gguf) | Q3_K_L | 3 | 3.60 GB| 6.10 GB | small, substantial quality loss |
130
+ | [llama-2-coder-7b.Q4_0.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q4_0.gguf) | Q4_0 | 4 | 3.83 GB| 6.33 GB | legacy; small, very high quality loss - prefer using Q3_K_M |
131
+ | [llama-2-coder-7b.Q4_K_S.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q4_K_S.gguf) | Q4_K_S | 4 | 3.86 GB| 6.36 GB | small, greater quality loss |
132
+ | [llama-2-coder-7b.Q4_K_M.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q4_K_M.gguf) | Q4_K_M | 4 | 4.08 GB| 6.58 GB | medium, balanced quality - recommended |
133
+ | [llama-2-coder-7b.Q5_0.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q5_0.gguf) | Q5_0 | 5 | 4.65 GB| 7.15 GB | legacy; medium, balanced quality - prefer using Q4_K_M |
134
+ | [llama-2-coder-7b.Q5_K_S.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q5_K_S.gguf) | Q5_K_S | 5 | 4.65 GB| 7.15 GB | large, low quality loss - recommended |
135
+ | [llama-2-coder-7b.Q5_K_M.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q5_K_M.gguf) | Q5_K_M | 5 | 4.78 GB| 7.28 GB | large, very low quality loss - recommended |
136
+ | [llama-2-coder-7b.Q6_K.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q6_K.gguf) | Q6_K | 6 | 5.53 GB| 8.03 GB | very large, extremely low quality loss |
137
+ | [llama-2-coder-7b.Q8_0.gguf](https://huggingface.co/TheBloke/Llama-2-Coder-7B-GGUF/blob/main/llama-2-coder-7b.Q8_0.gguf) | Q8_0 | 8 | 7.16 GB| 9.66 GB | very large, extremely low quality loss - not recommended |
138
+
139
+ **Note**: the above RAM figures assume no GPU offloading. If layers are offloaded to the GPU, this will reduce RAM usage and use VRAM instead.
140
+
141
+
142
+
143
+ <!-- README_GGUF.md-provided-files end -->
144
+
145
+ <!-- README_GGUF.md-how-to-run start -->
146
+ ## Example `llama.cpp` command
147
+
148
+ Make sure you are using `llama.cpp` from commit [d0cee0d36d5be95a0d9088b674dbb27354107221](https://github.com/ggerganov/llama.cpp/commit/d0cee0d36d5be95a0d9088b674dbb27354107221) or later.
149
+
150
+ ```shell
151
+ ./main -ngl 32 -m llama-2-coder-7b.q4_K_M.gguf --color -c 4096 --temp 0.7 --repeat_penalty 1.1 -n -1 -p "You are a coding assistant that will help the user to resolve the following instruction:\n### Instruction: {prompt}\n\n### Solution:"
152
+ ```
153
+
154
+ Change `-ngl 32` to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.
155
+
156
+ Change `-c 4096` to the desired sequence length. For extended sequence models - eg 8K, 16K, 32K - the necessary RoPE scaling parameters are read from the GGUF file and set by llama.cpp automatically.
157
+
158
+ If you want to have a chat-style conversation, replace the `-p <PROMPT>` argument with `-i -ins`
159
+
160
+ For other parameters and how to use them, please refer to [the llama.cpp documentation](https://github.com/ggerganov/llama.cpp/blob/master/examples/main/README.md)
161
+
162
+ ## How to run in `text-generation-webui`
163
+
164
+ Further instructions here: [text-generation-webui/docs/llama.cpp.md](https://github.com/oobabooga/text-generation-webui/blob/main/docs/llama.cpp.md).
165
+
166
+ ## How to run from Python code
167
+
168
+ You can use GGUF models from Python using the [llama-cpp-python](https://github.com/abetlen/llama-cpp-python) or [ctransformers](https://github.com/marella/ctransformers) libraries.
169
+
170
+ ### How to load this model from Python using ctransformers
171
+
172
+ #### First install the package
173
+
174
+ ```bash
175
+ # Base ctransformers with no GPU acceleration
176
+ pip install ctransformers>=0.2.24
177
+ # Or with CUDA GPU acceleration
178
+ pip install ctransformers[cuda]>=0.2.24
179
+ # Or with ROCm GPU acceleration
180
+ CT_HIPBLAS=1 pip install ctransformers>=0.2.24 --no-binary ctransformers
181
+ # Or with Metal GPU acceleration for macOS systems
182
+ CT_METAL=1 pip install ctransformers>=0.2.24 --no-binary ctransformers
183
+ ```
184
+
185
+ #### Simple example code to load one of these GGUF models
186
+
187
+ ```python
188
+ from ctransformers import AutoModelForCausalLM
189
+
190
+ # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
191
+ llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-Coder-7B-GGUF", model_file="llama-2-coder-7b.q4_K_M.gguf", model_type="llama", gpu_layers=50)
192
+
193
+ print(llm("AI is going to"))
194
+ ```
195
+
196
+ ## How to use with LangChain
197
+
198
+ Here's guides on using llama-cpp-python or ctransformers with LangChain:
199
+
200
+ * [LangChain + llama-cpp-python](https://python.langchain.com/docs/integrations/llms/llamacpp)
201
+ * [LangChain + ctransformers](https://python.langchain.com/docs/integrations/providers/ctransformers)
202
+
203
+ <!-- README_GGUF.md-how-to-run end -->
204
+
205
+ <!-- footer start -->
206
+ <!-- 200823 -->
207
+ ## Discord
208
+
209
+ For further support, and discussions on these models and AI in general, join us at:
210
+
211
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
212
+
213
+ ## Thanks, and how to contribute
214
+
215
+ Thanks to the [chirper.ai](https://chirper.ai) team!
216
+
217
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
218
+
219
+ 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.
220
+
221
+ 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.
222
+
223
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
224
+
225
+ * Patreon: https://patreon.com/TheBlokeAI
226
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
227
+
228
+ **Special thanks to**: Aemon Algiz.
229
+
230
+ **Patreon special mentions**: Russ Johnson, J, alfie_i, Alex, NimbleBox.ai, Chadd, Mandus, Nikolai Manek, Ken Nordquist, ya boyyy, Illia Dulskyi, Viktor Bowallius, vamX, Iucharbius, zynix, Magnesian, Clay Pascal, Pierre Kircher, Enrico Ros, Tony Hughes, Elle, Andrey, knownsqashed, Deep Realms, Jerry Meng, Lone Striker, Derek Yates, Pyrater, Mesiah Bishop, James Bentley, Femi Adebogun, Brandon Frisco, SuperWojo, Alps Aficionado, Michael Dempsey, Vitor Caleffi, Will Dee, Edmond Seymore, usrbinkat, LangChain4j, Kacper Wikieł, Luke Pendergrass, John Detwiler, theTransient, Nathan LeClaire, Tiffany J. Kim, biorpg, Eugene Pentland, Stanislav Ovsiannikov, Fred von Graf, terasurfer, Kalila, Dan Guido, Nitin Borwankar, 阿明, Ai Maven, John Villwock, Gabriel Puliatti, Stephen Murray, Asp the Wyvern, danny, Chris Smitley, ReadyPlayerEmma, S_X, Daniel P. Andersen, Olakabola, Jeffrey Morgan, Imad Khwaja, Caitlyn Gatomon, webtim, Alicia Loh, Trenton Dambrowitz, Swaroop Kallakuri, Erik Bjäreholt, Leonard Tan, Spiking Neurons AB, Luke @flexchar, Ajan Kanaga, Thomas Belote, Deo Leter, RoA, Willem Michiel, transmissions 11, subjectnull, Matthew Berman, Joseph William Delisle, David Ziegler, Michael Davis, Johann-Peter Hartmann, Talal Aujan, senxiiz, Artur Olbinski, Rainer Wilmers, Spencer Kim, Fen Risland, Cap'n Zoog, Rishabh Srivastava, Michael Levine, Geoffrey Montalvo, Sean Connelly, Alexandros Triantafyllidis, Pieter, Gabriel Tamborski, Sam, Subspace Studios, Junyu Yang, Pedro Madruga, Vadim, Cory Kujawski, K, Raven Klaugh, Randy H, Mano Prime, Sebastain Graf, Space Cruiser
231
+
232
+
233
+ Thank you to all my generous patrons and donaters!
234
+
235
+ And thank you again to a16z for their generous grant.
236
+
237
+ <!-- footer end -->
238
+
239
+ <!-- original-model-card start -->
240
+ # Original model card: mrm8488's Llama 2 Coder 7B
241
+
242
+
243
+ <div style="text-align:center;width:250px;height:250px;">
244
+ <img src="https://huggingface.co/mrm8488/llama-2-coder-7b/resolve/main/llama2-coder-logo-removebg-preview.png" alt="llama-2 coder logo"">
245
+ </div>
246
+
247
+
248
+ # LlaMa 2 Coder 🦙👩‍💻
249
+ **LlaMa-2 7b** fine-tuned on the **CodeAlpaca 20k instructions dataset** by using the method **QLoRA** with [PEFT](https://github.com/huggingface/peft) library.
250
+
251
+ ## Model description 🧠
252
+
253
+ [Llama-2](https://huggingface.co/meta-llama/Llama-2-7b)
254
+
255
+ Llama 2 is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters.
256
+ Meta developed and publicly released the Llama 2 family of large language models (LLMs), a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters. Our fine-tuned LLMs, called Llama-2-Chat, are optimized for dialogue use cases. Llama-2-Chat models outperform open-source chat models on most benchmarks we tested, and in our human evaluations for helpfulness and safety, are on par with some popular closed-source models like ChatGPT and PaLM.
257
+
258
+
259
+ ## Training and evaluation data 📚
260
+
261
+ [CodeAlpaca_20K](https://huggingface.co/datasets/HuggingFaceH4/CodeAlpaca_20K): contains 20K instruction-following data used for fine-tuning the Code Alpaca model.
262
+
263
+
264
+ ### Training hyperparameters ⚙
265
+
266
+ ```py
267
+ optim="paged_adamw_32bit",
268
+ num_train_epochs = 2,
269
+ eval_steps=50,
270
+ save_steps=50,
271
+ evaluation_strategy="steps",
272
+ save_strategy="steps",
273
+ save_total_limit=2,
274
+ seed=66,
275
+ load_best_model_at_end=True,
276
+ logging_steps=1,
277
+ learning_rate=2e-4,
278
+ fp16=True,
279
+ bf16=False,
280
+ max_grad_norm=0.3,
281
+ warmup_ratio=0.03,
282
+ group_by_length=True,
283
+ lr_scheduler_type="constant"
284
+ ```
285
+
286
+ ### Training results 🗒️
287
+
288
+
289
+ | Step | Training Loss | Validation Loss |
290
+ |------|----------|----------|
291
+ | 50 | 0.624400 | 0.600070 |
292
+ | 100 | 0.634100 | 0.592757 |
293
+ | 150 | 0.545800 | 0.586652 |
294
+ | 200 | 0.572500 | 0.577525 |
295
+ | 250 | 0.528000 | 0.590118 |
296
+
297
+
298
+ ### Eval results 📊
299
+
300
+ WIP
301
+
302
+
303
+ ### Example of usage 👩‍💻
304
+ ```py
305
+ import torch
306
+ from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
307
+
308
+ model_id = "mrm8488/llama-2-coder-7b"
309
+
310
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
311
+
312
+ model = AutoModelForCausalLM.from_pretrained(model_id).to("cuda")
313
+
314
+ def create_prompt(instruction):
315
+ system = "You are a coding assistant that will help the user to resolve the following instruction:"
316
+ instruction = "### Instruction: " + instruction
317
+ return system + "\n" + instruction + "\n\n" + "### Solution:" + "\n"
318
+
319
+ def generate(
320
+ instruction,
321
+ max_new_tokens=128,
322
+ temperature=0.1,
323
+ top_p=0.75,
324
+ top_k=40,
325
+ num_beams=4,
326
+ **kwargs,
327
+ ):
328
+ prompt = create_prompt(instruction)
329
+ print(prompt)
330
+ inputs = tokenizer(prompt, return_tensors="pt")
331
+ input_ids = inputs["input_ids"].to("cuda")
332
+ attention_mask = inputs["attention_mask"].to("cuda")
333
+ generation_config = GenerationConfig(
334
+ temperature=temperature,
335
+ top_p=top_p,
336
+ top_k=top_k,
337
+ num_beams=num_beams,
338
+ **kwargs,
339
+ )
340
+ with torch.no_grad():
341
+ generation_output = model.generate(
342
+ input_ids=input_ids,
343
+ attention_mask=attention_mask,
344
+ generation_config=generation_config,
345
+ return_dict_in_generate=True,
346
+ output_scores=True,
347
+ max_new_tokens=max_new_tokens,
348
+ early_stopping=True
349
+ )
350
+ s = generation_output.sequences[0]
351
+ output = tokenizer.decode(s)
352
+ return output.split("### Solution:")[1].lstrip("\n")
353
+
354
+ instruction = """
355
+ Edit the following XML code to add a navigation bar to the top of a web page
356
+ <html>
357
+ <head>
358
+ <title>CliBrAIn</title>
359
+ </head>
360
+ """
361
+ print(generate(instruction))
362
+ ```
363
+
364
+ ### Citation
365
+
366
+ ```
367
+ @misc {manuel_romero_2023,
368
+ author = { {Manuel Romero} },
369
+ title = { llama-2-coder-7b (Revision d30d193) },
370
+ year = 2023,
371
+ url = { https://huggingface.co/mrm8488/llama-2-coder-7b },
372
+ doi = { 10.57967/hf/0931 },
373
+ publisher = { Hugging Face }
374
+ }
375
+ ```
376
+
377
+ <!-- original-model-card end -->