{"id":19054723,"url":"https://github.com/ssbuild/chatglm2_finetuning","last_synced_at":"2025-08-21T03:32:17.720Z","repository":{"id":176466479,"uuid":"658269639","full_name":"ssbuild/chatglm2_finetuning","owner":"ssbuild","description":"chatglm2 6b finetuning and alpaca finetuning","archived":false,"fork":false,"pushed_at":"2024-04-21T16:48:07.000Z","size":406,"stargazers_count":144,"open_issues_count":21,"forks_count":17,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2024-12-11T10:37:19.954Z","etag":null,"topics":["chatglm","chatglm2","chatglm2-6b","deep-training","finetuning","ia3","lora","qlora"],"latest_commit_sha":null,"homepage":"","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/ssbuild.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}},"created_at":"2023-06-25T09:13:00.000Z","updated_at":"2024-09-27T01:56:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"8e31a41a-fcb5-41a1-9f37-9c976c1107cc","html_url":"https://github.com/ssbuild/chatglm2_finetuning","commit_stats":null,"previous_names":["ssbuild/chatglm2_finetuning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbuild%2Fchatglm2_finetuning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbuild%2Fchatglm2_finetuning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbuild%2Fchatglm2_finetuning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssbuild%2Fchatglm2_finetuning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssbuild","download_url":"https://codeload.github.com/ssbuild/chatglm2_finetuning/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230487843,"owners_count":18233865,"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","chatglm2","chatglm2-6b","deep-training","finetuning","ia3","lora","qlora"],"created_at":"2024-11-08T23:39:30.262Z","updated_at":"2024-12-19T19:07:28.585Z","avatar_url":"https://github.com/ssbuild.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"##  statement\r\n```text\r\n    2024-04-22 简化\r\n    2023-10-09 support accelerator trainer\r\n    2023-10-07 support colossalai trainer\r\n    2023-09-26 support transformers trainer\r\n    2023-08-16 解除 chatglm2-6b-int4 全参训练限制， 推理可选使用 Rope NtkScale , 不训练扩展推理长度\r\n    2023-08-02 增加 muti lora infer 例子, 手动升级 aigc_zoo , pip install -U git+https://github.com/ssbuild/deep_training.zoo.git --force-reinstall --no-deps\r\n    2023-07-18 微调经验分享见: https://github.com/ssbuild/aigc_zoo#训练经验分享\r\n    2023-07-16 modify data strategy\r\n    2023-07-04 support ptv2 and arrow_stream,arrow_file,parquet dataset\r\n```\r\n\r\n## install\r\n- [deep_training](https://github.com/ssbuild/deep_training)\r\n- pip install -U -r requirements.txt\r\n- 如果无法安装 , 可以切换官方源 pip install -i https://pypi.org/simple -U -r requirements.txt  \r\n\r\n```text\r\ndev 通过一下方式安装\r\npip install -U git+https://github.com/ssbuild/deep_training.git\r\npip install -U transformers\u003e=4.30 deepspeed xformers bitsandbytes\u003e=0.39 accelerate\u003e=0.20\r\n```\r\n\r\n\r\n## weight\r\n\r\n- [chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b)   支持四种微调方式\r\n- [chatglm2-6b-int4](https://huggingface.co/THUDM/chatglm2-6b-int4)  支持四种微调方式\r\n- [chatglm2-6b-32k](https://huggingface.co/THUDM/chatglm2-6b-32k)   支持四种微调方式\r\n- [chatglm2-6b-32k-int4](https://huggingface.co/ssbuild/chatglm2-6b-32k-int4/tree/main)  支持四种微调方式\r\n\r\n\r\n\r\n## data sample\r\n- [open_data 不定时更新数据集](https://github.com/ssbuild/open_data)\r\n- support tools , 数据构建参考qwen_finetuning llm_finetuning\r\n\r\n单条数据示例\r\n```text\r\nq question\r\na answer \r\n```\r\n\r\n\r\n\r\n```json\r\n{\"id\": 1, \"paragraph\": [{\"q\": \"从南京到上海的路线\", \"a\": [\"你好，南京到上海的路线如下：\", \"1. 南京到上海，可以乘坐南京地铁1号线，在南京站乘坐轨道交通1号线。\", \"2. 南京到浦东机场，可以搭乘上海地铁1号，在陆家嘴站乘坐地铁1线，在浦东国际机场站乘坐机场快线，前往上海浦东国际机场。\", \"3. 上海到南京，可以换乘上海地铁2号线，从南京站换乘地铁2线，再从南京南站换乘地铁1路，然后到达上海站\"]}]}\r\n{\"id\": 2, \"paragraph\": [{\"q\": \"写一个诗歌，关于冬天\", \"a\": [\"冬夜寂静冷，\", \"云在天边飘，\", \"冰封白雪上， \", \"寒冷像一场雪。\", \" \", \"雪花融化成冰，\", \"像那雪花飘洒，\", \"在寒冷的冬天，\", \"感受春天的喜悦。\", \" 冬日里，\", \"风雪渐消，\", \"一片寂静，\", \"把快乐和温暖带回家。\"]}]}\r\n{\"id\": 3, \"paragraph\": [{\"q\": \"晚上睡不着应该怎么办\", \"a\": [\"晚上睡不着可能会让你感到焦虑或不舒服,但以下是一些可以帮助你入睡的方法:\", \"\", \"1. 制定规律的睡眠时间表:保持规律的睡眠时间表可以帮助你建立健康的睡眠习惯,使你更容易入睡。尽量在每天的相同时间上床,并在同一时间起床。\", \"2. 创造一个舒适的睡眠环境:确保睡眠环境舒适,安静,黑暗且温度适宜。可以使用舒适的床上用品,并保持房间通风。\", \"3. 放松身心:在睡前做些放松的活动,例如泡个热水澡,听些轻柔的音乐,阅读一些有趣的书籍等,有助于缓解紧张和焦虑,使你更容易入睡。\", \"4. 避免饮用含有咖啡因的饮料:咖啡因是一种刺激性物质,会影响你的睡眠质量。尽量避免在睡前饮用含有咖啡因的饮料,例如咖啡,茶和可乐。\", \"5. 避免在床上做与睡眠无关的事情:在床上做些与睡眠无关的事情,例如看电影,玩游戏或工作等,可能会干扰你的睡眠。\", \"6. 尝试呼吸技巧:深呼吸是一种放松技巧,可以帮助你缓解紧张和焦虑,使你更容易入睡。试着慢慢吸气,保持几秒钟,然后缓慢呼气。\", \"\", \"如果这些方法无法帮助你入睡,你可以考虑咨询医生或睡眠专家,寻求进一步的建议。\"]}]}\r\n\r\n```\r\n或者\r\n\r\n```json\r\n{\"id\": 1, \"conversations\": [{\"from\": \"user\", \"value\": \"从南京到上海的路线\"}, {\"from\": \"assistant\", \"value\": [\"你好，南京到上海的路线如下：\", \"1. 南京到上海，可以乘坐南京地铁1号线，在南京站乘坐轨道交通1号线。\", \"2. 南京到浦东机场，可以搭乘上海地铁1号，在陆家嘴站乘坐地铁1线，在浦东国际机场站乘坐机场快线，前往上海浦东国际机场。\", \"3. 上海到南京，可以换乘上海地铁2号线，从南京站换乘地铁2线，再从南京南站换乘地铁1路，然后到达上海站\"]}]}\r\n{\"id\": 2, \"conversations\": [{\"from\": \"user\", \"value\": \"写一个诗歌，关于冬天\"}, {\"from\": \"assistant\", \"value\": [\"冬夜寂静冷，\", \"云在天边飘，\", \"冰封白雪上， \", \"寒冷像一场雪。\", \" \", \"雪花融化成冰，\", \"像那雪花飘洒，\", \"在寒冷的冬天，\", \"感受春天的喜悦。\", \" 冬日里，\", \"风雪渐消，\", \"一片寂静，\", \"把快乐和温暖带回家。\"]}]}\r\n{\"id\": 3, \"conversations\": [{\"from\": \"user\", \"value\": \"晚上睡不着应该怎么办\"}, {\"from\": \"assistant\", \"value\": [\"晚上睡不着可能会让你感到焦虑或不舒服,但以下是一些可以帮助你入睡的方法:\", \"\", \"1. 制定规律的睡眠时间表:保持规律的睡眠时间表可以帮助你建立健康的睡眠习惯,使你更容易入睡。尽量在每天的相同时间上床,并在同一时间起床。\", \"2. 创造一个舒适的睡眠环境:确保睡眠环境舒适,安静,黑暗且温度适宜。可以使用舒适的床上用品,并保持房间通风。\", \"3. 放松身心:在睡前做些放松的活动,例如泡个热水澡,听些轻柔的音乐,阅读一些有趣的书籍等,有助于缓解紧张和焦虑,使你更容易入睡。\", \"4. 避免饮用含有咖啡因的饮料:咖啡因是一种刺激性物质,会影响你的睡眠质量。尽量避免在睡前饮用含有咖啡因的饮料,例如咖啡,茶和可乐。\", \"5. 避免在床上做与睡眠无关的事情:在床上做些与睡眠无关的事情,例如看电影,玩游戏或工作等,可能会干扰你的睡眠。\", \"6. 尝试呼吸技巧:深呼吸是一种放松技巧,可以帮助你缓解紧张和焦虑,使你更容易入睡。试着慢慢吸气,保持几秒钟,然后缓慢呼气。\", \"\", \"如果这些方法无法帮助你入睡,你可以考虑咨询医生或睡眠专家,寻求进一步的建议。\"]}]}\r\n```\r\n\r\n\r\n\r\n## infer\r\n    # infer.py 推理预训练模型\r\n    # infer_finetuning.py 推理微调模型\r\n    # infer_lora_finetuning.py 推理lora微调模型\r\n     python infer.py\r\n\r\n\r\n| **量化等级**    | **最低 GPU 显存** |\r\n| -------------- | ----------------- |\r\n| FP16（无量化）   | 13 GB             |\r\n| INT8           | 10 GB              |\r\n| INT4           | 6 GB               |\r\n\r\n   \r\n\r\n![inference](data/1.png)\r\n![inference](data/2.png)\r\n\r\n\r\n\r\n\r\n## training\r\n```text\r\n# 制作数据\r\ncd scripts\r\nbash train_full.sh -m dataset \r\nor\r\nbash train_lora.sh -m dataset \r\nor\r\nbash train_ptv2.sh -m dataset \r\n\r\n注: num_process_worker 为多进程制作数据 ， 如果数据量较大 ， 适当调大至cpu数量\r\ndataHelper.make_dataset_with_args(data_args.train_file,mixed_data=False, shuffle=True,mode='train',num_process_worker=0)\r\n\r\n# 全参数训练 \r\n    bash train_full.sh -m train \r\n    \r\n# lora adalora ia3 \r\n    bash train_lora.sh -m train \r\n    \r\n# ptv2\r\n    bash train_ptv2.sh -m train \r\n```\r\n\r\n## 训练参数\r\n[训练参数](args.MD)\r\n\r\n\r\n\r\n\r\n## 友情链接\r\n\r\n- [pytorch-task-example](https://github.com/ssbuild/pytorch-task-example)\r\n- [tf-task-example](https://github.com/ssbuild/tf-task-example)\r\n- [chatmoss_finetuning](https://github.com/ssbuild/chatmoss_finetuning)\r\n- [chatglm_finetuning](https://github.com/ssbuild/chatglm_finetuning)\r\n- [chatglm2_finetuning](https://github.com/ssbuild/chatglm2_finetuning)\r\n- [chatglm3_finetuning](https://github.com/ssbuild/chatglm3_finetuning)\r\n- [chatyuan_finetuning](https://github.com/ssbuild/chatyuan_finetuning)\r\n- [llm_finetuning](https://github.com/ssbuild/llm_finetuning)\r\n- [rlhf_llm](https://github.com/ssbuild/rlhf_llm)\r\n- [rlhf_chatglm](https://github.com/ssbuild/rlhf_chatglm)\r\n- [rlhf_chatyuan](https://github.com/ssbuild/rlhf_chatyuan)\r\n- [rwkv_finetuning](https://github.com/ssbuild/rwkv_finetuning)\r\n- [baichuan_finetuning](https://github.com/ssbuild/baichuan_finetuning)\r\n- [xverse_finetuning](https://github.com/ssbuild/xverse_finetuning)\r\n- [aigc_serving](https://github.com/ssbuild/aigc_serving)\r\n- [aigc_evals](https://github.com/ssbuild/aigc_evals)\r\n\r\n\r\n## \r\n    纯粹而干净的代码\r\n\r\n\r\n    \r\n\r\n## Reference\r\n    https://huggingface.co/THUDM/chatglm2-6b\r\n\r\n\r\n\r\n\r\n## Star History\r\n\r\n[![Star History Chart](https://api.star-history.com/svg?repos=ssbuild/chatglm2_finetuning\u0026type=Date)](https://star-history.com/#ssbuild/chatglm2_finetuning\u0026Date)\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssbuild%2Fchatglm2_finetuning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssbuild%2Fchatglm2_finetuning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssbuild%2Fchatglm2_finetuning/lists"}