TheBloke commited on
Commit
e9c021e
1 Parent(s): c55eb4c

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +626 -0
README.md ADDED
@@ -0,0 +1,626 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: epfl-llm/meditron-7b
3
+ datasets:
4
+ - epfl-llm/guidelines
5
+ inference: false
6
+ language:
7
+ - en
8
+ license: llama2
9
+ metrics:
10
+ - accuracy
11
+ - perplexity
12
+ model_creator: EPFL LLM Team
13
+ model_name: Meditron 7B
14
+ model_type: llama
15
+ prompt_template: '<|im_start|>system
16
+
17
+ {system_message}<|im_end|>
18
+
19
+ <|im_start|>user
20
+
21
+ {prompt}<|im_end|>
22
+
23
+ <|im_start|>assistant
24
+
25
+ '
26
+ quantized_by: TheBloke
27
+ ---
28
+ <!-- markdownlint-disable MD041 -->
29
+
30
+ <!-- header start -->
31
+ <!-- 200823 -->
32
+ <div style="width: auto; margin-left: auto; margin-right: auto">
33
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
34
+ </div>
35
+ <div style="display: flex; justify-content: space-between; width: 100%;">
36
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
37
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
38
+ </div>
39
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
40
+ <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>
41
+ </div>
42
+ </div>
43
+ <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>
44
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
45
+ <!-- header end -->
46
+
47
+ # Meditron 7B - GPTQ
48
+ - Model creator: [EPFL LLM Team](https://huggingface.co/epfl-llm)
49
+ - Original model: [Meditron 7B](https://huggingface.co/epfl-llm/meditron-7b)
50
+
51
+ <!-- description start -->
52
+ # Description
53
+
54
+ This repo contains GPTQ model files for [EPFL LLM Team's Meditron 7B](https://huggingface.co/epfl-llm/meditron-7b).
55
+
56
+ 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.
57
+
58
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
59
+
60
+ <!-- description end -->
61
+ <!-- repositories-available start -->
62
+ ## Repositories available
63
+
64
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/meditron-7B-AWQ)
65
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/meditron-7B-GPTQ)
66
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/meditron-7B-GGUF)
67
+ * [EPFL LLM Team's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/epfl-llm/meditron-7b)
68
+ <!-- repositories-available end -->
69
+
70
+ <!-- prompt-template start -->
71
+ ## Prompt template: ChatML
72
+
73
+ ```
74
+ <|im_start|>system
75
+ {system_message}<|im_end|>
76
+ <|im_start|>user
77
+ {prompt}<|im_end|>
78
+ <|im_start|>assistant
79
+
80
+ ```
81
+
82
+ <!-- prompt-template end -->
83
+
84
+
85
+
86
+ <!-- README_GPTQ.md-compatible clients start -->
87
+ ## Known compatible clients / servers
88
+
89
+ These GPTQ models are known to work in the following inference servers/webuis.
90
+
91
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
92
+ - [KoboldAI United](https://github.com/henk717/koboldai)
93
+ - [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui)
94
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
95
+
96
+ This may not be a complete list; if you know of others, please let me know!
97
+ <!-- README_GPTQ.md-compatible clients end -->
98
+
99
+ <!-- README_GPTQ.md-provided-files start -->
100
+ ## Provided files, and GPTQ parameters
101
+
102
+ Multiple quantisation parameters are provided, to allow you to choose the best one for your hardware and requirements.
103
+
104
+ Each separate quant is in a different branch. See below for instructions on fetching from different branches.
105
+
106
+ Most GPTQ files are made with AutoGPTQ. Mistral models are currently made with Transformers.
107
+
108
+ <details>
109
+ <summary>Explanation of GPTQ parameters</summary>
110
+
111
+ - Bits: The bit size of the quantised model.
112
+ - GS: GPTQ group size. Higher numbers use less VRAM, but have lower quantisation accuracy. "None" is the lowest possible value.
113
+ - 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.
114
+ - Damp %: A GPTQ parameter that affects how samples are processed for quantisation. 0.01 is default, but 0.1 results in slightly better accuracy.
115
+ - 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).
116
+ - 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.
117
+ - ExLlama Compatibility: Whether this file can be loaded with ExLlama, which currently only supports Llama and Mistral models in 4-bit.
118
+
119
+ </details>
120
+
121
+ | Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
122
+ | ------ | ---- | -- | --------- | ------ | ------------ | ------- | ---- | ------- | ---- |
123
+ | [main](https://huggingface.co/TheBloke/meditron-7B-GPTQ/tree/main) | 4 | 128 | Yes | 0.1 | [Medical Medaow WikiDoc](https://huggingface.co/datasets/medalpaca/medical_meadow_wikidoc/viewer/) | 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. |
124
+ | [gptq-4bit-32g-actorder_True](https://huggingface.co/TheBloke/meditron-7B-GPTQ/tree/gptq-4bit-32g-actorder_True) | 4 | 32 | Yes | 0.1 | [Medical Medaow WikiDoc](https://huggingface.co/datasets/medalpaca/medical_meadow_wikidoc/viewer/) | 4096 | 4.28 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
125
+ | [gptq-8bit--1g-actorder_True](https://huggingface.co/TheBloke/meditron-7B-GPTQ/tree/gptq-8bit--1g-actorder_True) | 8 | None | Yes | 0.1 | [Medical Medaow WikiDoc](https://huggingface.co/datasets/medalpaca/medical_meadow_wikidoc/viewer/) | 4096 | 7.01 GB | No | 8-bit, with Act Order. No group size, to lower VRAM requirements. |
126
+ | [gptq-8bit-128g-actorder_True](https://huggingface.co/TheBloke/meditron-7B-GPTQ/tree/gptq-8bit-128g-actorder_True) | 8 | 128 | Yes | 0.1 | [Medical Medaow WikiDoc](https://huggingface.co/datasets/medalpaca/medical_meadow_wikidoc/viewer/) | 4096 | 7.16 GB | No | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. |
127
+ | [gptq-8bit-32g-actorder_True](https://huggingface.co/TheBloke/meditron-7B-GPTQ/tree/gptq-8bit-32g-actorder_True) | 8 | 32 | Yes | 0.1 | [Medical Medaow WikiDoc](https://huggingface.co/datasets/medalpaca/medical_meadow_wikidoc/viewer/) | 4096 | 7.62 GB | No | 8-bit, with group size 32g and Act Order for maximum inference quality. |
128
+ | [gptq-4bit-64g-actorder_True](https://huggingface.co/TheBloke/meditron-7B-GPTQ/tree/gptq-4bit-64g-actorder_True) | 4 | 64 | Yes | 0.1 | [Medical Medaow WikiDoc](https://huggingface.co/datasets/medalpaca/medical_meadow_wikidoc/viewer/) | 4096 | 4.02 GB | Yes | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. |
129
+
130
+ <!-- README_GPTQ.md-provided-files end -->
131
+
132
+ <!-- README_GPTQ.md-download-from-branches start -->
133
+ ## How to download, including from branches
134
+
135
+ ### In text-generation-webui
136
+
137
+ To download from the `main` branch, enter `TheBloke/meditron-7B-GPTQ` in the "Download model" box.
138
+
139
+ To download from another branch, add `:branchname` to the end of the download name, eg `TheBloke/meditron-7B-GPTQ:gptq-4bit-32g-actorder_True`
140
+
141
+ ### From the command line
142
+
143
+ I recommend using the `huggingface-hub` Python library:
144
+
145
+ ```shell
146
+ pip3 install huggingface-hub
147
+ ```
148
+
149
+ To download the `main` branch to a folder called `meditron-7B-GPTQ`:
150
+
151
+ ```shell
152
+ mkdir meditron-7B-GPTQ
153
+ huggingface-cli download TheBloke/meditron-7B-GPTQ --local-dir meditron-7B-GPTQ --local-dir-use-symlinks False
154
+ ```
155
+
156
+ To download from a different branch, add the `--revision` parameter:
157
+
158
+ ```shell
159
+ mkdir meditron-7B-GPTQ
160
+ huggingface-cli download TheBloke/meditron-7B-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir meditron-7B-GPTQ --local-dir-use-symlinks False
161
+ ```
162
+
163
+ <details>
164
+ <summary>More advanced huggingface-cli download usage</summary>
165
+
166
+ 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.
167
+
168
+ The cache location can be changed with the `HF_HOME` environment variable, and/or the `--cache-dir` parameter to `huggingface-cli`.
169
+
170
+ 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).
171
+
172
+ To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
173
+
174
+ ```shell
175
+ pip3 install hf_transfer
176
+ ```
177
+
178
+ And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
179
+
180
+ ```shell
181
+ mkdir meditron-7B-GPTQ
182
+ HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/meditron-7B-GPTQ --local-dir meditron-7B-GPTQ --local-dir-use-symlinks False
183
+ ```
184
+
185
+ Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
186
+ </details>
187
+
188
+ ### With `git` (**not** recommended)
189
+
190
+ To clone a specific branch with `git`, use a command like this:
191
+
192
+ ```shell
193
+ git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/meditron-7B-GPTQ
194
+ ```
195
+
196
+ 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.)
197
+
198
+ <!-- README_GPTQ.md-download-from-branches end -->
199
+ <!-- README_GPTQ.md-text-generation-webui start -->
200
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
201
+
202
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
203
+
204
+ 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.
205
+
206
+ 1. Click the **Model tab**.
207
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/meditron-7B-GPTQ`.
208
+
209
+ - To download from a specific branch, enter for example `TheBloke/meditron-7B-GPTQ:gptq-4bit-32g-actorder_True`
210
+ - see Provided Files above for the list of branches for each option.
211
+
212
+ 3. Click **Download**.
213
+ 4. The model will start downloading. Once it's finished it will say "Done".
214
+ 5. In the top left, click the refresh icon next to **Model**.
215
+ 6. In the **Model** dropdown, choose the model you just downloaded: `meditron-7B-GPTQ`
216
+ 7. The model will automatically load, and is now ready for use!
217
+ 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.
218
+
219
+ - 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`.
220
+
221
+ 9. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
222
+
223
+ <!-- README_GPTQ.md-text-generation-webui end -->
224
+
225
+ <!-- README_GPTQ.md-use-from-tgi start -->
226
+ ## Serving this model from Text Generation Inference (TGI)
227
+
228
+ 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`
229
+
230
+ Example Docker parameters:
231
+
232
+ ```shell
233
+ --model-id TheBloke/meditron-7B-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
234
+ ```
235
+
236
+ Example Python code for interfacing with TGI (requires huggingface-hub 0.17.0 or later):
237
+
238
+ ```shell
239
+ pip3 install huggingface-hub
240
+ ```
241
+
242
+ ```python
243
+ from huggingface_hub import InferenceClient
244
+
245
+ endpoint_url = "https://your-endpoint-url-here"
246
+
247
+ prompt = "Tell me about AI"
248
+ prompt_template=f'''<|im_start|>system
249
+ {system_message}<|im_end|>
250
+ <|im_start|>user
251
+ {prompt}<|im_end|>
252
+ <|im_start|>assistant
253
+ '''
254
+
255
+ client = InferenceClient(endpoint_url)
256
+ response = client.text_generation(prompt,
257
+ max_new_tokens=128,
258
+ do_sample=True,
259
+ temperature=0.7,
260
+ top_p=0.95,
261
+ top_k=40,
262
+ repetition_penalty=1.1)
263
+
264
+ print(f"Model output: {response}")
265
+ ```
266
+ <!-- README_GPTQ.md-use-from-tgi end -->
267
+ <!-- README_GPTQ.md-use-from-python start -->
268
+ ## Python code example: inference from this GPTQ model
269
+
270
+ ### Install the necessary packages
271
+
272
+ Requires: Transformers 4.33.0 or later, Optimum 1.12.0 or later, and AutoGPTQ 0.4.2 or later.
273
+
274
+ ```shell
275
+ pip3 install --upgrade transformers optimum
276
+ # If using PyTorch 2.1 + CUDA 12.x:
277
+ pip3 install --upgrade auto-gptq
278
+ # or, if using PyTorch 2.1 + CUDA 11.x:
279
+ pip3 install --upgrade auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
280
+ ```
281
+
282
+ 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:
283
+
284
+ ```shell
285
+ pip3 uninstall -y auto-gptq
286
+ git clone https://github.com/PanQiWei/AutoGPTQ
287
+ cd AutoGPTQ
288
+ git checkout v0.5.1
289
+ pip3 install .
290
+ ```
291
+
292
+ ### Example Python code
293
+
294
+ ```python
295
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
296
+
297
+ model_name_or_path = "TheBloke/meditron-7B-GPTQ"
298
+ # To use a different branch, change revision
299
+ # For example: revision="gptq-4bit-32g-actorder_True"
300
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
301
+ device_map="auto",
302
+ trust_remote_code=False,
303
+ revision="main")
304
+
305
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
306
+
307
+ prompt = "Tell me about AI"
308
+ prompt_template=f'''<|im_start|>system
309
+ {system_message}<|im_end|>
310
+ <|im_start|>user
311
+ {prompt}<|im_end|>
312
+ <|im_start|>assistant
313
+ '''
314
+
315
+ print("\n\n*** Generate:")
316
+
317
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
318
+ output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
319
+ print(tokenizer.decode(output[0]))
320
+
321
+ # Inference can also be done using transformers' pipeline
322
+
323
+ print("*** Pipeline:")
324
+ pipe = pipeline(
325
+ "text-generation",
326
+ model=model,
327
+ tokenizer=tokenizer,
328
+ max_new_tokens=512,
329
+ do_sample=True,
330
+ temperature=0.7,
331
+ top_p=0.95,
332
+ top_k=40,
333
+ repetition_penalty=1.1
334
+ )
335
+
336
+ print(pipe(prompt_template)[0]['generated_text'])
337
+ ```
338
+ <!-- README_GPTQ.md-use-from-python end -->
339
+
340
+ <!-- README_GPTQ.md-compatibility start -->
341
+ ## Compatibility
342
+
343
+ The files provided are tested to work with Transformers. For non-Mistral models, AutoGPTQ can also be used directly.
344
+
345
+ [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.
346
+
347
+ For a list of clients/servers, please see "Known compatible clients / servers", above.
348
+ <!-- README_GPTQ.md-compatibility end -->
349
+
350
+ <!-- footer start -->
351
+ <!-- 200823 -->
352
+ ## Discord
353
+
354
+ For further support, and discussions on these models and AI in general, join us at:
355
+
356
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
357
+
358
+ ## Thanks, and how to contribute
359
+
360
+ Thanks to the [chirper.ai](https://chirper.ai) team!
361
+
362
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
363
+
364
+ 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.
365
+
366
+ 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.
367
+
368
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
369
+
370
+ * Patreon: https://patreon.com/TheBlokeAI
371
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
372
+
373
+ **Special thanks to**: Aemon Algiz.
374
+
375
+ **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
376
+
377
+
378
+ Thank you to all my generous patrons and donaters!
379
+
380
+ And thank you again to a16z for their generous grant.
381
+
382
+ <!-- footer end -->
383
+
384
+ # Original model card: EPFL LLM Team's Meditron 7B
385
+
386
+ <img width=50% src="meditron_LOGO.png" alt="Alt text" title="Meditron-logo">
387
+
388
+ # Model Card for Meditron-7B-v1.0
389
+ Meditron is a suite of open-source medical Large Language Models (LLMs).
390
+ Meditron-7B is a 7 billion parameters model adapted to the medical domain from Llama-2-7B through continued pretraining on a comprehensively curated medical corpus, including selected PubMed articles, abstracts, a [new dataset](https://huggingface.co/datasets/epfl-llm/guidelines) of internationally-recognized medical guidelines, and general domain data from [RedPajama-v1](https://huggingface.co/datasets/togethercomputer/RedPajama-Data-1T).
391
+ Meditron-7B, finetuned on relevant training data, outperforms Llama-2-7B and PMC-Llama on multiple medical reasoning tasks.
392
+
393
+ <details open>
394
+ <summary><strong>Advisory Notice</strong></summary>
395
+
396
+ <blockquote style="padding: 10px; margin: 0 0 10px; border-left: 5px solid #ddd;">
397
+ While Meditron is designed to encode medical knowledge from sources of high-quality evidence, it is not yet adapted to deliver this knowledge appropriately, safely, or within professional actionable constraints.
398
+ We recommend against deploying Meditron in medical applications without extensive use-case alignment, as well as additional testing, specifically including randomized controlled trials in real-world practice settings.
399
+ </blockquote>
400
+ </details>
401
+
402
+ ## Model Details
403
+
404
+ - **Developed by:** [EPFL LLM Team](https://huggingface.co/epfl-llm)
405
+ - **Model type:** Causal decoder-only transformer language model
406
+ - **Language(s):** English (mainly)
407
+ - **Model License:** [LLAMA 2 COMMUNITY LICENSE AGREEMENT](https://huggingface.co/meta-llama/Llama-2-70b/raw/main/LICENSE.txt)
408
+ - **Code License:** [APACHE 2.0 LICENSE](LICENSE)
409
+ - **Continue-pretrained from model:** [Llama-2-7B](https://huggingface.co/meta-llama/Llama-2-7b)
410
+ - **Context length:** 2K tokens
411
+ - **Input:** Text-only data
412
+ - **Output:** Model generates text only
413
+ - **Status:** This is a static model trained on an offline dataset. Future versions of the tuned models will be released as we enhance model's performance.
414
+ - **Knowledge Cutoff:** August 2023
415
+
416
+
417
+ ### Model Sources
418
+
419
+ - **Repository:** [epflLLM/meditron](https://github.com/epfLLM/meditron)
420
+ - **Trainer:** [epflLLM/Megatron-LLM](https://github.com/epfLLM/Megatron-LLM)
421
+ - **Paper:** *[MediTron-70B: Scaling Medical Pretraining for Large Language Models](https://arxiv.org/abs/2311.16079)*
422
+
423
+ ## Uses
424
+
425
+ Meditron-7B is being made available for further testing and assessment as an AI assistant to enhance clinical decision-making and enhance access to an LLM for healthcare use. Potential use cases may include but are not limited to:
426
+ - Medical exam question answering
427
+ - Supporting differential diagnosis
428
+ - Disease information (symptoms, cause, treatment) query
429
+ - General health information query
430
+
431
+ ### Direct Use
432
+
433
+ It is possible to use this model to generate text, which is useful for experimentation and understanding its capabilities.
434
+ It should not be used directly for production or work that may impact people.
435
+
436
+ ### Downstream Use
437
+ Meditron-7B is a foundation model that can be finetuned, instruction-tuned, or RLHF-tuned for specific downstream tasks and applications.
438
+ The main way we have used this model is finetuning for downstream question-answering tasks, but we encourage using this model for additional applications.
439
+
440
+ Specific formatting needs to be followed to prompt our finetuned models, including the `<|im_start|>`, `<|im_end|>` tags, and `system`, `question`, `answer` identifiers.
441
+
442
+ """
443
+ <|im_start|>system
444
+ {system_message}<|im_end|>
445
+ <|im_start|>question
446
+ {prompt}<|im_end|>
447
+ <|im_start|>answer
448
+ """
449
+ **Note 1**: The above formatting is not required for running the base model (this repository)
450
+
451
+ **Note 2**: the above formatting is just an example of a finetuning template. This format is not a requirement if you use your own formatting option for the finetuning of the model.
452
+
453
+ To run proper generation with this base model, we recommend using a high-throughput and memory-efficient inference engine, such as [vLLM](https://github.com/vllm-project/vllm), with a UI that supports chat and text generation, such as [BetterChatGPT](https://github.com/ztjhz/BetterChatGPT)
454
+ To see more details about model deployment and generation, please see our [documentation](https://github.com/epfLLM/meditron/blob/main/deployment/README.md).
455
+
456
+ ### Out-of-Scope Use
457
+
458
+ We do not recommend using this model for natural language generation in a production environment, finetuned or otherwise.
459
+
460
+ ## Truthfulness, Helpfulness, Risk, and Bias
461
+
462
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
463
+
464
+ We did an initial assessment of Meditron models' **Truthfulness** against baseline models and consumer-level medical models.
465
+ We use TruthfulQA (multiple choice) as the main evaluation benchmark.
466
+ We only focus on the categories that are relevant to the medical domain, including Health, Nutrition, Psychology, and Science.
467
+ For 7B models, we perform one-shot evaluations for consistent answer generation.
468
+ For 70B models, the evaluations are under the zero-shot setting.
469
+ Below, we report the detailed truthfulness performance of each category.
470
+
471
+ | | | | | | | | |
472
+ | --- | ------ |----- |----- |----- |----- |----- |----- |
473
+ |Category | meditron-70b | llama-2-70b | med42-70b* | meditron-7b | llama-2-7b | PMC-llama-7b |
474
+ |Health | 81.8 | 69.1 | 83.6 | 27.3 | 16.4 | 3.6 |
475
+ |Nutrition | 77.9 | 68.8 | 62.5 | 31.1 | 12.5 | 6.3 |
476
+ |Psychology| 47.4 | 36.8 | 52.6 | 21.1 | 10.5 | 0.0 |
477
+ |Science | 77.8 | 44.4 | 33.3 | 33.3 | 11.1 | 0.0 |
478
+ |Avg | 71.2 | 54.8 | 58.0 | 28.3 | 12.6 | 2.5 |
479
+ | | | | | | | |
480
+
481
+ For a more detailed performance analysis, please see our paper.
482
+
483
+ Significant research is still required to fully explore potential bias, fairness, and safety issues with this language model.
484
+ Please recognize that our evaluation on Meditron-7B's helpfulness, risk, and bias are highly limited.
485
+ Thus, as we noted in the safety notice, we strongly against any deployment in medical applications without further alignment process and rigorous evaluation!
486
+
487
+ ### Recommendations
488
+
489
+ **IMPORTANT!**
490
+ Users (both direct and downstream) should be made aware of the risks, biases, and limitations of the model.
491
+ While this model is capable of generating natural language text, we have only begun to explore this capability and its limitations.
492
+ Understanding these limitations is especially important in a domain like medicine.
493
+ Therefore, we strongly recommend against using this model in production for natural language generation or for professional purposes related to health and medicine.
494
+
495
+ ## Training Details
496
+
497
+ ### Training Data
498
+ Meditron’s domain-adaptive pre-training corpus GAP-Replay combines 48.1B tokens from four corpora:
499
+ - [**Clinical Guidelines**](https://huggingface.co/datasets/epfl-llm/guidelines): a new dataset of 46K internationally-recognized clinical practice guidelines from various healthcare-related sources, including hospitals and international organizations.
500
+ - **Medical Paper Abstracts**: 16.1M abstracts extracted from closed-access PubMed and PubMed Central papers.
501
+ - **Medical Papers**: full-text articles extracted from 5M publicly available PubMed and PubMed Central papers.
502
+ - **Replay Data**: 400M tokens of general domain pretraining data sampled from [RedPajama-v1](https://huggingface.co/datasets/togethercomputer/RedPajama-Data-1T)
503
+
504
+ <img width=75% src="gap-replay.png" alt="Alt text" title="Meditron-logo">
505
+
506
+ #### Data Preprocessing
507
+
508
+ Please see the detailed preprocessing procedure in our paper.
509
+
510
+ ### Training Procedure
511
+
512
+ We used the [Megatron-LLM](https://github.com/epfLLM/Megatron-LLM) distributed training library, a derivative of Nvidia's Megatron LM project, to optimize training efficiency.
513
+ Hardware consists of 1 node of 8x NVIDIA A100 (80GB) SXM GPUs connected by NVLink and NVSwitch with a single Nvidia ConnectX-6 DX network card and equipped with 2 x AMD EPYC 7543 32-Core Processors and 512 GB of RAM.
514
+
515
+ Our three way parallelism scheme uses:
516
+ - Data Parallelism (DP -- different GPUs process different subsets of the batches) of 2,
517
+ - Pipeline Parallelism (PP -- different GPUs process different layers) of 4,
518
+ - Tensor Parallelism (TP -- different GPUs process different subtensors for matrix multiplication) of 1.
519
+
520
+
521
+ #### Training Hyperparameters
522
+
523
+ | | |
524
+ | --- | ------ |
525
+ | bf16 | true |
526
+ | lr | 3e-4 |
527
+ | eps | 1e-5 |
528
+ | betas | \[0.9, 0.95\] |
529
+ | clip_grad | 1 |
530
+ | weight decay | 0.1 |
531
+ | DP size | 16 |
532
+ | TP size | 4 |
533
+ | PP size | 1 |
534
+ | seq length | 2048 |
535
+ | lr scheduler | cosine|
536
+ | min lr | 1e-6 |
537
+ | warmup iteration | 2000 |
538
+ | micro batch size | 10 |
539
+ | global batch size | 1600 |
540
+ | | |
541
+
542
+ #### Sizes
543
+ The model was trained in September 2023.
544
+
545
+ The model architecture is exactly Llama 2, meaning
546
+
547
+ | | |
548
+ | --- | ------ |
549
+ | Model size | 7B |
550
+ | Hidden dimension | 4096 |
551
+ | Num. attention heads | 32 |
552
+ | Num. layers | 32 |
553
+ | | |
554
+
555
+ ## Evaluation
556
+
557
+ <!-- This section describes the evaluation protocols and provides the results. -->
558
+
559
+ ### Testing Data & Metrics
560
+
561
+ #### Testing Data
562
+ - [MedQA (USMLE)](https://huggingface.co/datasets/bigbio/med_qa)
563
+ - [MedMCQA](https://huggingface.co/datasets/medmcqa)
564
+ - [PubMedQA](https://huggingface.co/datasets/bigbio/pubmed_qa)
565
+ - [MMLU-Medical](https://huggingface.co/datasets/lukaemon/mmlu)
566
+ - [MedQA-4-Option](https://huggingface.co/datasets/GBaker/MedQA-USMLE-4-options)
567
+
568
+ #### Metrics
569
+ - Accuracy: suite the evaluation of multiple-choice question-answering tasks.
570
+
571
+ ### Results
572
+ We finetune meditron-7b, llama-2-7b, pmc-llama-7b on each benchmark (pubmedqa, medmcqa, medqa)'s training data individually.
573
+ We report the finetuned models' performance with top token selection as the inference mode.
574
+ For MMLU-Medical, models finetuned on MedMCQA are used for inference.
575
+ For MedQA-4-Option, models finetuned on MedQA are used for inference.
576
+ For a more detailed performance analysis, please see our paper.
577
+
578
+ | | | | | | |
579
+ | --- | ------ |----- |----- |----- |----- |
580
+ |Dataset | meditron-7b | llama-2-7b | pmc-llama-7b | Zephyr-7B-beta* | Mistral-7B-instruct* |
581
+ |MMLU-Medical | 54.2 | 53.7 | 56.4 | 63.3 | 60.0 |
582
+ |PubMedQA | 74.4 | 61.8 | 59.2 | 46.0 | 17.8 |
583
+ |MedMCQA | 59.2 | 54.4 | 57.6 | 43.0 | 40.2 |
584
+ |MedQA | 47.9 | 44.0 | 42.4 | 42.8 | 32.4 |
585
+ |MedQA-4-Option| 52.0 | 49.6 | 49.2 | 48.5 | 41.1 |
586
+ |Avg | 57.5 | 52.7 | 53.0 | 48.7 | 38.3 |
587
+ | | | | | | |
588
+
589
+ **Note**: models with * are already instruction-tuned, so we exclude them from further finetuning on any training data.
590
+
591
+
592
+ ## Environmental Impact
593
+
594
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
595
+
596
+ - **Hardware Type:** 8 x NVIDIA A100 (80GB) SXM
597
+ - **Total GPU hours:** 588.8
598
+ - **Hardware Provider:** EPFL Research Computing Platform
599
+ - **Compute Region:** Switzerland
600
+ - **Carbon Emitted:** Switzerland has a carbon efficiency of 0.016 kgCO2/kWh (https://www.carbonfootprint.com/docs/2018_8_electricity_factors_august_2018_-_online_sources.pdf). 73.6 hours of 8 A100s means 588.8 hours at a TDP of 400W. Assuming a Power Usage effectiveness of 1.5, total emissions are estimated to be:
601
+
602
+ (400W / 1000W/kWh / GPU * 0.016 kgCO2/kWh * 73.6 h * 8 GPU) * 1.8 PUE = 6.8 kgCO2.
603
+
604
+ ## Citation
605
+
606
+ **BibTeX:**
607
+ If you use Meditron or its training data, please cite our work:
608
+
609
+ ```
610
+ @misc{chen2023meditron70b,
611
+ title={MEDITRON-70B: Scaling Medical Pretraining for Large Language Models},
612
+ author={Zeming Chen and Alejandro Hernández-Cano and Angelika Romanou and Antoine Bonnet and Kyle Matoba and Francesco Salvi and Matteo Pagliardini and Simin Fan and Andreas Köpf and Amirkeivan Mohtashami and Alexandre Sallinen and Alireza Sakhaeirad and Vinitra Swamy and Igor Krawczuk and Deniz Bayazit and Axel Marmet and Syrielle Montariol and Mary-Anne Hartley and Martin Jaggi and Antoine Bosselut},
613
+ year={2023},
614
+ eprint={2311.16079},
615
+ archivePrefix={arXiv},
616
+ primaryClass={cs.CL}
617
+ }
618
+
619
+ @software{epfmedtrn,
620
+ author = {Zeming Chen and Alejandro Hernández-Cano and Angelika Romanou and Antoine Bonnet and Kyle Matoba and Francesco Salvi and Matteo Pagliardini and Simin Fan and Andreas Köpf and Amirkeivan Mohtashami and Alexandre Sallinen and Alireza Sakhaeirad and Vinitra Swamy and Igor Krawczuk and Deniz Bayazit and Axel Marmet and Syrielle Montariol and Mary-Anne Hartley and Martin Jaggi and Antoine Bosselut},
621
+ title = {MediTron-70B: Scaling Medical Pretraining for Large Language Models},
622
+ month = November,
623
+ year = 2023,
624
+ url = {https://github.com/epfLLM/meditron}
625
+ }
626
+ ```