TheBloke commited on
Commit
dfd367d
1 Parent(s): b8da808

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +614 -0
README.md ADDED
@@ -0,0 +1,614 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: microsoft/Orca-2-7b
3
+ inference: false
4
+ license: other
5
+ model_creator: Microsoft
6
+ model_name: Orca 2 7B
7
+ model_type: llama
8
+ pipeline_tag: text-generation
9
+ prompt_template: '<|im_start|>system
10
+
11
+ {system_message}<|im_end|>
12
+
13
+ <|im_start|>user
14
+
15
+ {prompt}<|im_end|>
16
+
17
+ <|im_start|>assistant
18
+
19
+ '
20
+ quantized_by: TheBloke
21
+ tags:
22
+ - orca
23
+ - orca2
24
+ - microsoft
25
+ ---
26
+ <!-- markdownlint-disable MD041 -->
27
+
28
+ <!-- header start -->
29
+ <!-- 200823 -->
30
+ <div style="width: auto; margin-left: auto; margin-right: auto">
31
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
32
+ </div>
33
+ <div style="display: flex; justify-content: space-between; width: 100%;">
34
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
35
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
36
+ </div>
37
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
38
+ <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>
39
+ </div>
40
+ </div>
41
+ <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>
42
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
43
+ <!-- header end -->
44
+
45
+ # Orca 2 7B - GPTQ
46
+ - Model creator: [Microsoft](https://huggingface.co/microsoft)
47
+ - Original model: [Orca 2 7B](https://huggingface.co/microsoft/Orca-2-7b)
48
+
49
+ <!-- description start -->
50
+ # Description
51
+
52
+ This repo contains GPTQ model files for [Microsoft's Orca 2 7B](https://huggingface.co/microsoft/Orca-2-7b).
53
+
54
+ Multiple GPTQ parameter permutations are provided; see Provided Files below for details of the options provided, their parameters, and the software used to create them.
55
+
56
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
57
+
58
+ <!-- description end -->
59
+ <!-- repositories-available start -->
60
+ ## Repositories available
61
+
62
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/Orca-2-7B-AWQ)
63
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ)
64
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/Orca-2-7B-GGUF)
65
+ * [Microsoft's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/microsoft/Orca-2-7b)
66
+ <!-- repositories-available end -->
67
+
68
+ <!-- prompt-template start -->
69
+ ## Prompt template: ChatML
70
+
71
+ ```
72
+ <|im_start|>system
73
+ {system_message}<|im_end|>
74
+ <|im_start|>user
75
+ {prompt}<|im_end|>
76
+ <|im_start|>assistant
77
+
78
+ ```
79
+
80
+ <!-- prompt-template end -->
81
+
82
+
83
+
84
+ <!-- README_GPTQ.md-compatible clients start -->
85
+ ## Known compatible clients / servers
86
+
87
+ These GPTQ models are known to work in the following inference servers/webuis.
88
+
89
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
90
+ - [KoboldAI United](https://github.com/henk717/koboldai)
91
+ - [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui)
92
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
93
+
94
+ This may not be a complete list; if you know of others, please let me know!
95
+ <!-- README_GPTQ.md-compatible clients end -->
96
+
97
+ <!-- README_GPTQ.md-provided-files start -->
98
+ ## Provided files, and GPTQ parameters
99
+
100
+ Multiple quantisation parameters are provided, to allow you to choose the best one for your hardware and requirements.
101
+
102
+ Each separate quant is in a different branch. See below for instructions on fetching from different branches.
103
+
104
+ Most GPTQ files are made with AutoGPTQ. Mistral models are currently made with Transformers.
105
+
106
+ <details>
107
+ <summary>Explanation of GPTQ parameters</summary>
108
+
109
+ - Bits: The bit size of the quantised model.
110
+ - GS: GPTQ group size. Higher numbers use less VRAM, but have lower quantisation accuracy. "None" is the lowest possible value.
111
+ - Act Order: True or False. Also known as `desc_act`. True results in better quantisation accuracy. Some GPTQ clients have had issues with models that use Act Order plus Group Size, but this is generally resolved now.
112
+ - Damp %: A GPTQ parameter that affects how samples are processed for quantisation. 0.01 is default, but 0.1 results in slightly better accuracy.
113
+ - GPTQ dataset: The calibration dataset used during quantisation. Using a dataset more appropriate to the model's training can improve quantisation accuracy. Note that the GPTQ calibration dataset is not the same as the dataset used to train the model - please refer to the original model repo for details of the training dataset(s).
114
+ - Sequence Length: The length of the dataset sequences used for quantisation. Ideally this is the same as the model sequence length. For some very long sequence models (16+K), a lower sequence length may have to be used. Note that a lower sequence length does not limit the sequence length of the quantised model. It only impacts the quantisation accuracy on longer inference sequences.
115
+ - ExLlama Compatibility: Whether this file can be loaded with ExLlama, which currently only supports Llama and Mistral models in 4-bit.
116
+
117
+ </details>
118
+
119
+ | Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
120
+ | ------ | ---- | -- | --------- | ------ | ------------ | ------- | ---- | ------- | ---- |
121
+ | [main](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ/tree/main) | 4 | 128 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4/viewer/allenai--c4) | 4096 | 3.90 GB | Yes | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. |
122
+ | [gptq-4bit-32g-actorder_True](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ/tree/gptq-4bit-32g-actorder_True) | 4 | 32 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4/viewer/allenai--c4) | 4096 | 4.28 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
123
+ | [gptq-8bit--1g-actorder_True](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ/tree/gptq-8bit--1g-actorder_True) | 8 | None | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4/viewer/allenai--c4) | 4096 | 7.01 GB | No | 8-bit, with Act Order. No group size, to lower VRAM requirements. |
124
+ | [gptq-8bit-128g-actorder_True](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ/tree/gptq-8bit-128g-actorder_True) | 8 | 128 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4/viewer/allenai--c4) | 4096 | 7.16 GB | No | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. |
125
+ | [gptq-8bit-32g-actorder_True](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ/tree/gptq-8bit-32g-actorder_True) | 8 | 32 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4/viewer/allenai--c4) | 4096 | 7.62 GB | No | 8-bit, with group size 32g and Act Order for maximum inference quality. |
126
+ | [gptq-4bit-64g-actorder_True](https://huggingface.co/TheBloke/Orca-2-7B-GPTQ/tree/gptq-4bit-64g-actorder_True) | 4 | 64 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4/viewer/allenai--c4) | 4096 | 4.02 GB | Yes | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. |
127
+
128
+ <!-- README_GPTQ.md-provided-files end -->
129
+
130
+ <!-- README_GPTQ.md-download-from-branches start -->
131
+ ## How to download, including from branches
132
+
133
+ ### In text-generation-webui
134
+
135
+ To download from the `main` branch, enter `TheBloke/Orca-2-7B-GPTQ` in the "Download model" box.
136
+
137
+ To download from another branch, add `:branchname` to the end of the download name, eg `TheBloke/Orca-2-7B-GPTQ:gptq-4bit-32g-actorder_True`
138
+
139
+ ### From the command line
140
+
141
+ I recommend using the `huggingface-hub` Python library:
142
+
143
+ ```shell
144
+ pip3 install huggingface-hub
145
+ ```
146
+
147
+ To download the `main` branch to a folder called `Orca-2-7B-GPTQ`:
148
+
149
+ ```shell
150
+ mkdir Orca-2-7B-GPTQ
151
+ huggingface-cli download TheBloke/Orca-2-7B-GPTQ --local-dir Orca-2-7B-GPTQ --local-dir-use-symlinks False
152
+ ```
153
+
154
+ To download from a different branch, add the `--revision` parameter:
155
+
156
+ ```shell
157
+ mkdir Orca-2-7B-GPTQ
158
+ huggingface-cli download TheBloke/Orca-2-7B-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir Orca-2-7B-GPTQ --local-dir-use-symlinks False
159
+ ```
160
+
161
+ <details>
162
+ <summary>More advanced huggingface-cli download usage</summary>
163
+
164
+ If you remove the `--local-dir-use-symlinks False` parameter, the files will instead be stored in the central Hugging Face cache directory (default location on Linux is: `~/.cache/huggingface`), and symlinks will be added to the specified `--local-dir`, pointing to their real location in the cache. This allows for interrupted downloads to be resumed, and allows you to quickly clone the repo to multiple places on disk without triggering a download again. The downside, and the reason why I don't list that as the default option, is that the files are then hidden away in a cache folder and it's harder to know where your disk space is being used, and to clear it up if/when you want to remove a download model.
165
+
166
+ The cache location can be changed with the `HF_HOME` environment variable, and/or the `--cache-dir` parameter to `huggingface-cli`.
167
+
168
+ For more documentation on downloading with `huggingface-cli`, please see: [HF -> Hub Python Library -> Download files -> Download from the CLI](https://huggingface.co/docs/huggingface_hub/guides/download#download-from-the-cli).
169
+
170
+ To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
171
+
172
+ ```shell
173
+ pip3 install hf_transfer
174
+ ```
175
+
176
+ And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
177
+
178
+ ```shell
179
+ mkdir Orca-2-7B-GPTQ
180
+ HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/Orca-2-7B-GPTQ --local-dir Orca-2-7B-GPTQ --local-dir-use-symlinks False
181
+ ```
182
+
183
+ Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
184
+ </details>
185
+
186
+ ### With `git` (**not** recommended)
187
+
188
+ To clone a specific branch with `git`, use a command like this:
189
+
190
+ ```shell
191
+ git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/Orca-2-7B-GPTQ
192
+ ```
193
+
194
+ Note that using Git with HF repos is strongly discouraged. It will be much slower than using `huggingface-hub`, and will use twice as much disk space as it has to store the model files twice (it stores every byte both in the intended target folder, and again in the `.git` folder as a blob.)
195
+
196
+ <!-- README_GPTQ.md-download-from-branches end -->
197
+ <!-- README_GPTQ.md-text-generation-webui start -->
198
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
199
+
200
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
201
+
202
+ 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.
203
+
204
+ 1. Click the **Model tab**.
205
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/Orca-2-7B-GPTQ`.
206
+
207
+ - To download from a specific branch, enter for example `TheBloke/Orca-2-7B-GPTQ:gptq-4bit-32g-actorder_True`
208
+ - see Provided Files above for the list of branches for each option.
209
+
210
+ 3. Click **Download**.
211
+ 4. The model will start downloading. Once it's finished it will say "Done".
212
+ 5. In the top left, click the refresh icon next to **Model**.
213
+ 6. In the **Model** dropdown, choose the model you just downloaded: `Orca-2-7B-GPTQ`
214
+ 7. The model will automatically load, and is now ready for use!
215
+ 8. 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.
216
+
217
+ - Note that you do not need to and should not set manual GPTQ parameters any more. These are set automatically from the file `quantize_config.json`.
218
+
219
+ 9. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
220
+
221
+ <!-- README_GPTQ.md-text-generation-webui end -->
222
+
223
+ <!-- README_GPTQ.md-use-from-tgi start -->
224
+ ## Serving this model from Text Generation Inference (TGI)
225
+
226
+ It's recommended to use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
227
+
228
+ Example Docker parameters:
229
+
230
+ ```shell
231
+ --model-id TheBloke/Orca-2-7B-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
232
+ ```
233
+
234
+ Example Python code for interfacing with TGI (requires huggingface-hub 0.17.0 or later):
235
+
236
+ ```shell
237
+ pip3 install huggingface-hub
238
+ ```
239
+
240
+ ```python
241
+ from huggingface_hub import InferenceClient
242
+
243
+ endpoint_url = "https://your-endpoint-url-here"
244
+
245
+ prompt = "Tell me about AI"
246
+ prompt_template=f'''<|im_start|>system
247
+ {system_message}<|im_end|>
248
+ <|im_start|>user
249
+ {prompt}<|im_end|>
250
+ <|im_start|>assistant
251
+ '''
252
+
253
+ client = InferenceClient(endpoint_url)
254
+ response = client.text_generation(prompt,
255
+ max_new_tokens=128,
256
+ do_sample=True,
257
+ temperature=0.7,
258
+ top_p=0.95,
259
+ top_k=40,
260
+ repetition_penalty=1.1)
261
+
262
+ print(f"Model output: {response}")
263
+ ```
264
+ <!-- README_GPTQ.md-use-from-tgi end -->
265
+ <!-- README_GPTQ.md-use-from-python start -->
266
+ ## Python code example: inference from this GPTQ model
267
+
268
+ ### Install the necessary packages
269
+
270
+ Requires: Transformers 4.33.0 or later, Optimum 1.12.0 or later, and AutoGPTQ 0.4.2 or later.
271
+
272
+ ```shell
273
+ pip3 install --upgrade transformers optimum
274
+ # If using PyTorch 2.1 + CUDA 12.x:
275
+ pip3 install --upgrade auto-gptq
276
+ # or, if using PyTorch 2.1 + CUDA 11.x:
277
+ pip3 install --upgrade auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
278
+ ```
279
+
280
+ If you are using PyTorch 2.0, you will need to install AutoGPTQ from source. Likewise if you have problems with the pre-built wheels, you should try building from source:
281
+
282
+ ```shell
283
+ pip3 uninstall -y auto-gptq
284
+ git clone https://github.com/PanQiWei/AutoGPTQ
285
+ cd AutoGPTQ
286
+ git checkout v0.5.1
287
+ pip3 install .
288
+ ```
289
+
290
+ ### Example Python code
291
+
292
+ ```python
293
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
294
+
295
+ model_name_or_path = "TheBloke/Orca-2-7B-GPTQ"
296
+ # To use a different branch, change revision
297
+ # For example: revision="gptq-4bit-32g-actorder_True"
298
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
299
+ device_map="auto",
300
+ trust_remote_code=False,
301
+ revision="main")
302
+
303
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
304
+
305
+ prompt = "Tell me about AI"
306
+ prompt_template=f'''<|im_start|>system
307
+ {system_message}<|im_end|>
308
+ <|im_start|>user
309
+ {prompt}<|im_end|>
310
+ <|im_start|>assistant
311
+ '''
312
+
313
+ print("\n\n*** Generate:")
314
+
315
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
316
+ output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
317
+ print(tokenizer.decode(output[0]))
318
+
319
+ # Inference can also be done using transformers' pipeline
320
+
321
+ print("*** Pipeline:")
322
+ pipe = pipeline(
323
+ "text-generation",
324
+ model=model,
325
+ tokenizer=tokenizer,
326
+ max_new_tokens=512,
327
+ do_sample=True,
328
+ temperature=0.7,
329
+ top_p=0.95,
330
+ top_k=40,
331
+ repetition_penalty=1.1
332
+ )
333
+
334
+ print(pipe(prompt_template)[0]['generated_text'])
335
+ ```
336
+ <!-- README_GPTQ.md-use-from-python end -->
337
+
338
+ <!-- README_GPTQ.md-compatibility start -->
339
+ ## Compatibility
340
+
341
+ The files provided are tested to work with Transformers. For non-Mistral models, AutoGPTQ can also be used directly.
342
+
343
+ [ExLlama](https://github.com/turboderp/exllama) is compatible with Llama and Mistral models in 4-bit. Please see the Provided Files table above for per-file compatibility.
344
+
345
+ For a list of clients/servers, please see "Known compatible clients / servers", above.
346
+ <!-- README_GPTQ.md-compatibility end -->
347
+
348
+ <!-- footer start -->
349
+ <!-- 200823 -->
350
+ ## Discord
351
+
352
+ For further support, and discussions on these models and AI in general, join us at:
353
+
354
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
355
+
356
+ ## Thanks, and how to contribute
357
+
358
+ Thanks to the [chirper.ai](https://chirper.ai) team!
359
+
360
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
361
+
362
+ 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.
363
+
364
+ 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.
365
+
366
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
367
+
368
+ * Patreon: https://patreon.com/TheBlokeAI
369
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
370
+
371
+ **Special thanks to**: Aemon Algiz.
372
+
373
+ **Patreon special mentions**: Brandon Frisco, LangChain4j, Spiking Neurons AB, transmissions 11, Joseph William Delisle, Nitin Borwankar, Willem Michiel, Michael Dempsey, vamX, Jeffrey Morgan, zynix, jjj, Omer Bin Jawed, Sean Connelly, jinyuan sun, Jeromy Smith, Shadi, Pawan Osman, Chadd, Elijah Stavena, Illia Dulskyi, Sebastain Graf, Stephen Murray, terasurfer, Edmond Seymore, Celu Ramasamy, Mandus, Alex, biorpg, Ajan Kanaga, Clay Pascal, Raven Klaugh, 阿明, K, ya boyyy, usrbinkat, Alicia Loh, John Villwock, ReadyPlayerEmma, Chris Smitley, Cap'n Zoog, fincy, GodLy, S_X, sidney chen, Cory Kujawski, OG, Mano Prime, AzureBlack, Pieter, Kalila, Spencer Kim, Tom X Nguyen, Stanislav Ovsiannikov, Michael Levine, Andrey, Trailburnt, Vadim, Enrico Ros, Talal Aujan, Brandon Phillips, Jack West, Eugene Pentland, Michael Davis, Will Dee, webtim, Jonathan Leane, Alps Aficionado, Rooh Singh, Tiffany J. Kim, theTransient, Luke @flexchar, Elle, Caitlyn Gatomon, Ari Malik, subjectnull, Johann-Peter Hartmann, Trenton Dambrowitz, Imad Khwaja, Asp the Wyvern, Emad Mostaque, Rainer Wilmers, Alexandros Triantafyllidis, Nicholas, Pedro Madruga, SuperWojo, Harry Royden McLaughlin, James Bentley, Olakabola, David Ziegler, Ai Maven, Jeff Scroggin, Nikolai Manek, Deo Leter, Matthew Berman, Fen Risland, Ken Nordquist, Manuel Alberto Morcote, Luke Pendergrass, TL, Fred von Graf, Randy H, Dan Guido, NimbleBox.ai, Vitor Caleffi, Gabriel Tamborski, knownsqashed, Lone Striker, Erik Bjäreholt, John Detwiler, Leonard Tan, Iucharbius
374
+
375
+
376
+ Thank you to all my generous patrons and donaters!
377
+
378
+ And thank you again to a16z for their generous grant.
379
+
380
+ <!-- footer end -->
381
+
382
+ # Original model card: Microsoft's Orca 2 7B
383
+
384
+
385
+ # Orca 2
386
+
387
+ <!-- Provide a quick summary of what the model is/does. -->
388
+
389
+ Orca 2 is a helpful assistant that is built for research purposes only and provides a single turn response
390
+ in tasks such as reasoning over user given data, reading comprehension, math problem solving and text summarization.
391
+ The model is designed to excel particularly in reasoning.
392
+
393
+ We open-source Orca 2 to encourage further research on the development, evaluation, and alignment of smaller LMs.
394
+
395
+ ## What is Orca 2’s intended use(s)?
396
+
397
+ + Orca 2 is built for research purposes only.
398
+ + The main purpose is to allow the research community to assess its abilities and to provide a foundation for building better frontier models.
399
+
400
+ ## How was Orca 2 evaluated?
401
+
402
+ + Orca 2 has been evaluated on a large number of tasks ranging from reasoning to grounding and safety. Please refer
403
+ to Section 6 and Appendix in the [Orca 2 paper](https://arxiv.org/pdf/2311.11045.pdf) for details on evaluations.
404
+
405
+ ## Model Details
406
+
407
+ Orca 2 is a finetuned version of LLAMA-2. Orca 2’s training data is a synthetic dataset that was created to enhance the small model’s reasoning abilities.
408
+ All synthetic training data was moderated using the Microsoft Azure content filters. More details about the model can be found in the [Orca 2 paper](https://arxiv.org/pdf/2311.11045.pdf).
409
+
410
+ Please refer to LLaMA-2 technical report for details on the model architecture.
411
+
412
+ ## License
413
+
414
+ Orca 2 is licensed under the [Microsoft Research License](LICENSE).
415
+
416
+ Llama 2 is licensed under the [LLAMA 2 Community License](https://ai.meta.com/llama/license/), Copyright © Meta Platforms, Inc. All Rights Reserved.
417
+
418
+ ## Bias, Risks, and Limitations
419
+
420
+ Orca 2, built upon the LLaMA 2 model family, retains many of its limitations, as well as the
421
+ common limitations of other large language models or limitation caused by its training
422
+ process, including:
423
+
424
+ **Data Biases**: Large language models, trained on extensive data, can inadvertently carry
425
+ biases present in the source data. Consequently, the models may generate outputs that could
426
+ be potentially biased or unfair.
427
+
428
+ **Lack of Contextual Understanding**: Despite their impressive capabilities in language understanding and generation, these models exhibit limited real-world understanding, resulting
429
+ in potential inaccuracies or nonsensical responses.
430
+
431
+ **Lack of Transparency**: Due to the complexity and size, large language models can act
432
+ as “black boxes”, making it difficult to comprehend the rationale behind specific outputs or
433
+ decisions. We recommend reviewing transparency notes from Azure for more information.
434
+
435
+ **Content Harms**: There are various types of content harms that large language models
436
+ can cause. It is important to be aware of them when using these models, and to take
437
+ actions to prevent them. It is recommended to leverage various content moderation services
438
+ provided by different companies and institutions. On an important note, we hope for better
439
+ regulations and standards from government and technology leaders around content harms
440
+ for AI technologies in future. We value and acknowledge the important role that research
441
+ and open source community can play in this direction.
442
+
443
+ **Hallucination**: It is important to be aware and cautious not to entirely rely on a given
444
+ language model for critical decisions or information that might have deep impact as it is
445
+ not obvious how to prevent these models from fabricating content. Moreover, it is not clear
446
+ whether small models may be more susceptible to hallucination in ungrounded generation
447
+ use cases due to their smaller sizes and hence reduced memorization capacities. This is an
448
+ active research topic and we hope there will be more rigorous measurement, understanding
449
+ and mitigations around this topic.
450
+
451
+ **Potential for Misuse**: Without suitable safeguards, there is a risk that these models could
452
+ be maliciously used for generating disinformation or harmful content.
453
+
454
+ **Data Distribution**: Orca 2’s performance is likely to correlate strongly with the distribution
455
+ of the tuning data. This correlation might limit its accuracy in areas underrepresented in
456
+ the training dataset such as math, coding, and reasoning.
457
+
458
+ **System messages**: Orca 2 demonstrates variance in performance depending on the system
459
+ instructions. Additionally, the stochasticity introduced by the model size may lead to
460
+ generation of non-deterministic responses to different system instructions.
461
+
462
+ **Zero-Shot Settings**: Orca 2 was trained on data that mostly simulate zero-shot settings.
463
+ While the model demonstrate very strong performance in zero-shot settings, it does not show
464
+ the same gains of using few-shot learning compared to other, specially larger, models.
465
+
466
+ **Synthetic data**: As Orca 2 is trained on synthetic data, it could inherit both the advantages
467
+ and shortcomings of the models and methods used for data generation. We posit that Orca
468
+ 2 benefits from the safety measures incorporated during training and safety guardrails (e.g.,
469
+ content filter) within the Azure OpenAI API. However, detailed studies are required for
470
+ better quantification of such risks.
471
+
472
+ This model is solely designed for research settings, and its testing has only been carried
473
+ out in such environments. It should not be used in downstream applications, as additional
474
+ analysis is needed to assess potential harm or bias in the proposed application.
475
+
476
+ ## Getting started with Orca 2
477
+
478
+ **Inference with Hugging Face library**
479
+
480
+ ```python
481
+ import torch
482
+ import transformers
483
+
484
+ if torch.cuda.is_available():
485
+ torch.set_default_device("cuda")
486
+ else:
487
+ torch.set_default_device("cpu")
488
+
489
+ model = transformers.AutoModelForCausalLM.from_pretrained("microsoft/Orca-2-7b", device_map='auto')
490
+
491
+ # https://github.com/huggingface/transformers/issues/27132
492
+ # please use the slow tokenizer since fast and slow tokenizer produces different tokens
493
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
494
+ "microsoft/Orca-2-7b",
495
+ use_fast=False,
496
+ )
497
+
498
+ system_message = "You are Orca, an AI language model created by Microsoft. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."
499
+ user_message = "How can you determine if a restaurant is popular among locals or mainly attracts tourists, and why might this information be useful?"
500
+
501
+ prompt = f"<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n{user_message}<|im_end|>\n<|im_start|>assistant"
502
+
503
+ inputs = tokenizer(prompt, return_tensors='pt')
504
+ output_ids = model.generate(inputs["input_ids"],)
505
+ answer = tokenizer.batch_decode(output_ids)[0]
506
+
507
+ print(answer)
508
+
509
+ # This example continues showing how to add a second turn message by the user to the conversation
510
+ second_turn_user_message = "Give me a list of the key points of your first answer."
511
+
512
+ # we set add_special_tokens=False because we dont want to automatically add a bos_token between messages
513
+ second_turn_message_in_markup = f"\n<|im_start|>user\n{second_turn_user_message}<|im_end|>\n<|im_start|>assistant"
514
+ second_turn_tokens = tokenizer(second_turn_message_in_markup, return_tensors='pt', add_special_tokens=False)
515
+ second_turn_input = torch.cat([output_ids, second_turn_tokens['input_ids']], dim=1)
516
+
517
+ output_ids_2 = model.generate(second_turn_input,)
518
+ second_turn_answer = tokenizer.batch_decode(output_ids_2)[0]
519
+
520
+ print(second_turn_answer)
521
+ ```
522
+
523
+
524
+ **Safe inference with Azure AI Content Safety**
525
+
526
+ The usage of [Azure AI Content Safety](https://azure.microsoft.com/en-us/products/ai-services/ai-content-safety/) on top of model prediction is strongly encouraged
527
+ and can help preventing some of content harms. Azure AI Content Safety is a content moderation platform
528
+ that uses AI to moderate content. By having Azure AI Content Safety on the output of Orca 2,
529
+ the model output can be moderated by scanning it for different harm categories including sexual content, violence, hate, and
530
+ self-harm with multiple severity levels and multi-lingual detection.
531
+
532
+ ```python
533
+ import os
534
+ import math
535
+ import transformers
536
+ import torch
537
+
538
+ from azure.ai.contentsafety import ContentSafetyClient
539
+ from azure.core.credentials import AzureKeyCredential
540
+ from azure.core.exceptions import HttpResponseError
541
+ from azure.ai.contentsafety.models import AnalyzeTextOptions
542
+
543
+ CONTENT_SAFETY_KEY = os.environ["CONTENT_SAFETY_KEY"]
544
+ CONTENT_SAFETY_ENDPOINT = os.environ["CONTENT_SAFETY_ENDPOINT"]
545
+
546
+ # We use Azure AI Content Safety to filter out any content that reaches "Medium" threshold
547
+ # For more information: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/
548
+ def should_filter_out(input_text, threshold=4):
549
+ # Create an Content Safety client
550
+ client = ContentSafetyClient(CONTENT_SAFETY_ENDPOINT, AzureKeyCredential(CONTENT_SAFETY_KEY))
551
+
552
+ # Construct a request
553
+ request = AnalyzeTextOptions(text=input_text)
554
+
555
+ # Analyze text
556
+ try:
557
+ response = client.analyze_text(request)
558
+ except HttpResponseError as e:
559
+ print("Analyze text failed.")
560
+ if e.error:
561
+ print(f"Error code: {e.error.code}")
562
+ print(f"Error message: {e.error.message}")
563
+ raise
564
+ print(e)
565
+ raise
566
+
567
+ categories = ["hate_result", "self_harm_result", "sexual_result", "violence_result"]
568
+ max_score = -math.inf
569
+ for category in categories:
570
+ max_score = max(max_score, getattr(response, category).severity)
571
+
572
+ return max_score >= threshold
573
+
574
+ model_path = 'microsoft/Orca-2-7b'
575
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
576
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_path)
577
+ model.to(device)
578
+
579
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
580
+ model_path,
581
+ model_max_length=4096,
582
+ padding_side="right",
583
+ use_fast=False,
584
+ add_special_tokens=False,
585
+ )
586
+
587
+ system_message = "You are Orca, an AI language model created by Microsoft. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."
588
+ user_message = "\" \n :You can't just say, \"\"that's crap\"\" and remove it without gaining a consensus. You already know this, based on your block history. —/ \" \nIs the comment obscene? \nOptions : Yes, No."
589
+
590
+ prompt = f"<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n{user_message}<|im_end|>\n<|im_start|>assistant"
591
+
592
+ inputs = tokenizer(prompt, return_tensors='pt')
593
+ inputs = inputs.to(device)
594
+
595
+ output_ids = model.generate(inputs["input_ids"], max_length=4096, do_sample=False, temperature=0.0, use_cache=True)
596
+ sequence_length = inputs["input_ids"].shape[1]
597
+ new_output_ids = output_ids[:, sequence_length:]
598
+ answers = tokenizer.batch_decode(new_output_ids, skip_special_tokens=True)
599
+ final_output = answers[0] if not should_filter_out(answers[0]) else "[Content Filtered]"
600
+
601
+ print(final_output)
602
+ ```
603
+
604
+ ## Citation
605
+ ```bibtex
606
+ @misc{mitra2023orca,
607
+ title={Orca 2: Teaching Small Language Models How to Reason},
608
+ author={Arindam Mitra and Luciano Del Corro and Shweti Mahajan and Andres Codas and Clarisse Simoes and Sahaj Agrawal and Xuxi Chen and Anastasia Razdaibiedina and Erik Jones and Kriti Aggarwal and Hamid Palangi and Guoqing Zheng and Corby Rosset and Hamed Khanpour and Ahmed Awadallah},
609
+ year={2023},
610
+ eprint={2311.11045},
611
+ archivePrefix={arXiv},
612
+ primaryClass={cs.AI}
613
+ }
614
+ ```