TheBloke commited on
Commit
567c5af
1 Parent(s): 4f4e28c

Upload README.md

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