{"id":13524812,"url":"https://github.com/xionghonglin/DoctorGLM","last_synced_at":"2025-04-01T03:33:05.289Z","repository":{"id":149412055,"uuid":"620773009","full_name":"xionghonglin/DoctorGLM","owner":"xionghonglin","description":"基于ChatGLM-6B的中文问诊模型","archived":false,"fork":false,"pushed_at":"2023-10-19T06:49:02.000Z","size":45776,"stargazers_count":752,"open_issues_count":16,"forks_count":80,"subscribers_count":15,"default_branch":"main","last_synced_at":"2024-08-02T06:17:11.166Z","etag":null,"topics":["chatglm-6b"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xionghonglin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-03-29T10:48:16.000Z","updated_at":"2024-08-01T10:22:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"ad29242d-5e5b-4d5f-8a3f-7d74fee8c704","html_url":"https://github.com/xionghonglin/DoctorGLM","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xionghonglin%2FDoctorGLM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xionghonglin%2FDoctorGLM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xionghonglin%2FDoctorGLM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xionghonglin%2FDoctorGLM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xionghonglin","download_url":"https://codeload.github.com/xionghonglin/DoctorGLM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222698187,"owners_count":17024877,"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":["chatglm-6b"],"created_at":"2024-08-01T06:01:13.655Z","updated_at":"2024-11-02T09:30:35.501Z","avatar_url":"https://github.com/xionghonglin.png","language":"Python","funding_links":[],"categories":["🤖 模型","Models","大语言模型LLMs","A01_文本生成_文本对话","大模型列表","中文医疗大模型"],"sub_categories":["🧩 领域模型","英文","大语言对话模型及数据"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"imgs/logo.png\" width=400px/\u003e\n  \u003cbr/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Version-0.0.3--alpha-brightgreen\"\u003e\n  \u003cbr/\u003e\n  \u003ca href=\"https://xionghonglin.github.io/DoctorGLM/\"\u003e[Project Page]\u003c/a\u003e\n  \u003ca href=\"https://arxiv.org/abs/2304.01097\"\u003e[Arxiv]\u003c/a\u003e\n  \u003ca href=\"https://zhuanlan.zhihu.com/p/622649076\"\u003e[最新博客]\u003c/a\u003e\n  \u003ca href=\"https://doctorglm.idealab-llms.com\"\u003e[在线体验]\u003c/a\u003e\n\u003c/p\u003e\n\n\n\n\n# DoctorGLM\n基于 ChatGLM-6B的中文问诊模型\n\n## 最近更新\n- \u003cimg src=\"https://img.shields.io/badge/Version-0.0.3--alpha-brightgreen\"\u003e(2023.4.18): P-Tuning \u0026 多轮对话 \u0026 模型可靠性提升\n\n## 训练数据\n| Dataset    | Department                | Language | Q\u0026A  | Chat | Number | Syn. | Size  | Weight |\n|------------|--------------------------|----------|------|------|--------|------|-------|-------|\n| CMD.       | Surgical                 | CN       | ✔    | ×    | 116K   | ×    | 52MB  |       |\n|            | Obstetrics and Gynecology| CN       | ✔    | ×    | 229K   | ×    | 78MB  |       |\n|            | Pediatrics               | CN       | ✔    | ×    | 117K   | ×    | 47MB  |       |\n|            | Internal Medicine        | CN       | ✔    | ×    | 307K   | ×    | 102MB |       |\n|            | Andriatria               | CN       | ✔    | ×    | 113K   | ×    | 44MB  |       |\n|            | Merged                   | CN       | ✔    | ×    | 1.9M   | ×    |       |Doctor_GLM/ckpt|\n| MedDialog  | Multiple                 | CN\u0026EN    | ✔    | ✔    | 3.4M   | ×    | 1.5GB |[ptuning_weight](https://pan.baidu.com/s/1Yf56egVGwI0XN2iOLcEGSQ?pwd=r4p0)   |\n| ChatDoctor | Multiple                 | EN       | ✔    | ×    | 5.4K   | ✔    | 2.9MB |Coming soon    |\n| HearlthcareMagic| Multiple            | EN       | ✔    | ×    | 200K   | ×    | 216MB |Coming soon    |\n\n\n\nhttps://github.com/Toyhom/Chinese-medical-dialogue-data\n\n## 使用\n### lora\n- 显存 \u003e= 13G （未量化版本）\n- pip install deep_training cpm_kernels icetk transformers\u003e=4.26.1 \n- torch \u003e= 1.12.0 (icetk依赖cpu版torch, 建议先安装icetk后安装gpu版torch)\n- lora的finetune代码来自 https://github.com/ssbuild/chatglm_finetuning\n\n对于fp16模型，直接使用Doctor_GLM/chat_lora.ipynb，由于官方更新了chatglm的权重，我们将老版权重放在了\n[old_pretrain_model](https://pan.baidu.com/s/1vuoBbOQVPJPAcurEfVRn7A?pwd=ahwc)\n可以下载后解压到old_pretrain_model目录\n\n量化的模型我们打了个包，使用方便，但是效果目前来看很成问题：INT4需要大约6G显存，INT8需要大约8G显存，在Doctor_GLM/chat_lora_quant.ipynb下使用\n``` python\nfrom load_quantization import load_int\ntokenizer, model = load_int('DoctorGLM-6B-INT8-6merge-int8.pt',8)\nresponse, history = model.chat(tokenizer,\n                               \"我爷爷高血压可以喝咖啡吗\",\n                               history=[],\n                               max_length=2048)\nprint(response)\n```\n模型下载链接：\n[INT4](https://pan.baidu.com/s/1nHQ1EQ2OBuWCyBZKBnBHYw?pwd=x6l4) [INT8](https://pan.baidu.com/s/1v2hWl1dPnh8xoJzxtpbugw?pwd=y4hu)\n量化方法均为分层的线性量化。\n目前量化模型的性能**仍有较大问题**，后期我们会对量化方法和模型进行更新\n\n### p-tuningv2\n官方提供了p-tuningv2的实现，新版本权重可以在hugging face上下载，也可以从我们的链接下载 [pretrain_model](https://pan.baidu.com/s/1WaG-NQeXVR7BNZs_zlUFmQ?pwd=h88g)   \np-tuningv2的权重在\n[ptuning_weight](https://pan.baidu.com/s/1Yf56egVGwI0XN2iOLcEGSQ?pwd=r4p0) ， 下载后解压到ckpt/ptuningv2目录下, 然后使用Doctor_GLM/chat_ptuning_v2.ipynb，根据需要调整quantization_bit为4或8\n\n\n\n## 模型在线部署\n\n为了方便部署并随时调整模型生成回答时的参数，我们提供了基于 `Gradio` 库的部署代码，路径为 `Doctor_GLM/gradio.ipynb`。运行之后，访问本机的7860或者代码声明的其他端口即可以运行Demo，模型在生成回答时的参数可以由用户自由调控。若想让部署的模型可以被局域网之外的其他用户访问，需要将sharing设置为 `True`（默认为`False`）。部署之后运行效果如下所示：\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"imgs/gradio_demo.gif\" width=1300px/\u003e\n  \u003cbr/\u003e\n\u003c/p\u003e\n\n## 最近更新\n- \u003cimg src=\"https://img.shields.io/badge/Version-0.0.1--alpha-brightgreen\"\u003e (2023.4.3) 初版的权重，来自LoRA SFT 1 epcoh\n- \u003cimg src=\"https://img.shields.io/badge/Version-0.0.2--alpha-brightgreen\"\u003e (2023.4.13) LoRA-INT4/8量化权重，以及我们实验发现LoRA一直会丢失对话能力，放弃该方式，转向P-Tuning\n- \u003cimg src=\"https://img.shields.io/badge/Version-0.0.3--alpha-brightgreen\"\u003e (2023.4.18) P-Tuning 多轮对话数据集训练的新权重和arxiv\n\n## 即将到来的更新 \n- [ ] \u003cimg src=\"https://img.shields.io/badge/Version-0.0.4--alpha-brightgreen\"\u003e (2023.4.21) 对话中加入参考文献，模型上传到huggingface\n\n\n第一次运行会下载chatGLM-6B权重, 如果已有chatGLM-6B权重可以将data_utils.py里的路径修改为自己的权重目录\n## 结果示例\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"imgs/3_ret.png\" width=1300px/\u003e\n  \u003cbr/\u003e\n\u003c/p\u003e\n我们随机跑了100个结果，在 ./results目录下，两份json文件分别为由ChatGLM, DoctorGLM得到的结果，目前存在大量复读机。\n\n\n\n## 引用\n```\n@article{xiong2023doctorglm,\n  title={Doctorglm: Fine-tuning your chinese doctor is not a herculean task},\n  author={Xiong, Honglin and Wang, Sheng and Zhu, Yitao and Zhao, Zihao and Liu, Yuxiao and Wang, Qian and Shen, Dinggang},\n  journal={arXiv preprint arXiv:2304.01097},\n  year={2023}\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxionghonglin%2FDoctorGLM","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxionghonglin%2FDoctorGLM","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxionghonglin%2FDoctorGLM/lists"}