MedQA ChatGLM
1.0.0
Note
欢迎关注我们最新的工作:CareLlama (关怀羊驼),它是一个医疗大语言模型,同时它集合了数十个公开可用的医疗微调数据集和开放可用的医疗大语言模型以促进医疗LLM快速发展:https://github.com/WangRongsheng/CareLlama

1 使用的数据为cMedQA2
| 项目 | 数据集 | 底座模型 |
|---|---|---|
| ChatMed | Consult 包含50w+在线问诊+ChatGPT回复,TCM中医药诊疗数据集未公开 | LLaMA-7B |
| ChatDoctor | HealthCareMagic-100k 包含100k+真实患者与医生对话数据集,icliniq-10k 包含10k+患者与医生对话数据集,GenMedGPT-5k 包含5k+由GPT生成的医患对话数据集 | LLaMA-7B |
| Med-ChatGLM | Huatuo-data 、Huatuo-liver-cancer | ChatGLM-6B |
| Huatuo-Llama-Med-Chinese | Huatuo-data 、Huatuo-liver-cancer | LLaMA-7B |
| DoctorGLM | CMD. 、MedDialog 、ChatDoctor项目数据集 | ChatGLM-6B |
| MedicalGPT-zh | 数据未开源 | ChatGLM-6B |
| Dr.LLaMA | LLaMA | |
| Medical_NLP 2 | - | - |
| CMCQA 3 | - | - |
| QiZhenGPT | - | - |
| LLM-Pretrain-FineTune | - | - |
| PMC-LLaMA | - | LLaMA-7B |
| BianQue | - | - |
| medAlpaca | - | LLaMA-7B |
| MedicalGPT | - | - |
| LLM-Pretrain-FineTune | - | - |
| ShenNong-TCM-LLM | - | - |
| Sunsimiao | - | - |
| CMLM-ZhongJing | - | - |
| ZhongJing | - | - |
| Ming | - | - |
| DISC-MedLLM | - | - |
pip install -r requirements.txtCUDA_VISIBLE_DEVICES=0 python MedQA-ChatGLM/finetune.py
--do_train
--dataset merged-cMedQA
--finetuning_type lora
--output_dir ./med-lora
--per_device_train_batch_size 32
--gradient_accumulation_steps 256
--lr_scheduler_type cosine
--logging_steps 500
--save_steps 1000
--learning_rate 5e-5
--num_train_epochs 10.0
--fp16CUDA_VISIBLE_DEVICES=0 python MedQA-ChatGLM/finetune.py
--do_train
--dataset merged-cMedQA
--finetuning_type freeze
--output_dir ./med-freeze
--per_device_train_batch_size 32
--gradient_accumulation_steps 256
--lr_scheduler_type cosine
--logging_steps 500
--save_steps 1000
--learning_rate 5e-5
--num_train_epochs 10.0
--fp16CUDA_VISIBLE_DEVICES=1 python MedQA-ChatGLM/finetune.py
--do_train --dataset merged-cMedQA
--finetuning_type p_tuning
--output_dir ./med-p_tuning
--per_device_train_batch_size 32
--gradient_accumulation_steps 256
--lr_scheduler_type cosine
--logging_steps 500
--save_steps 1000
--learning_rate 5e-5
--num_train_epochs 10.0
--fp16更多参数信息,可以查看docs/参数详解.md .
多GPU分布式训练:
# 配置分布式参数
accelerate config
# 分布式训练
accelerate launch src/finetune.py
--do_train
--dataset Huatuo,CMD,MedDialog,guanaco,cognition
--finetuning_type lora
--output_dir med-lora
--per_device_train_batch_size 16
--gradient_accumulation_steps 4
--lr_scheduler_type cosine
--logging_steps 10
--save_steps 1000
--learning_rate 5e-5
--num_train_epochs 3.0
--fp16
--ddp_find_unused_parameters False # 分布式训练时,LoRA微调需要添加防止报错
--plot_lossCUDA_VISIBLE_DEVICES=0 python MedQA-ChatGLM/web_demo.py
--checkpoint_dir med-lora/
(med-freez/)
(med-p_tuning/)CUDA_VISIBLE_DEVICES=0 python MedQA-ChatGLM/infer.py
--checkpoint_dir med-lora/
(med-freez/)
(med-p_tuning/)合并模型:
CUDA_VISIBLE_DEVICES=0 python MedQA-ChatGLM/export_weights.py
--finetuning_weights_path ./med-lora
--save_weights_path ./save_lora加载合并模型:
CUDA_VISIBLE_DEVICES=0 python MedQA-ChatGLM/load_export_weights.py
--save_weights_path ./save_lora| 微调方式 | 模型权重 | 训练时长 | 训练轮次 |
|---|---|---|---|
| LoRA | MedQA-ChatGLM-LoRA | 28h | 10 |
| P-Tuning V2 | MedQA-ChatGLM-PTuningV2 | 27h | 10 |
| Freeze | MedQA-ChatGLM-Freeze | 28h | 10 |
* 实验是在Linux系统,A100 (1X, 80GB)上进行的
本项目相关资源仅供学术研究之用,严禁用于商业用途。使用涉及第三方代码的部分时,请严格遵循相应的开源协议。模型生成的内容受模型计算、随机性和量化精度损失等因素影响,本项目无法对其准确性作出保证。本项目数据集绝大部分由模型生成,即使符合某些医学事实,也不能被用作实际医学诊断的依据。对于模型输出的任何内容,本项目不承担任何法律责任,亦不对因使用相关资源和输出结果而可能产生的任何损失承担责任。