{"id":13579519,"url":"https://github.com/epfLLM/meditron","last_synced_at":"2025-04-05T21:31:52.335Z","repository":{"id":208884457,"uuid":"722687885","full_name":"epfLLM/meditron","owner":"epfLLM","description":"Meditron is a suite of open-source medical Large Language Models (LLMs).","archived":false,"fork":false,"pushed_at":"2024-04-10T11:48:37.000Z","size":23768,"stargazers_count":1878,"open_issues_count":15,"forks_count":170,"subscribers_count":32,"default_branch":"main","last_synced_at":"2024-11-05T04:02:29.399Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://huggingface.co/epfl-llm","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/epfLLM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T17:45:46.000Z","updated_at":"2024-11-03T17:06:04.000Z","dependencies_parsed_at":"2023-11-23T20:24:43.624Z","dependency_job_id":"323d59c8-d942-47b2-96b1-ad6c802db43b","html_url":"https://github.com/epfLLM/meditron","commit_stats":null,"previous_names":["epfllm/meditron"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfLLM%2Fmeditron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfLLM%2Fmeditron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfLLM%2Fmeditron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfLLM%2Fmeditron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/epfLLM","download_url":"https://codeload.github.com/epfLLM/meditron/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223214892,"owners_count":17107604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:01:40.139Z","updated_at":"2024-11-05T17:31:57.869Z","avatar_url":"https://github.com/epfLLM.png","language":"Python","readme":"\u003cimg width=40% src=\"figures/meditron_LOGO.png\" alt=\"MediTron logo\" title=\"Meditron-logo\"\u003e\n\nMeditron is a suite of open-source medical Large Language Models (LLMs).\n\nWe release Meditron-7B and Meditron-70B, which are adapted to the medical domain from Llama-2 through continued pretraining on a comprehensively curated medical corpus, including selected PubMed papers and abstracts, a new dataset of internationally-recognized medical guidelines, and a general domain corpus.\n\nMeditron-70B, finetuned on relevant data, outperforms Llama-2-70B, GPT-3.5 and Flan-PaLM on multiple medical reasoning tasks.\n\n\u003cdetails open\u003e\n  \u003csummary\u003e\u003cstrong\u003eAdvisory Notice\u003c/strong\u003e\u003c/summary\u003e\n\n  \u003cblockquote style=\"background-color: #f2f2f2; padding: 10px; margin: 0 0 10px; border-left: 5px solid #ddd;\"\u003e\n    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. We recommend against using Meditron in medical applications without extensive use-case alignment, as well as additional testing, specifically including randomized controlled trials in real-world practice settings.\n  \u003c/blockquote\u003e\n\u003c/details\u003e\n\n## Model Details\n\n- **Developed by:** [EPFL LLM Team](https://huggingface.co/epfl-llm)\n- **Model type:** Causal decoder-only transformer language model\n- **Language(s):** English (mainly)\n- **Model License:** [LLAMA 2 COMMUNITY LICENSE AGREEMENT](https://ai.meta.com/llama/license/)\n- **Code License:** [APACHE 2.0 LICENSE](LICENSE)\n- **Continue-pretrained from model:** [Llama-2-70B](https://huggingface.co/meta-llama/Llama-2-70b)\n- **Context length:**  4k tokens\n- **Input:**  Text only data\n- **Output:**  Model generates text only\n- **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.\n- **Knowledge Cutoff:** August 2023\n- **Trainer:** [epflLLM/Megatron-LLM](https://github.com/epfLLM/Megatron-LLM)\n- **Paper:** *[Meditron-70B: Scaling Medical Pretraining for Large Language Models](https://arxiv.org/abs/2311.16079)*\n\n## How to use\n\nYou can load the Meditron model directly from the [HuggingFace model hub](https://huggingface.co/epfl-llm/meditron-70B) as follows:\n\n```python\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\ntokenizer = AutoTokenizer.from_pretrained(\"epfl-llm/meditron-70b\")\nmodel = AutoModelForCausalLM.from_pretrained(\"epfl-llm/meditron-70b\")\n```\n\n\u003cimg width=100% src=\"figures/meditron-pipeline.png\" alt=\"Pipeline\" title=\"Pipeline\"\u003e\n\n## Medical Training Data\n\nWe release code to download and pre-process the data used to train Meditron.\n\nMediTron’s domain-adaptive pre-training corpus *GAP-Replay* combines 48.1B tokens from four corpora:\n\n- **Clinical \u003cu\u003eG\u003c/u\u003euidelines**: a new corpus of 46K clinical practice guidelines from various healthcare-related sources, including hospitals and international organizations,\n- **Paper \u003cu\u003eA\u003c/u\u003ebstracts**: 16.1M abstracts extracted from closed-access PubMed and PubMed Central papers,\n- **Medical \u003cu\u003eP\u003c/u\u003eapers**: full-text articles extracted from 5M publicly available PubMed and PubMed Central papers.\n- **\u003cu\u003eReplay\u003c/u\u003e dataset**: 400M tokens of general domain pretraining data sampled from [RedPajama-v1](https://huggingface.co/datasets/togethercomputer/RedPajama-Data-1T).\n\n### Download instructions\n\nYou can download and pre-process the entire GAP-Replay corpus by running `./download.sh` in the `gap-replay` folder.\n\nYou can download 36K open-access articles from our *Guidelines* corpus from the [HuggingFace datasets hub](https://huggingface.co/datasets/epfl-llm/guidelines).\n\n```python\nfrom datasets import load_dataset\n\ndataset = load_dataset(\"epfl-llm/guidelines\")\n```\n\nYou can scrape and clean all 46K guidelines (including closed-access sources) by running `./download.sh` in the `guidelines` folder.\n\nMore details can be found in the [GAP-Replay documentation](gap-replay/README.md).\n\n## Training Procedure\n\nWe 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.\nThe 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.\nThe nodes are connected via RDMA over Converged Ethernet.\n\nOur three-way parallelism scheme uses the following:\n\n- Data Parallelism (DP -- different GPUs process different subsets of the batches) of 2,\n- Pipeline Parallelism (PP -- different GPUs process different layers) of 8,\n- Tensor Parallelism (TP -- different GPUs process different subtensors for matrix multiplication) of 8.\n\n### Training Hyperparameters (7B)\n\n|  |  |\n| --- | ------ |\n| bf16 | true |\n| lr  | 3e-4 |\n| eps | 1e-5       |\n| betas | \\[0.9, 0.95\\] |\n| clip_grad | 1 |\n| weight decay | 0.1 |\n| DP size | 16 |\n| TP size | 4 |\n| PP size | 1 |\n| seq length | 2048 |\n| lr scheduler | cosine|\n| min lr | 1e-6 |\n| warmup iteration | 2000 |\n| micro batch size | 10 |\n| global batch size | 1600 |\n|  |  |\n\n### Training Hyperparameters (70B)\n\n|  |  |\n| --- | ------ |\n| bf16 | true |\n| lr  | 1.5e-4 |\n| eps | 1e-5       |\n| betas | \\[0.9, 0.95\\] |\n| clip_grad | 1 |\n| weight decay | 0.1 |\n| DP size | 2 |\n| TP size | 8 |\n| PP size | 8 |\n| seq length | 4096 |\n| lr scheduler | cosine|\n| min lr | 1e-6 |\n| warmup iteration | 2000 |\n| micro batch size | 2 |\n| global batch size | 512 |\n|  |  |\n\nYou can see the script we used to pretrain our models through Megatron-LLM here: [finetune.sh](./pretrain/finetune.sh)\n\n## Supervised Finetuning\n\nWe again used the [Megatron-LLM](https://github.com/epfLLM/Megatron-LLM) distributed training library for supervised finetuning (sinlge-node and multi-node).\nWe made a file, `sft.py`, that automatically handles the tokenization and finetuning process through Megatron-LLM. To start a multi-node finetuning process, here is an example:\n\n```bash\ncd finetuning\npython sft.py \\\n    --checkpoint=baseline \\\n    --size=70 \\\n    --run_name=cotmedqa \\\n    --data /pure-mlo-scratch/zechen/meditron/benchmarks/ft_preprocessed/medqa_cot_train.jsonl \\\n    --val /pure-mlo-scratch/zechen/meditron/benchmarks/ft_preprocessed/medqa_cot_validation.jsonl \\\n    --micro_batch=4\n    --nodes=4 \\\n    --addr=\u003cRANK0_HOST_NAME\u003e \\\n    --save_interval=200 \\\n    --pp=4 \\\n    --seq 4096 \\\n    --rank=\u003cCURRENT_RANK\u003e\n```\n\nRun the above line of code at node rank-0, rank-1, rank-2, and rank3 to start a 4-node finetuning process.\n\n**Important!**: Make sure to have the proper paths defined in `sft.py` and `finetune_sft.sh`.\n\n### Finetuning Hyperparameters\n\n|  |  |\n| --- | ------ |\n| bf16 | true |\n| lr  | 2e-5 |\n| eps | 1e-5       |\n| betas | \\[0.9, 0.95\\] |\n| clip_grad | 1 |\n| weight decay | 0.1 |\n| DP size | 16 |\n| TP size | 4 |\n| PP size | 1 |\n| seq length | 2048 or 4096 |\n| lr scheduler | cosine|\n| min lr | 2e-6 |\n| warmup ratio | 0.1 |\n| added tokens | [\u003c\\|im_start\\|\u003e, \u003c\\|im_end\\|\u003e] |\n|  |  |\n\n## Uses\n\nMeditron-70B is being made available for further testing and assessment as an AI assistant to enhance clinical decision-making and democratize access to an LLM for healthcare use. Potential use cases may include but are not limited to:\n\n- Medical exam question answering\n- Supporting differential diagnosis\n- Disease information (symptoms, cause, treatment) query\n- General health information query\n\nIt is possible to use this model to generate text, which is useful for experimentation and understanding its capabilities. It should not be used directly for production or work that may impact people.\n\nWe do not recommend using this model for natural language generation in a production environment, finetuned or otherwise.\n\n### Downstream Use\n\nMeditron-70B and Meditron-7B are both foundation models without finetuning or instruction-tuning. They can be finetuned, instruction-tuned, or RLHF-tuned for specific downstream tasks and applications.\nThere are two ways we have used this model for downstream question-answering tasks.\n1. We apply in-context learning with k demonstrations (3 or 5 in our paper) added to the prompt.\n2. We finetuned the models for downstream question-answering tasks using specific training sets.\n\nWe encourage and look forward to the adaption of the base model for more diverse applications.\n\nIf you want a more interactive way to prompt the model, we recommend using a high-throughput and memory-efficient inference engine with a UI that supports chat and text generation.\n\nYou can check out our deployment guide below, where we used [FastChat](https://github.com/lm-sys/FastChat) with [vLLM](https://github.com/vllm-project/vllm). We collected generations for our qualitative analysis through an interactive UI platform, [BetterChatGPT](https://github.com/ztjhz/BetterChatGPT). Here is the prompt format we used as an example:\n\n\u003cimg width=70% src=\"figures/prompt_example.png\" alt=\"qualitative-analysis-prompt\" title=\"Qualitative Analysis Prompt\"\u003e\n\n## Medical Benchmark Inference \u0026 Evaluation\n\n### Requirements\n\nBefore you start, please install the necessary packages:\n\n    vllm \u003e= 0.2.1\n    transformers \u003e= 4.34.0\n    datasets \u003e= 2.14.6\n    torch \u003e= 2.0.1\n\nFor detailed instructions to run inference and evaluation with medical benchmarks, please read the documentation here [inference \u0026 evaluation instructions](./evaluation/README.md).\n\n## Model Deployment\n\nFor detailed instructions to deploy meditron models and have an interactive chat session, please read the documentation here [Model Deployment](./deployment/README.md)\n\n## Citation\n\nIf you use this software or our paper, please cite them:\n\u003cpre\u003e\n@misc{chen2023meditron70b,\n      title={MEDITRON-70B: Scaling Medical Pretraining for Large Language Models},\n      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},\n      year={2023},\n      eprint={2311.16079},\n      archivePrefix={arXiv},\n      primaryClass={cs.CL}\n}\n\n@software{epfmedtrn,\n  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},\n  title = {MediTron-70B: Scaling Medical Pretraining for Large Language Models},\n  month = November,\n  year = 2023,\n  url = {https://github.com/epfLLM/meditron}\n}\n\u003c/pre\u003e\n","funding_links":[],"categories":["Python","Model","🤖 Scientific Models","Medical LLMs \u0026 Foundation Models","Health AI \u0026 Machine Learning"],"sub_categories":["🧬 Life Sciences","Medical Reasoning \u0026 Foundation Models"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FepfLLM%2Fmeditron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FepfLLM%2Fmeditron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FepfLLM%2Fmeditron/lists"}