优化项目结构,增加 Examples ToDo
@@ -56,190 +56,190 @@
|
||||
### 已支持模型
|
||||
|
||||
- [Gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it)
|
||||
- [x] [Gemma-2-9b-it FastApi 部署调用](./Gemma2/01-Gemma-2-9b-it%20FastApi%20部署调用.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it langchain 接入](./Gemma2/02-Gemma-2-9b-it%20langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it WebDemo 部署](./Gemma2/03-Gemma-2-9b-it%20WebDemo%20部署.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it Peft Lora 微调](./Gemma2/04-Gemma-2-9b-it%20peft%20lora微调.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it FastApi 部署调用](./models/Gemma2/01-Gemma-2-9b-it%20FastApi%20部署调用.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it langchain 接入](./models/Gemma2/02-Gemma-2-9b-it%20langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it WebDemo 部署](./models/Gemma2/03-Gemma-2-9b-it%20WebDemo%20部署.md) @不要葱姜蒜
|
||||
- [x] [Gemma-2-9b-it Peft Lora 微调](./models/Gemma2/04-Gemma-2-9b-it%20peft%20lora微调.md) @不要葱姜蒜
|
||||
|
||||
- [Yuan2.0](https://github.com/IEIT-Yuan/Yuan-2.0)
|
||||
- [x] [Yuan2.0-2B FastApi 部署调用](./Yuan2.0/01-Yuan2.0-2B%20FastApi%20部署调用.md) @张帆
|
||||
- [x] [Yuan2.0-2B Langchain 接入](./Yuan2.0/02-Yuan2.0-2B%20Langchain%20接入.md) @张帆
|
||||
- [x] [Yuan2.0-2B WebDemo部署](./Yuan2.0/03-Yuan2.0-2B%20WebDemo部署.md) @张帆
|
||||
- [x] [Yuan2.0-2B vLLM部署调用](./Yuan2.0/04-Yuan2.0-2B%20vLLM部署调用.md) @张帆
|
||||
- [x] [Yuan2.0-2B Lora微调](./Yuan2.0/05-Yuan2.0-2B%20Lora微调.md) @张帆
|
||||
- [x] [Yuan2.0-2B FastApi 部署调用](./models/Yuan2.0/01-Yuan2.0-2B%20FastApi%20部署调用.md) @张帆
|
||||
- [x] [Yuan2.0-2B Langchain 接入](./models/Yuan2.0/02-Yuan2.0-2B%20Langchain%20接入.md) @张帆
|
||||
- [x] [Yuan2.0-2B WebDemo部署](./models/Yuan2.0/03-Yuan2.0-2B%20WebDemo部署.md) @张帆
|
||||
- [x] [Yuan2.0-2B vLLM部署调用](./models/Yuan2.0/04-Yuan2.0-2B%20vLLM部署调用.md) @张帆
|
||||
- [x] [Yuan2.0-2B Lora微调](./models/Yuan2.0/05-Yuan2.0-2B%20Lora微调.md) @张帆
|
||||
|
||||
- [Yuan2.0-M32](https://github.com/IEIT-Yuan/Yuan2.0-M32)
|
||||
- [x] [Yuan2.0-M32 FastApi 部署调用](./Yuan2.0-M32/01-Yuan2.0-M32%20FastApi%20部署调用.md) @张帆
|
||||
- [x] [Yuan2.0-M32 Langchain 接入](./Yuan2.0-M32/02-Yuan2.0-M32%20Langchain%20接入.md) @张帆
|
||||
- [x] [Yuan2.0-M32 WebDemo部署](./Yuan2.0-M32/03-Yuan2.0-M32%20WebDemo部署.md) @张帆
|
||||
- [x] [Yuan2.0-M32 FastApi 部署调用](./models/Yuan2.0-M32/01-Yuan2.0-M32%20FastApi%20部署调用.md) @张帆
|
||||
- [x] [Yuan2.0-M32 Langchain 接入](./models/Yuan2.0-M32/02-Yuan2.0-M32%20Langchain%20接入.md) @张帆
|
||||
- [x] [Yuan2.0-M32 WebDemo部署](./models/Yuan2.0-M32/03-Yuan2.0-M32%20WebDemo部署.md) @张帆
|
||||
|
||||
- [DeepSeek-Coder-V2](https://github.com/deepseek-ai/DeepSeek-Coder-V2)
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct FastApi 部署调用](./DeepSeek-Coder-V2/01-DeepSeek-Coder-V2-Lite-Instruct%20FastApi%20部署调用.md) @姜舒凡
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct langchain 接入](./DeepSeek-Coder-V2/02-DeepSeek-Coder-V2-Lite-Instruct%20接入%20LangChain.md) @姜舒凡
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct WebDemo 部署](./DeepSeek-Coder-V2/03-DeepSeek-Coder-V2-Lite-Instruct%20WebDemo%20部署.md) @Kailigithub
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct Lora 微调](./DeepSeek-Coder-V2/04-DeepSeek-Coder-V2-Lite-Instruct%20Lora%20微调.md) @余洋
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct FastApi 部署调用](./models/DeepSeek-Coder-V2/01-DeepSeek-Coder-V2-Lite-Instruct%20FastApi%20部署调用.md) @姜舒凡
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct langchain 接入](./models/DeepSeek-Coder-V2/02-DeepSeek-Coder-V2-Lite-Instruct%20接入%20LangChain.md) @姜舒凡
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct WebDemo 部署](./models/DeepSeek-Coder-V2/03-DeepSeek-Coder-V2-Lite-Instruct%20WebDemo%20部署.md) @Kailigithub
|
||||
- [x] [DeepSeek-Coder-V2-Lite-Instruct Lora 微调](./models/DeepSeek-Coder-V2/04-DeepSeek-Coder-V2-Lite-Instruct%20Lora%20微调.md) @余洋
|
||||
|
||||
- [哔哩哔哩 Index-1.9B](https://github.com/bilibili/Index-1.9B)
|
||||
- [x] [Index-1.9B-Chat FastApi 部署调用](./bilibili_Index-1.9B/01-Index-1.9B-chat%20FastApi%20部署调用.md) @邓恺俊
|
||||
- [x] [Index-1.9B-Chat langchain 接入](./bilibili_Index-1.9B/02-Index-1.9B-Chat%20接入%20LangChain.md) @张友东
|
||||
- [x] [Index-1.9B-Chat WebDemo 部署](./bilibili_Index-1.9B/03-Index-1.9B-chat%20WebDemo部署.md) @九月
|
||||
- [x] [Index-1.9B-Chat Lora 微调](./bilibili_Index-1.9B/04-Index-1.9B-Chat%20Lora%20微调.md) @姜舒凡
|
||||
- [x] [Index-1.9B-Chat FastApi 部署调用](./models/bilibili_Index-1.9B/01-Index-1.9B-chat%20FastApi%20部署调用.md) @邓恺俊
|
||||
- [x] [Index-1.9B-Chat langchain 接入](./models/bilibili_Index-1.9B/02-Index-1.9B-Chat%20接入%20LangChain.md) @张友东
|
||||
- [x] [Index-1.9B-Chat WebDemo 部署](./models/bilibili_Index-1.9B/03-Index-1.9B-chat%20WebDemo部署.md) @九月
|
||||
- [x] [Index-1.9B-Chat Lora 微调](./models/bilibili_Index-1.9B/04-Index-1.9B-Chat%20Lora%20微调.md) @姜舒凡
|
||||
|
||||
- [Qwen2](https://github.com/QwenLM/Qwen2)
|
||||
- [x] [Qwen2-7B-Instruct FastApi 部署调用](./Qwen2/01-Qwen2-7B-Instruct%20FastApi%20部署调用.md) @康婧淇
|
||||
- [x] [Qwen2-7B-Instruct langchain 接入](./Qwen2/02-Qwen2-7B-Instruct%20Langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [Qwen2-7B-Instruct WebDemo 部署](./Qwen2/03-Qwen2-7B-Instruct%20WebDemo部署.md) @三水
|
||||
- [x] [Qwen2-7B-Instruct vLLM 部署调用](./Qwen2/04-Qwen2-7B-Instruct%20vLLM%20部署调用.md) @姜舒凡
|
||||
- [x] [Qwen2-7B-Instruct Lora 微调](./Qwen2/05-Qwen2-7B-Instruct%20Lora%20微调.md) @散步
|
||||
- [x] [Qwen2-7B-Instruct FastApi 部署调用](./models/Qwen2/01-Qwen2-7B-Instruct%20FastApi%20部署调用.md) @康婧淇
|
||||
- [x] [Qwen2-7B-Instruct langchain 接入](./models/Qwen2/02-Qwen2-7B-Instruct%20Langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [Qwen2-7B-Instruct WebDemo 部署](./models/Qwen2/03-Qwen2-7B-Instruct%20WebDemo部署.md) @三水
|
||||
- [x] [Qwen2-7B-Instruct vLLM 部署调用](./models/Qwen2/04-Qwen2-7B-Instruct%20vLLM%20部署调用.md) @姜舒凡
|
||||
- [x] [Qwen2-7B-Instruct Lora 微调](./models/Qwen2/05-Qwen2-7B-Instruct%20Lora%20微调.md) @散步
|
||||
|
||||
- [GLM-4](https://github.com/THUDM/GLM-4.git)
|
||||
- [x] [GLM-4-9B-chat FastApi 部署调用](./GLM-4/01-GLM-4-9B-chat%20FastApi%20部署调用.md) @张友东
|
||||
- [x] [GLM-4-9B-chat langchain 接入](./GLM-4/02-GLM-4-9B-chat%20langchain%20接入.md) @谭逸珂
|
||||
- [x] [GLM-4-9B-chat WebDemo 部署](./GLM-4/03-GLM-4-9B-Chat%20WebDemo.md) @何至轩
|
||||
- [x] [GLM-4-9B-chat vLLM 部署](./GLM-4/04-GLM-4-9B-Chat%20vLLM%20部署调用.md) @王熠明
|
||||
- [x] [GLM-4-9B-chat Lora 微调](./GLM-4/05-GLM-4-9B-chat%20Lora%20微调.md) @肖鸿儒
|
||||
- [x] [GLM-4-9B-chat FastApi 部署调用](./models/GLM-4/01-GLM-4-9B-chat%20FastApi%20部署调用.md) @张友东
|
||||
- [x] [GLM-4-9B-chat langchain 接入](./models/GLM-4/02-GLM-4-9B-chat%20langchain%20接入.md) @谭逸珂
|
||||
- [x] [GLM-4-9B-chat WebDemo 部署](./models/GLM-4/03-GLM-4-9B-Chat%20WebDemo.md) @何至轩
|
||||
- [x] [GLM-4-9B-chat vLLM 部署](./models/GLM-4/04-GLM-4-9B-Chat%20vLLM%20部署调用.md) @王熠明
|
||||
- [x] [GLM-4-9B-chat Lora 微调](./models/GLM-4/05-GLM-4-9B-chat%20Lora%20微调.md) @肖鸿儒
|
||||
|
||||
- [Qwen 1.5](https://github.com/QwenLM/Qwen1.5.git)
|
||||
- [x] [Qwen1.5-7B-chat FastApi 部署调用](./Qwen1.5/01-Qwen1.5-7B-Chat%20FastApi%20部署调用.md) @颜鑫
|
||||
- [x] [Qwen1.5-7B-chat langchain 接入](./Qwen1.5/02-Qwen1.5-7B-Chat%20接入langchain搭建知识库助手.md) @颜鑫
|
||||
- [x] [Qwen1.5-7B-chat WebDemo 部署](./Qwen1.5/03-Qwen1.5-7B-Chat%20WebDemo.md) @颜鑫
|
||||
- [x] [Qwen1.5-7B-chat Lora 微调](./Qwen1.5/04-Qwen1.5-7B-chat%20Lora%20微调.md) @不要葱姜蒜
|
||||
- [x] [Qwen1.5-72B-chat-GPTQ-Int4 部署环境](./Qwen1.5/05-Qwen1.5-7B-Chat-GPTQ-Int4%20%20WebDemo.md) @byx020119
|
||||
- [x] [Qwen1.5-MoE-chat Transformers 部署调用](./Qwen1.5/06-Qwen1.5-MoE-A2.7B.md) @丁悦
|
||||
- [x] [Qwen1.5-7B-chat vLLM推理部署](./Qwen1.5/07-Qwen1.5-7B-Chat%20vLLM%20推理部署调用.md) @高立业
|
||||
- [x] [Qwen1.5-7B-chat Lora 微调 接入SwanLab实验管理平台](./Qwen1.5/08-Qwen1.5-7B-chat%20LoRA微调接入实验管理.md) @黄柏特
|
||||
- [x] [Qwen1.5-7B-chat FastApi 部署调用](./models/Qwen1.5/01-Qwen1.5-7B-Chat%20FastApi%20部署调用.md) @颜鑫
|
||||
- [x] [Qwen1.5-7B-chat langchain 接入](./models/Qwen1.5/02-Qwen1.5-7B-Chat%20接入langchain搭建知识库助手.md) @颜鑫
|
||||
- [x] [Qwen1.5-7B-chat WebDemo 部署](./models/Qwen1.5/03-Qwen1.5-7B-Chat%20WebDemo.md) @颜鑫
|
||||
- [x] [Qwen1.5-7B-chat Lora 微调](./models/Qwen1.5/04-Qwen1.5-7B-chat%20Lora%20微调.md) @不要葱姜蒜
|
||||
- [x] [Qwen1.5-72B-chat-GPTQ-Int4 部署环境](./models/Qwen1.5/05-Qwen1.5-7B-Chat-GPTQ-Int4%20%20WebDemo.md) @byx020119
|
||||
- [x] [Qwen1.5-MoE-chat Transformers 部署调用](./models/Qwen1.5/06-Qwen1.5-MoE-A2.7B.md) @丁悦
|
||||
- [x] [Qwen1.5-7B-chat vLLM推理部署](./models/Qwen1.5/07-Qwen1.5-7B-Chat%20vLLM%20推理部署调用.md) @高立业
|
||||
- [x] [Qwen1.5-7B-chat Lora 微调 接入SwanLab实验管理平台](./models/Qwen1.5/08-Qwen1.5-7B-chat%20LoRA微调接入实验管理.md) @黄柏特
|
||||
|
||||
- [谷歌-Gemma](https://huggingface.co/google/gemma-7b-it)
|
||||
- [x] [gemma-2b-it FastApi 部署调用 ](./Gemma/01-Gemma-2B-Instruct%20FastApi%20部署调用.md) @东东
|
||||
- [x] [gemma-2b-it langchain 接入 ](./Gemma/02-Gemma-2B-Instruct%20langchain%20接入.md) @东东
|
||||
- [x] [gemma-2b-it WebDemo 部署 ](./Gemma/03-Gemma-2B-Instruct%20WebDemo%20部署.md) @东东
|
||||
- [x] [gemma-2b-it Peft Lora 微调 ](./Gemma/04-Gemma-2B-Instruct%20Lora微调.md) @东东
|
||||
- [x] [gemma-2b-it FastApi 部署调用 ](./models/Gemma/01-Gemma-2B-Instruct%20FastApi%20部署调用.md) @东东
|
||||
- [x] [gemma-2b-it langchain 接入 ](./models/Gemma/02-Gemma-2B-Instruct%20langchain%20接入.md) @东东
|
||||
- [x] [gemma-2b-it WebDemo 部署 ](./models/Gemma/03-Gemma-2B-Instruct%20WebDemo%20部署.md) @东东
|
||||
- [x] [gemma-2b-it Peft Lora 微调 ](./models/Gemma/04-Gemma-2B-Instruct%20Lora微调.md) @东东
|
||||
|
||||
- [phi-3](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct)
|
||||
- [x] [Phi-3-mini-4k-instruct FastApi 部署调用](./phi-3/01-Phi-3-mini-4k-instruct%20FastApi%20部署调用.md) @郑皓桦
|
||||
- [x] [Phi-3-mini-4k-instruct langchain 接入](./phi-3/02-Phi-3-mini-4k-instruct%20langchain%20接入.md) @郑皓桦
|
||||
- [x] [Phi-3-mini-4k-instruct WebDemo 部署](./phi-3/03-Phi-3-mini-4k-instruct%20WebDemo部署.md) @丁悦
|
||||
- [x] [Phi-3-mini-4k-instruct Lora 微调](./phi-3/04-Phi-3-mini-4k-Instruct%20Lora%20微调.md) @丁悦
|
||||
- [x] [Phi-3-mini-4k-instruct FastApi 部署调用](./models/phi-3/01-Phi-3-mini-4k-instruct%20FastApi%20部署调用.md) @郑皓桦
|
||||
- [x] [Phi-3-mini-4k-instruct langchain 接入](./models/phi-3/02-Phi-3-mini-4k-instruct%20langchain%20接入.md) @郑皓桦
|
||||
- [x] [Phi-3-mini-4k-instruct WebDemo 部署](./models/phi-3/03-Phi-3-mini-4k-instruct%20WebDemo部署.md) @丁悦
|
||||
- [x] [Phi-3-mini-4k-instruct Lora 微调](./models/phi-3/04-Phi-3-mini-4k-Instruct%20Lora%20微调.md) @丁悦
|
||||
|
||||
- [CharacterGLM-6B](https://github.com/thu-coai/CharacterGLM-6B)
|
||||
- [x] [CharacterGLM-6B Transformers 部署调用](./CharacterGLM/01-CharacterGLM-6B%20Transformer部署调用.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B FastApi 部署调用](./CharacterGLM/02-CharacterGLM-6B%20FastApi部署调用.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B webdemo 部署](./CharacterGLM/03-CharacterGLM-6B-chat.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B Lora 微调](./CharacterGLM/04-CharacterGLM-6B%20Lora微调.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B Transformers 部署调用](./models/CharacterGLM/01-CharacterGLM-6B%20Transformer部署调用.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B FastApi 部署调用](./models/CharacterGLM/02-CharacterGLM-6B%20FastApi部署调用.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B webdemo 部署](./models/CharacterGLM/03-CharacterGLM-6B-chat.md) @孙健壮
|
||||
- [x] [CharacterGLM-6B Lora 微调](./models/CharacterGLM/04-CharacterGLM-6B%20Lora微调.md) @孙健壮
|
||||
|
||||
- [LLaMA3-8B-Instruct](https://github.com/meta-llama/llama3.git)
|
||||
- [x] [LLaMA3-8B-Instruct FastApi 部署调用](./LLaMA3/01-LLaMA3-8B-Instruct%20FastApi%20部署调用.md) @高立业
|
||||
- [X] [LLaMA3-8B-Instruct langchain 接入](./LLaMA3/02-LLaMA3-8B-Instruct%20langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [LLaMA3-8B-Instruct WebDemo 部署](./LLaMA3/03-LLaMA3-8B-Instruct%20WebDemo%20部署.md) @不要葱姜蒜
|
||||
- [x] [LLaMA3-8B-Instruct Lora 微调](./LLaMA3/04-LLaMA3-8B-Instruct%20Lora%20微调.md) @高立业
|
||||
- [x] [LLaMA3-8B-Instruct FastApi 部署调用](./models/LLaMA3/01-LLaMA3-8B-Instruct%20FastApi%20部署调用.md) @高立业
|
||||
- [X] [LLaMA3-8B-Instruct langchain 接入](./models/LLaMA3/02-LLaMA3-8B-Instruct%20langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [LLaMA3-8B-Instruct WebDemo 部署](./models/LLaMA3/03-LLaMA3-8B-Instruct%20WebDemo%20部署.md) @不要葱姜蒜
|
||||
- [x] [LLaMA3-8B-Instruct Lora 微调](./models/LLaMA3/04-LLaMA3-8B-Instruct%20Lora%20微调.md) @高立业
|
||||
|
||||
- [XVERSE-7B-Chat](https://modelscope.cn/models/xverse/XVERSE-7B-Chat/summary)
|
||||
- [x] [XVERSE-7B-Chat transformers 部署调用](./XVERSE/01-XVERSE-7B-chat%20Transformers推理.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat FastApi 部署调用](./XVERSE/02-XVERSE-7B-chat%20FastAPI部署.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat langchain 接入](./XVERSE/03-XVERSE-7B-chat%20langchain%20接入.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat WebDemo 部署](./XVERSE/04-XVERSE-7B-chat%20WebDemo%20部署.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat Lora 微调](./XVERSE/05-XVERSE-7B-Chat%20Lora%20微调.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat transformers 部署调用](./models/XVERSE/01-XVERSE-7B-chat%20Transformers推理.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat FastApi 部署调用](./models/XVERSE/02-XVERSE-7B-chat%20FastAPI部署.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat langchain 接入](./models/XVERSE/03-XVERSE-7B-chat%20langchain%20接入.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat WebDemo 部署](./models/XVERSE/04-XVERSE-7B-chat%20WebDemo%20部署.md) @郭志航
|
||||
- [x] [XVERSE-7B-Chat Lora 微调](./models/XVERSE/05-XVERSE-7B-Chat%20Lora%20微调.md) @郭志航
|
||||
|
||||
- [TransNormerLLM](https://github.com/OpenNLPLab/TransnormerLLM.git)
|
||||
- [X] [TransNormerLLM-7B-Chat FastApi 部署调用](./TransNormer/01-TransNormer-7B%20FastApi%20部署调用.md) @王茂霖
|
||||
- [X] [TransNormerLLM-7B-Chat langchain 接入](./TransNormer/02-TransNormer-7B%20接入langchain搭建知识库助手.md) @王茂霖
|
||||
- [X] [TransNormerLLM-7B-Chat WebDemo 部署](./TransNormer/03-TransNormer-7B%20WebDemo.md) @王茂霖
|
||||
- [x] [TransNormerLLM-7B-Chat Lora 微调](./TransNormer/04-TrasnNormer-7B%20Lora%20微调.md) @王茂霖
|
||||
- [X] [TransNormerLLM-7B-Chat FastApi 部署调用](./models/TransNormer/01-TransNormer-7B%20FastApi%20部署调用.md) @王茂霖
|
||||
- [X] [TransNormerLLM-7B-Chat langchain 接入](./models/TransNormer/02-TransNormer-7B%20接入langchain搭建知识库助手.md) @王茂霖
|
||||
- [X] [TransNormerLLM-7B-Chat WebDemo 部署](./models/TransNormer/03-TransNormer-7B%20WebDemo.md) @王茂霖
|
||||
- [x] [TransNormerLLM-7B-Chat Lora 微调](./models/TransNormer/04-TrasnNormer-7B%20Lora%20微调.md) @王茂霖
|
||||
|
||||
- [BlueLM Vivo 蓝心大模型](https://github.com/vivo-ai-lab/BlueLM.git)
|
||||
- [x] [BlueLM-7B-Chat FatApi 部署调用](./BlueLM/01-BlueLM-7B-Chat%20FastApi%20部署.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat langchain 接入](./BlueLM/02-BlueLM-7B-Chat%20langchain%20接入.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat WebDemo 部署](./BlueLM/03-BlueLM-7B-Chat%20WebDemo%20部署.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat Lora 微调](./BlueLM/04-BlueLM-7B-Chat%20Lora%20微调.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat FatApi 部署调用](./models/BlueLM/01-BlueLM-7B-Chat%20FastApi%20部署.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat langchain 接入](./models/BlueLM/02-BlueLM-7B-Chat%20langchain%20接入.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat WebDemo 部署](./models/BlueLM/03-BlueLM-7B-Chat%20WebDemo%20部署.md) @郭志航
|
||||
- [x] [BlueLM-7B-Chat Lora 微调](./models/BlueLM/04-BlueLM-7B-Chat%20Lora%20微调.md) @郭志航
|
||||
|
||||
- [InternLM2](https://github.com/InternLM/InternLM)
|
||||
- [x] [InternLM2-7B-chat FastApi 部署调用](./InternLM2/01-InternLM2-7B-chat%20FastAPI部署.md) @不要葱姜蒜
|
||||
- [x] [InternLM2-7B-chat langchain 接入](./InternLM2/02-InternLM2-7B-chat%20langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [InternLM2-7B-chat WebDemo 部署](./InternLM2/03-InternLM2-7B-chat%20WebDemo%20部署.md) @郑皓桦
|
||||
- [x] [InternLM2-7B-chat Xtuner Qlora 微调](./InternLM2/04-InternLM2-7B-chat%20Xtuner%20Qlora%20微调.md) @郑皓桦
|
||||
- [x] [InternLM2-7B-chat FastApi 部署调用](./models/InternLM2/01-InternLM2-7B-chat%20FastAPI部署.md) @不要葱姜蒜
|
||||
- [x] [InternLM2-7B-chat langchain 接入](./models/InternLM2/02-InternLM2-7B-chat%20langchain%20接入.md) @不要葱姜蒜
|
||||
- [x] [InternLM2-7B-chat WebDemo 部署](./models/InternLM2/03-InternLM2-7B-chat%20WebDemo%20部署.md) @郑皓桦
|
||||
- [x] [InternLM2-7B-chat Xtuner Qlora 微调](./models/InternLM2/04-InternLM2-7B-chat%20Xtuner%20Qlora%20微调.md) @郑皓桦
|
||||
|
||||
- [DeepSeek 深度求索](https://github.com/deepseek-ai/DeepSeek-LLM)
|
||||
- [x] [DeepSeek-7B-chat FastApi 部署调用](./DeepSeek/01-DeepSeek-7B-chat%20FastApi.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat langchain 接入](./DeepSeek/02-DeepSeek-7B-chat%20langchain.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat WebDemo](./DeepSeek/03-DeepSeek-7B-chat%20WebDemo.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat Lora 微调](./DeepSeek/04-DeepSeek-7B-chat%20Lora%20微调.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat 4bits量化 Qlora 微调](./DeepSeek/05-DeepSeek-7B-chat%204bits量化%20Qlora%20微调.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-MoE-16b-chat Transformers 部署调用](./DeepSeek/06-DeepSeek-MoE-16b-chat%20Transformer部署调用.md) @Kailigithub
|
||||
- [x] [DeepSeek-MoE-16b-chat FastApi 部署调用](./DeepSeek/06-DeepSeek-MoE-16b-chat%20FastApi.md) @Kailigithub
|
||||
- [x] [DeepSeek-coder-6.7b finetune colab](./DeepSeek/07-deepseek_fine_tune.ipynb) @Swiftie
|
||||
- [x] [Deepseek-coder-6.7b webdemo colab](./DeepSeek/08-deepseek_web_demo.ipynb) @Swiftie
|
||||
- [x] [DeepSeek-7B-chat FastApi 部署调用](./models/DeepSeek/01-DeepSeek-7B-chat%20FastApi.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat langchain 接入](./models/DeepSeek/02-DeepSeek-7B-chat%20langchain.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat WebDemo](./models/DeepSeek/03-DeepSeek-7B-chat%20WebDemo.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat Lora 微调](./models/DeepSeek/04-DeepSeek-7B-chat%20Lora%20微调.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-7B-chat 4bits量化 Qlora 微调](./models/DeepSeek/05-DeepSeek-7B-chat%204bits量化%20Qlora%20微调.md) @不要葱姜蒜
|
||||
- [x] [DeepSeek-MoE-16b-chat Transformers 部署调用](./models/DeepSeek/06-DeepSeek-MoE-16b-chat%20Transformer部署调用.md) @Kailigithub
|
||||
- [x] [DeepSeek-MoE-16b-chat FastApi 部署调用](./models/DeepSeek/06-DeepSeek-MoE-16b-chat%20FastApi.md) @Kailigithub
|
||||
- [x] [DeepSeek-coder-6.7b finetune colab](./models/DeepSeek/07-deepseek_fine_tune.ipynb) @Swiftie
|
||||
- [x] [Deepseek-coder-6.7b webdemo colab](./models/DeepSeek/08-deepseek_web_demo.ipynb) @Swiftie
|
||||
|
||||
- [MiniCPM](https://github.com/OpenBMB/MiniCPM.git)
|
||||
- [x] [MiniCPM-2B-chat transformers 部署调用](./MiniCPM/MiniCPM-2B-chat%20transformers%20部署调用.md) @Kailigithub
|
||||
- [x] [MiniCPM-2B-chat FastApi 部署调用](./MiniCPM/MiniCPM-2B-chat%20FastApi%20部署调用.md) @Kailigithub
|
||||
- [x] [MiniCPM-2B-chat langchain 接入](./MiniCPM/MiniCPM-2B-chat%20langchain接入.md) @不要葱姜蒜
|
||||
- [x] [MiniCPM-2B-chat webdemo 部署](./MiniCPM/MiniCPM-2B-chat%20WebDemo部署.md) @Kailigithub
|
||||
- [x] [MiniCPM-2B-chat Lora && Full 微调](./MiniCPM/MiniCPM-2B-chat%20Lora%20&&%20Full%20微调.md) @不要葱姜蒜
|
||||
- [x] [MiniCPM-2B-chat transformers 部署调用](./models/MiniCPM/MiniCPM-2B-chat%20transformers%20部署调用.md) @Kailigithub
|
||||
- [x] [MiniCPM-2B-chat FastApi 部署调用](./models/MiniCPM/MiniCPM-2B-chat%20FastApi%20部署调用.md) @Kailigithub
|
||||
- [x] [MiniCPM-2B-chat langchain 接入](./models/MiniCPM/MiniCPM-2B-chat%20langchain接入.md) @不要葱姜蒜
|
||||
- [x] [MiniCPM-2B-chat webdemo 部署](./models/MiniCPM/MiniCPM-2B-chat%20WebDemo部署.md) @Kailigithub
|
||||
- [x] [MiniCPM-2B-chat Lora && Full 微调](./models/MiniCPM/MiniCPM-2B-chat%20Lora%20&&%20Full%20微调.md) @不要葱姜蒜
|
||||
|
||||
- [Qwen-Audio](https://github.com/QwenLM/Qwen-Audio.git)
|
||||
- [x] [Qwen-Audio FastApi 部署调用](./Qwen-Audio/01-Qwen-Audio-chat%20FastApi.md) @陈思州
|
||||
- [x] [Qwen-Audio WebDemo](./Qwen-Audio/02-Qwen-Audio-chat%20WebDemo.md) @陈思州
|
||||
- [x] [Qwen-Audio FastApi 部署调用](./models/Qwen-Audio/01-Qwen-Audio-chat%20FastApi.md) @陈思州
|
||||
- [x] [Qwen-Audio WebDemo](./models/Qwen-Audio/02-Qwen-Audio-chat%20WebDemo.md) @陈思州
|
||||
|
||||
- [Qwen](https://github.com/QwenLM/Qwen.git)
|
||||
- [x] [Qwen-7B-chat Transformers 部署调用](./Qwen/01-Qwen-7B-Chat%20Transformers部署调用.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat FastApi 部署调用](./Qwen/02-Qwen-7B-Chat%20FastApi%20部署调用.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat WebDemo](./Qwen/03-Qwen-7B-Chat%20WebDemo.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat Lora 微调](./Qwen/04-Qwen-7B-Chat%20Lora%20微调.md) @不要葱姜蒜
|
||||
- [x] [Qwen-7B-chat ptuning 微调](./Qwen/05-Qwen-7B-Chat%20Ptuning%20微调.md) @肖鸿儒
|
||||
- [x] [Qwen-7B-chat 全量微调](./Qwen/06-Qwen-7B-chat%20全量微调.md) @不要葱姜蒜
|
||||
- [x] [Qwen-7B-Chat 接入langchain搭建知识库助手](./Qwen/07-Qwen-7B-Chat%20接入langchain搭建知识库助手.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat 低精度训练](./Qwen/08-Qwen-7B-Chat%20Lora%20低精度微调.md) @肖鸿儒
|
||||
- [x] [Qwen-1_8B-chat CPU 部署](./Qwen/09-Qwen-1_8B-chat%20CPU%20部署%20.md) @散步
|
||||
- [x] [Qwen-7B-chat Transformers 部署调用](./models/Qwen/01-Qwen-7B-Chat%20Transformers部署调用.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat FastApi 部署调用](./models/Qwen/02-Qwen-7B-Chat%20FastApi%20部署调用.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat WebDemo](./models/Qwen/03-Qwen-7B-Chat%20WebDemo.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat Lora 微调](./models/Qwen/04-Qwen-7B-Chat%20Lora%20微调.md) @不要葱姜蒜
|
||||
- [x] [Qwen-7B-chat ptuning 微调](./models/Qwen/05-Qwen-7B-Chat%20Ptuning%20微调.md) @肖鸿儒
|
||||
- [x] [Qwen-7B-chat 全量微调](./models/Qwen/06-Qwen-7B-chat%20全量微调.md) @不要葱姜蒜
|
||||
- [x] [Qwen-7B-Chat 接入langchain搭建知识库助手](./models/Qwen/07-Qwen-7B-Chat%20接入langchain搭建知识库助手.md) @李娇娇
|
||||
- [x] [Qwen-7B-chat 低精度训练](./models/Qwen/08-Qwen-7B-Chat%20Lora%20低精度微调.md) @肖鸿儒
|
||||
- [x] [Qwen-1_8B-chat CPU 部署](./models/Qwen/09-Qwen-1_8B-chat%20CPU%20部署%20.md) @散步
|
||||
|
||||
- [Yi 零一万物](https://github.com/01-ai/Yi.git)
|
||||
- [x] [Yi-6B-chat FastApi 部署调用](./Yi/01-Yi-6B-Chat%20FastApi%20部署调用.md) @李柯辰
|
||||
- [x] [Yi-6B-chat langchain接入](./Yi/02-Yi-6B-Chat%20接入langchain搭建知识库助手.md) @李柯辰
|
||||
- [x] [Yi-6B-chat WebDemo](./Yi/03-Yi-6B-chat%20WebDemo.md) @肖鸿儒
|
||||
- [x] [Yi-6B-chat Lora 微调](./Yi/04-Yi-6B-Chat%20Lora%20微调.md) @李娇娇
|
||||
- [x] [Yi-6B-chat FastApi 部署调用](./models/Yi/01-Yi-6B-Chat%20FastApi%20部署调用.md) @李柯辰
|
||||
- [x] [Yi-6B-chat langchain接入](./models/Yi/02-Yi-6B-Chat%20接入langchain搭建知识库助手.md) @李柯辰
|
||||
- [x] [Yi-6B-chat WebDemo](./models/Yi/03-Yi-6B-chat%20WebDemo.md) @肖鸿儒
|
||||
- [x] [Yi-6B-chat Lora 微调](./models/Yi/04-Yi-6B-Chat%20Lora%20微调.md) @李娇娇
|
||||
|
||||
- [Baichuan 百川智能](https://www.baichuan-ai.com/home)
|
||||
- [x] [Baichuan2-7B-chat FastApi 部署调用](./BaiChuan/01-Baichuan2-7B-chat%2BFastApi%2B%E9%83%A8%E7%BD%B2%E8%B0%83%E7%94%A8.md) @惠佳豪
|
||||
- [x] [Baichuan2-7B-chat WebDemo](./BaiChuan/02-Baichuan-7B-chat%2BWebDemo.md) @惠佳豪
|
||||
- [x] [Baichuan2-7B-chat 接入 LangChain 框架](./BaiChuan/03-Baichuan2-7B-chat%E6%8E%A5%E5%85%A5LangChain%E6%A1%86%E6%9E%B6.md) @惠佳豪
|
||||
- [x] [Baichuan2-7B-chat Lora 微调](./BaiChuan/04-Baichuan2-7B-chat%2Blora%2B%E5%BE%AE%E8%B0%83.md) @惠佳豪
|
||||
- [x] [Baichuan2-7B-chat WebDemo](./models/BaiChuan/02-Baichuan-7B-chat%2BWebDemo.md) @惠佳豪
|
||||
- [x] [Baichuan2-7B-chat 接入 LangChain 框架](./models/BaiChuan/03-Baichuan2-7B-chat%E6%8E%A5%E5%85%A5LangChain%E6%A1%86%E6%9E%B6.md) @惠佳豪
|
||||
- [x] [Baichuan2-7B-chat Lora 微调](./models/BaiChuan/04-Baichuan2-7B-chat%2Blora%2B%E5%BE%AE%E8%B0%83.md) @惠佳豪
|
||||
|
||||
- [InternLM](https://github.com/InternLM/InternLM.git)
|
||||
- [x] [InternLM-Chat-7B Transformers 部署调用](./InternLM/01-InternLM-Chat-7B%20Transformers%20部署调用.md) @小罗
|
||||
- [x] [InternLM-Chat-7B FastApi 部署调用](InternLM/02-internLM-Chat-7B%20FastApi.md) @不要葱姜蒜
|
||||
- [x] [InternLM-Chat-7B WebDemo](InternLM/03-InternLM-Chat-7B.md) @不要葱姜蒜
|
||||
- [x] [Lagent+InternLM-Chat-7B-V1.1 WebDemo](InternLM/04-Lagent+InternLM-Chat-7B-V1.1.md) @不要葱姜蒜
|
||||
- [x] [浦语灵笔图文理解&创作 WebDemo](InternLM/05-浦语灵笔图文理解&创作.md) @不要葱姜蒜
|
||||
- [x] [InternLM-Chat-7B 接入 LangChain 框架](InternLM/06-InternLM接入LangChain搭建知识库助手.md) @Logan Zou
|
||||
- [x] [InternLM-Chat-7B Transformers 部署调用](./models/InternLM/01-InternLM-Chat-7B%20Transformers%20部署调用.md) @小罗
|
||||
- [x] [InternLM-Chat-7B FastApi 部署调用](./models/InternLM/02-internLM-Chat-7B%20FastApi.md) @不要葱姜蒜
|
||||
- [x] [InternLM-Chat-7B WebDemo](./models/InternLM/03-InternLM-Chat-7B.md) @不要葱姜蒜
|
||||
- [x] [Lagent+InternLM-Chat-7B-V1.1 WebDemo](./models/InternLM/04-Lagent+InternLM-Chat-7B-V1.1.md) @不要葱姜蒜
|
||||
- [x] [浦语灵笔图文理解&创作 WebDemo](./models/InternLM/05-浦语灵笔图文理解&创作.md) @不要葱姜蒜
|
||||
- [x] [InternLM-Chat-7B 接入 LangChain 框架](./models/InternLM/06-InternLM接入LangChain搭建知识库助手.md) @Logan Zou
|
||||
|
||||
- [Atom (llama2)](https://hf-mirror.com/FlagAlpha/Atom-7B-Chat)
|
||||
- [x] [Atom-7B-chat WebDemo](./Atom/01-Atom-7B-chat-WebDemo.md) @Kailigithub
|
||||
- [x] [Atom-7B-chat Lora 微调](./Atom/02-Atom-7B-Chat%20Lora%20微调.md) @Logan Zou
|
||||
- [x] [Atom-7B-Chat 接入langchain搭建知识库助手](./Atom/03-Atom-7B-Chat%20接入langchain搭建知识库助手.md) @陈思州
|
||||
- [x] [Atom-7B-chat 全量微调](./Atom/04-Atom-7B-chat%20全量微调.md) @Logan Zou
|
||||
- [x] [Atom-7B-chat WebDemo](./models/Atom/01-Atom-7B-chat-WebDemo.md) @Kailigithub
|
||||
- [x] [Atom-7B-chat Lora 微调](./models/Atom/02-Atom-7B-Chat%20Lora%20微调.md) @Logan Zou
|
||||
- [x] [Atom-7B-Chat 接入langchain搭建知识库助手](./models/Atom/03-Atom-7B-Chat%20接入langchain搭建知识库助手.md) @陈思州
|
||||
- [x] [Atom-7B-chat 全量微调](./models/Atom/04-Atom-7B-chat%20全量微调.md) @Logan Zou
|
||||
|
||||
- [ChatGLM3](https://github.com/THUDM/ChatGLM3.git)
|
||||
- [x] [ChatGLM3-6B Transformers 部署调用](./ChatGLM/01-ChatGLM3-6B%20Transformer部署调用.md) @丁悦
|
||||
- [x] [ChatGLM3-6B FastApi 部署调用](./ChatGLM/02-ChatGLM3-6B%20FastApi部署调用.md) @丁悦
|
||||
- [x] [ChatGLM3-6B chat WebDemo](ChatGLM/03-ChatGLM3-6B-chat.md) @不要葱姜蒜
|
||||
- [x] [ChatGLM3-6B Code Interpreter WebDemo](ChatGLM/04-ChatGLM3-6B-Code-Interpreter.md) @不要葱姜蒜
|
||||
- [x] [ChatGLM3-6B 接入 LangChain 框架](ChatGLM/05-ChatGLM3-6B接入LangChain搭建知识库助手.md) @Logan Zou
|
||||
- [x] [ChatGLM3-6B Lora 微调](ChatGLM/06-ChatGLM3-6B-Lora微调.md) @肖鸿儒
|
||||
- [x] [ChatGLM3-6B Transformers 部署调用](./models/ChatGLM/01-ChatGLM3-6B%20Transformer部署调用.md) @丁悦
|
||||
- [x] [ChatGLM3-6B FastApi 部署调用](./models/ChatGLM/02-ChatGLM3-6B%20FastApi部署调用.md) @丁悦
|
||||
- [x] [ChatGLM3-6B chat WebDemo](./models/ChatGLM/03-ChatGLM3-6B-chat.md) @不要葱姜蒜
|
||||
- [x] [ChatGLM3-6B Code Interpreter WebDemo](./models/ChatGLM/04-ChatGLM3-6B-Code-Interpreter.md) @不要葱姜蒜
|
||||
- [x] [ChatGLM3-6B 接入 LangChain 框架](./models/ChatGLM/05-ChatGLM3-6B接入LangChain搭建知识库助手.md) @Logan Zou
|
||||
- [x] [ChatGLM3-6B Lora 微调](./models/ChatGLM/06-ChatGLM3-6B-Lora微调.md) @肖鸿儒
|
||||
|
||||
### 通用环境配置
|
||||
|
||||
- [x] [pip、conda 换源](./General-Setting/01-pip、conda换源.md) @不要葱姜蒜
|
||||
- [x] [AutoDL 开放端口](./General-Setting/02-AutoDL开放端口.md) @不要葱姜蒜
|
||||
- [x] [pip、conda 换源](./models/General-Setting/01-pip、conda换源.md) @不要葱姜蒜
|
||||
- [x] [AutoDL 开放端口](./models/General-Setting/02-AutoDL开放端口.md) @不要葱姜蒜
|
||||
|
||||
- 模型下载
|
||||
- [x] [hugging face](./General-Setting/03-模型下载.md) @不要葱姜蒜
|
||||
- [x] [hugging face](./models/General-Setting/03-模型下载.md) @不要葱姜蒜
|
||||
- [x] [hugging face](./General-Setting/03-模型下载.md) 镜像下载 @不要葱姜蒜
|
||||
- [x] [modelscope](./General-Setting/03-模型下载.md) @不要葱姜蒜
|
||||
- [x] [git-lfs](./General-Setting/03-模型下载.md) @不要葱姜蒜
|
||||
- [x] [Openxlab](./General-Setting/03-模型下载.md)
|
||||
- [x] [modelscope](./models/General-Setting/03-模型下载.md) @不要葱姜蒜
|
||||
- [x] [git-lfs](./models/General-Setting/03-模型下载.md) @不要葱姜蒜
|
||||
- [x] [Openxlab](./models/General-Setting/03-模型下载.md)
|
||||
- Issue && PR
|
||||
- [x] [Issue 提交](./General-Setting/04-Issue&PR&update.md) @肖鸿儒
|
||||
- [x] [PR 提交](./General-Setting/04-Issue&PR&update.md) @肖鸿儒
|
||||
- [x] [fork更新](./General-Setting/04-Issue&PR&update.md) @肖鸿儒
|
||||
- [x] [Issue 提交](./models/General-Setting/04-Issue&PR&update.md) @肖鸿儒
|
||||
- [x] [PR 提交](./models/General-Setting/04-Issue&PR&update.md) @肖鸿儒
|
||||
- [x] [fork更新](./models/General-Setting/04-Issue&PR&update.md) @肖鸿儒
|
||||
|
||||
## 致谢
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# self-llm Examples
|
||||
|
||||
在学习者完成了基础部分的学习之后,我们将会提供一些例子来帮助学习者更好的理解和掌握大模型应用开发。我们会以应用类型为向导,提供一些优秀的大模型应用项目案例 Demo ,使得学习者完成我们的 examples 后,能够更好的理解和掌握大模型应用开发的技术要点和掌握大模型应用二次开发或单独开发的能力。
|
||||
|
||||
## Examples 目录
|
||||
|
||||
- 角色扮演
|
||||
- [ ] Chat-嬛嬛
|
||||
- [ ] Chat-悟空
|
||||
- 办公效率
|
||||
- [ ] 搭建 RAG 对话系统
|
||||
- 学习教育
|
||||
- [ ] ChatTest
|
||||
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 292 KiB After Width: | Height: | Size: 292 KiB |
|
Before Width: | Height: | Size: 205 KiB After Width: | Height: | Size: 205 KiB |
|
Before Width: | Height: | Size: 284 KiB After Width: | Height: | Size: 284 KiB |
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
|
Before Width: | Height: | Size: 282 KiB After Width: | Height: | Size: 282 KiB |
|
Before Width: | Height: | Size: 226 KiB After Width: | Height: | Size: 226 KiB |
|
Before Width: | Height: | Size: 157 KiB After Width: | Height: | Size: 157 KiB |
|
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 305 KiB After Width: | Height: | Size: 305 KiB |
|
Before Width: | Height: | Size: 184 KiB After Width: | Height: | Size: 184 KiB |
|
Before Width: | Height: | Size: 185 KiB After Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 132 KiB After Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 427 KiB After Width: | Height: | Size: 427 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
@@ -1,77 +1,77 @@
|
||||
# CharacterGLM-6B Transformers部署调用
|
||||
|
||||
## 环境准备
|
||||
|
||||
在autodl平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择PyTorch-->2.0.0-->3.8(ubuntu20.04)-->11.8
|
||||
|
||||

|
||||
|
||||
接下来打开刚刚租用服务器的JupyterLab,并且打开其中的终端开始环境配置、模型下载和运行demo。
|
||||
|
||||
pip换源和安装依赖包
|
||||
|
||||
```python
|
||||
#升级pip
|
||||
python -m pip install --upgrade pip
|
||||
#更换 pypi 源加速库的安装
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
pip install modelscope
|
||||
pip install transformers
|
||||
pip install sentencepiece
|
||||
```
|
||||
|
||||
## 模型下载
|
||||
|
||||
使用 modelscope 中的snapshot_download函数下载模型,第一个参数为模型名称,参数cache_dir为模型的下载路径。
|
||||
|
||||
在 /root/autodl-tmp 路径下新建 download.py 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 python /root/autodl-tmp/download.py执行下载,模型大小为 12 GB,下载模型大概需要 10~15 分钟
|
||||
|
||||
```python
|
||||
import torch
|
||||
from modelscope import snapshot_download, AutoModel, AutoTokenizer
|
||||
import os
|
||||
model_dir = snapshot_download('THUCoAI/CharacterGLM-6B', cache_dir='/root/autodl-tmp', revision='master')
|
||||
```
|
||||
|
||||
## 代码准备
|
||||
|
||||
```python
|
||||
from transformers import AutoTokenizer,AutoModelForCausalLM
|
||||
import torch
|
||||
# 使用模型下载到的本地路径以加载
|
||||
model_dir = '/root/autodl-tmp/THUCoAI/CharacterGLM-6B'
|
||||
# 分词器的加载,本地加载,trust_remote_code=True设置允许从网络上下载模型权重和相关的代码
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
|
||||
# 模型加载,本地加载,使用AutoModelForCausalLM类
|
||||
model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True)
|
||||
# 将模型移动到GPU上进行加速(如果有GPU的话)
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
model.to(device)
|
||||
# 使用模型的评估模式来产生对话
|
||||
model.eval()
|
||||
session_meta = {'user_info': '我是陆星辰,是一个男性,是一位知名导演,也是苏梦远的合作导演。我擅长拍摄音乐题材的电影。苏梦远对我的态度是尊敬的,并视我为良师益友。', 'bot_info': '苏梦远,本名苏远心,是一位当红的国内女歌手及演员。在参加选秀节目后,凭借独特的嗓音及出众的舞台魅力迅速成名,进入娱乐圈。她外表美丽动人,但真正的魅力在于她的才华和勤奋。苏梦远是音乐学院毕业的优秀生,善于创作,拥有多首热门原创歌曲。除了音乐方面的成就,她还热衷于慈善事业,积极参加公益活动,用实际行动传递正能量。在工作中,她对待工作非常敬业,拍戏时总是全身心投入角色,赢得了业内人士的赞誉和粉丝的喜爱。虽然在娱乐圈,但她始终保持低调、谦逊的态度,深得同行尊重。在表达时,苏梦远喜欢使用“我们”和“一起”,强调团队精神。', 'bot_name': '苏梦远', 'user_name': '陆星辰'}
|
||||
# 第一轮对话
|
||||
response, history = model.chat(tokenizer, session_meta,"你好呀,小苏", history=[])
|
||||
print(response)
|
||||
# 第二轮对话
|
||||
response, history = model.chat(tokenizer, session_meta,"最近对音乐有什么新的想法吗", history=history)
|
||||
print(response)
|
||||
# 第三轮对话
|
||||
response, history = model.chat(tokenizer,session_meta, "那我们商量一下下一部音乐电影的拍摄,好嘛?", history=history)
|
||||
print(response)
|
||||
```
|
||||
|
||||
## 部署
|
||||
|
||||
在终端输入以下命令运行trans.py,即实现CharacterGLM-6B的Transformers部署调用
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp
|
||||
python trans.py
|
||||
```
|
||||
|
||||
观察命令行中loading checkpoint表示模型正在加载,等待模型加载完成产生对话,如下图所示
|
||||
|
||||

|
||||
|
||||
# CharacterGLM-6B Transformers部署调用
|
||||
|
||||
## 环境准备
|
||||
|
||||
在autodl平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择PyTorch-->2.0.0-->3.8(ubuntu20.04)-->11.8
|
||||
|
||||

|
||||
|
||||
接下来打开刚刚租用服务器的JupyterLab,并且打开其中的终端开始环境配置、模型下载和运行demo。
|
||||
|
||||
pip换源和安装依赖包
|
||||
|
||||
```python
|
||||
#升级pip
|
||||
python -m pip install --upgrade pip
|
||||
#更换 pypi 源加速库的安装
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
pip install modelscope
|
||||
pip install transformers
|
||||
pip install sentencepiece
|
||||
```
|
||||
|
||||
## 模型下载
|
||||
|
||||
使用 modelscope 中的snapshot_download函数下载模型,第一个参数为模型名称,参数cache_dir为模型的下载路径。
|
||||
|
||||
在 /root/autodl-tmp 路径下新建 download.py 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 python /root/autodl-tmp/download.py执行下载,模型大小为 12 GB,下载模型大概需要 10~15 分钟
|
||||
|
||||
```python
|
||||
import torch
|
||||
from modelscope import snapshot_download, AutoModel, AutoTokenizer
|
||||
import os
|
||||
model_dir = snapshot_download('THUCoAI/CharacterGLM-6B', cache_dir='/root/autodl-tmp', revision='master')
|
||||
```
|
||||
|
||||
## 代码准备
|
||||
|
||||
```python
|
||||
from transformers import AutoTokenizer,AutoModelForCausalLM
|
||||
import torch
|
||||
# 使用模型下载到的本地路径以加载
|
||||
model_dir = '/root/autodl-tmp/THUCoAI/CharacterGLM-6B'
|
||||
# 分词器的加载,本地加载,trust_remote_code=True设置允许从网络上下载模型权重和相关的代码
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
|
||||
# 模型加载,本地加载,使用AutoModelForCausalLM类
|
||||
model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True)
|
||||
# 将模型移动到GPU上进行加速(如果有GPU的话)
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
model.to(device)
|
||||
# 使用模型的评估模式来产生对话
|
||||
model.eval()
|
||||
session_meta = {'user_info': '我是陆星辰,是一个男性,是一位知名导演,也是苏梦远的合作导演。我擅长拍摄音乐题材的电影。苏梦远对我的态度是尊敬的,并视我为良师益友。', 'bot_info': '苏梦远,本名苏远心,是一位当红的国内女歌手及演员。在参加选秀节目后,凭借独特的嗓音及出众的舞台魅力迅速成名,进入娱乐圈。她外表美丽动人,但真正的魅力在于她的才华和勤奋。苏梦远是音乐学院毕业的优秀生,善于创作,拥有多首热门原创歌曲。除了音乐方面的成就,她还热衷于慈善事业,积极参加公益活动,用实际行动传递正能量。在工作中,她对待工作非常敬业,拍戏时总是全身心投入角色,赢得了业内人士的赞誉和粉丝的喜爱。虽然在娱乐圈,但她始终保持低调、谦逊的态度,深得同行尊重。在表达时,苏梦远喜欢使用“我们”和“一起”,强调团队精神。', 'bot_name': '苏梦远', 'user_name': '陆星辰'}
|
||||
# 第一轮对话
|
||||
response, history = model.chat(tokenizer, session_meta,"你好呀,小苏", history=[])
|
||||
print(response)
|
||||
# 第二轮对话
|
||||
response, history = model.chat(tokenizer, session_meta,"最近对音乐有什么新的想法吗", history=history)
|
||||
print(response)
|
||||
# 第三轮对话
|
||||
response, history = model.chat(tokenizer,session_meta, "那我们商量一下下一部音乐电影的拍摄,好嘛?", history=history)
|
||||
print(response)
|
||||
```
|
||||
|
||||
## 部署
|
||||
|
||||
在终端输入以下命令运行trans.py,即实现CharacterGLM-6B的Transformers部署调用
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp
|
||||
python trans.py
|
||||
```
|
||||
|
||||
观察命令行中loading checkpoint表示模型正在加载,等待模型加载完成产生对话,如下图所示
|
||||
|
||||

|
||||
|
||||
@@ -1,183 +1,183 @@
|
||||
# CharacterGLM-6B FastApi部署调用
|
||||
|
||||
## 环境准备
|
||||
|
||||
在autodl平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择PyTorch-->2.0.0-->3.8(ubuntu20.04)-->11.8
|
||||
|
||||

|
||||
|
||||
|
||||
接下来打开刚刚租用服务器的JupyterLab,并且打开其中的终端开始环境配置、模型下载和运行demo。
|
||||
|
||||
pip换源和安装依赖包
|
||||
|
||||
```python
|
||||
# 升级pip
|
||||
python -m pip install --upgrade pip
|
||||
# 更换 pypi 源加速库的安装
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
pip install fastapi==0.104.1
|
||||
pip install uvicorn==0.24.0.post1
|
||||
pip install requests==2.25.1
|
||||
pip install modelscope==1.9.5
|
||||
pip install transformers==4.37.2
|
||||
pip install streamlit==1.24.0
|
||||
pip install sentencepiece==0.1.99
|
||||
pip install accelerate==0.24.1
|
||||
|
||||
```
|
||||
|
||||
## 模型下载
|
||||
|
||||
使用 modelscope 中的snapshot_download函数下载模型,第一个参数为模型名称,参数cache_dir为模型的下载路径。
|
||||
|
||||
在 /root/autodl-tmp 路径下新建 download.py 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 python /root/autodl-tmp/download.py执行下载,模型大小为 12 GB,下载模型大概需要 10~15 分钟
|
||||
|
||||
```python
|
||||
import torch
|
||||
from modelscope import snapshot_download, AutoModel, AutoTokenizer
|
||||
import os
|
||||
model_dir = snapshot_download('THUCoAI/CharacterGLM-6B', cache_dir='/root/autodl-tmp', revision='master')
|
||||
```
|
||||
|
||||
## 代码准备
|
||||
|
||||
在/root/autodl-tmp路径下新建api.py文件并在其中输入以下内容,粘贴代码后记得保存文件。下面的代码有很详细的注释,大家如有不理解的地方,欢迎提出issue。
|
||||
|
||||
```python
|
||||
from fastapi import FastAPI, Request
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
import uvicorn
|
||||
import json
|
||||
import datetime
|
||||
import torch
|
||||
|
||||
# 设置设备参数
|
||||
DEVICE = "cuda" # 使用CUDA
|
||||
DEVICE_ID = "0" # CUDA设备ID,如果未设置则为空
|
||||
CUDA_DEVICE = f"{DEVICE}:{DEVICE_ID}" if DEVICE_ID else DEVICE # 组合CUDA设备信息
|
||||
|
||||
# 清理GPU内存函数
|
||||
def torch_gc():
|
||||
if torch.cuda.is_available(): # 检查是否可用CUDA
|
||||
with torch.cuda.device(CUDA_DEVICE): # 指定CUDA设备
|
||||
torch.cuda.empty_cache() # 清空CUDA缓存
|
||||
torch.cuda.ipc_collect() # 收集CUDA内存碎片
|
||||
|
||||
# 创建FastAPI应用
|
||||
app = FastAPI()
|
||||
|
||||
# 处理POST请求的端点
|
||||
@app.post("/")
|
||||
async def create_item(request: Request):
|
||||
global model, tokenizer # 声明全局变量以便在函数内部使用模型和分词器
|
||||
json_post_raw = await request.json() # 获取POST请求的JSON数据
|
||||
json_post = json.dumps(json_post_raw) # 将JSON数据转换为字符串
|
||||
json_post_list = json.loads(json_post) # 将字符串转换为Python对象
|
||||
prompt = json_post_list.get('prompt') # 获取请求中的提示
|
||||
history = json_post_list.get('history') # 获取请求中的历史记录
|
||||
max_length = json_post_list.get('max_length') # 获取请求中的最大长度
|
||||
top_p = json_post_list.get('top_p') # 获取请求中的top_p参数
|
||||
temperature = json_post_list.get('temperature') # 获取请求中的温度参数
|
||||
session_meta = {'user_info': '我是陆星辰,是一个男性,是一位知名导演,也是苏梦远的合作导演。我擅长拍摄音乐题材的电影。苏梦远对我的态度是尊敬的,并视我为良师益友。', 'bot_info': '苏梦远,本名苏远心,是一位当红的国内女歌手及演员。在参加选秀节目后,凭借独特的嗓音及出众的舞台魅力迅速成名,进入娱乐圈。她外表美丽动人,但真正的魅力在于她的才华和勤奋。苏梦远是音乐学院毕业的优秀生,善于创作,拥有多首热门原创歌曲。除了音乐方面的成就,她还热衷于慈善事业,积极参加公益活动,用实际行动传递正能量。在工作中,她对待工作非常敬业,拍戏时总是全身心投入角色,赢得了业内人士的赞誉和粉丝的喜爱。虽然在娱乐圈,但她始终保持低调、谦逊的态度,深得同行尊重。在表达时,苏梦远喜欢使用“我们”和“一起”,强调团队精神。', 'bot_name': '苏梦远', 'user_name': '陆星辰'}
|
||||
# 调用模型进行对话生成
|
||||
response, history = model.chat(
|
||||
tokenizer,
|
||||
session_meta,
|
||||
prompt,
|
||||
history=history,
|
||||
max_length=max_length if max_length else 2048, # 如果未提供最大长度,默认使用2048
|
||||
top_p=top_p if top_p else 0.7, # 如果未提供top_p参数,默认使用0.7
|
||||
temperature=temperature if temperature else 0.95 # 如果未提供温度参数,默认使用0.95
|
||||
)
|
||||
now = datetime.datetime.now() # 获取当前时间
|
||||
time = now.strftime("%Y-%m-%d %H:%M:%S") # 格式化时间为字符串
|
||||
# 构建响应JSON
|
||||
answer = {
|
||||
"response": response,
|
||||
"history": history,
|
||||
"status": 200,
|
||||
"time": time
|
||||
}
|
||||
# 构建日志信息
|
||||
log = "[" + time + "] " + '", prompt:"' + prompt + '", response:"' + repr(response) + '"'
|
||||
print(log) # 打印日志
|
||||
torch_gc() # 执行GPU内存清理
|
||||
return answer # 返回响应
|
||||
|
||||
# 主函数入口
|
||||
if __name__ == '__main__':
|
||||
# 加载预训练的分词器和模型
|
||||
tokenizer = AutoTokenizer.from_pretrained("/root/autodl-tmp/THUCoAI/CharacterGLM-6B", trust_remote_code=True)
|
||||
model = AutoModelForCausalLM.from_pretrained("/root/autodl-tmp/THUCoAI/CharacterGLM-6B", trust_remote_code=True).to(torch.bfloat16).cuda()
|
||||
model.eval() # 设置模型为评估模式
|
||||
# 启动FastAPI应用
|
||||
# 用6006端口可以将autodl的端口映射到本地,从而在本地使用api
|
||||
uvicorn.run(app, host='0.0.0.0', port=6006, workers=1) # 在指定端口和主机上启动应用
|
||||
```
|
||||
|
||||
## Api部署调用
|
||||
|
||||
在终端输入以下命令启动api服务
|
||||
|
||||
```python
|
||||
|
||||
cd /root/autodl-tmp
|
||||
python api.py
|
||||
|
||||
```
|
||||
|
||||
默认部署在 6006 端口,通过 POST 方法进行调用,可以使用curl调用,如下所示:
|
||||
|
||||
```python
|
||||
|
||||
curl -X POST "http://127.0.0.1:6006" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"prompt": "你好", "history": []}'
|
||||
|
||||
```
|
||||
|
||||
调用示例结果如下图所示
|
||||
|
||||

|
||||
|
||||
|
||||
也可以使用python中的requests库进行调用,新建api-requests.py文件,写入如下代码:
|
||||
|
||||
```python
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
def get_completion(prompt):
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
data = {"prompt": prompt, "history": []}
|
||||
response = requests.post(url='http://127.0.0.1:6006', headers=headers, data=json.dumps(data))
|
||||
return response.json()['response']
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(get_completion('你是谁呀?'))
|
||||
|
||||
```
|
||||
|
||||
新开一个终端,输入如下指令
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp
|
||||
python api-requests.py
|
||||
|
||||
```
|
||||
|
||||
得到的返回值及结果展示如下
|
||||
|
||||
```python
|
||||
{
|
||||
'response': '嗨,你好,我叫苏梦远。(微笑着向对方走去)',
|
||||
'history': [['你是谁呀?', '嗨,你好,我叫苏梦远。(微笑着向对方走去)']],
|
||||
'status': 200,
|
||||
'time': '2024-03-05 22:44:35'
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
# CharacterGLM-6B FastApi部署调用
|
||||
|
||||
## 环境准备
|
||||
|
||||
在autodl平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择PyTorch-->2.0.0-->3.8(ubuntu20.04)-->11.8
|
||||
|
||||

|
||||
|
||||
|
||||
接下来打开刚刚租用服务器的JupyterLab,并且打开其中的终端开始环境配置、模型下载和运行demo。
|
||||
|
||||
pip换源和安装依赖包
|
||||
|
||||
```python
|
||||
# 升级pip
|
||||
python -m pip install --upgrade pip
|
||||
# 更换 pypi 源加速库的安装
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
pip install fastapi==0.104.1
|
||||
pip install uvicorn==0.24.0.post1
|
||||
pip install requests==2.25.1
|
||||
pip install modelscope==1.9.5
|
||||
pip install transformers==4.37.2
|
||||
pip install streamlit==1.24.0
|
||||
pip install sentencepiece==0.1.99
|
||||
pip install accelerate==0.24.1
|
||||
|
||||
```
|
||||
|
||||
## 模型下载
|
||||
|
||||
使用 modelscope 中的snapshot_download函数下载模型,第一个参数为模型名称,参数cache_dir为模型的下载路径。
|
||||
|
||||
在 /root/autodl-tmp 路径下新建 download.py 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 python /root/autodl-tmp/download.py执行下载,模型大小为 12 GB,下载模型大概需要 10~15 分钟
|
||||
|
||||
```python
|
||||
import torch
|
||||
from modelscope import snapshot_download, AutoModel, AutoTokenizer
|
||||
import os
|
||||
model_dir = snapshot_download('THUCoAI/CharacterGLM-6B', cache_dir='/root/autodl-tmp', revision='master')
|
||||
```
|
||||
|
||||
## 代码准备
|
||||
|
||||
在/root/autodl-tmp路径下新建api.py文件并在其中输入以下内容,粘贴代码后记得保存文件。下面的代码有很详细的注释,大家如有不理解的地方,欢迎提出issue。
|
||||
|
||||
```python
|
||||
from fastapi import FastAPI, Request
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
import uvicorn
|
||||
import json
|
||||
import datetime
|
||||
import torch
|
||||
|
||||
# 设置设备参数
|
||||
DEVICE = "cuda" # 使用CUDA
|
||||
DEVICE_ID = "0" # CUDA设备ID,如果未设置则为空
|
||||
CUDA_DEVICE = f"{DEVICE}:{DEVICE_ID}" if DEVICE_ID else DEVICE # 组合CUDA设备信息
|
||||
|
||||
# 清理GPU内存函数
|
||||
def torch_gc():
|
||||
if torch.cuda.is_available(): # 检查是否可用CUDA
|
||||
with torch.cuda.device(CUDA_DEVICE): # 指定CUDA设备
|
||||
torch.cuda.empty_cache() # 清空CUDA缓存
|
||||
torch.cuda.ipc_collect() # 收集CUDA内存碎片
|
||||
|
||||
# 创建FastAPI应用
|
||||
app = FastAPI()
|
||||
|
||||
# 处理POST请求的端点
|
||||
@app.post("/")
|
||||
async def create_item(request: Request):
|
||||
global model, tokenizer # 声明全局变量以便在函数内部使用模型和分词器
|
||||
json_post_raw = await request.json() # 获取POST请求的JSON数据
|
||||
json_post = json.dumps(json_post_raw) # 将JSON数据转换为字符串
|
||||
json_post_list = json.loads(json_post) # 将字符串转换为Python对象
|
||||
prompt = json_post_list.get('prompt') # 获取请求中的提示
|
||||
history = json_post_list.get('history') # 获取请求中的历史记录
|
||||
max_length = json_post_list.get('max_length') # 获取请求中的最大长度
|
||||
top_p = json_post_list.get('top_p') # 获取请求中的top_p参数
|
||||
temperature = json_post_list.get('temperature') # 获取请求中的温度参数
|
||||
session_meta = {'user_info': '我是陆星辰,是一个男性,是一位知名导演,也是苏梦远的合作导演。我擅长拍摄音乐题材的电影。苏梦远对我的态度是尊敬的,并视我为良师益友。', 'bot_info': '苏梦远,本名苏远心,是一位当红的国内女歌手及演员。在参加选秀节目后,凭借独特的嗓音及出众的舞台魅力迅速成名,进入娱乐圈。她外表美丽动人,但真正的魅力在于她的才华和勤奋。苏梦远是音乐学院毕业的优秀生,善于创作,拥有多首热门原创歌曲。除了音乐方面的成就,她还热衷于慈善事业,积极参加公益活动,用实际行动传递正能量。在工作中,她对待工作非常敬业,拍戏时总是全身心投入角色,赢得了业内人士的赞誉和粉丝的喜爱。虽然在娱乐圈,但她始终保持低调、谦逊的态度,深得同行尊重。在表达时,苏梦远喜欢使用“我们”和“一起”,强调团队精神。', 'bot_name': '苏梦远', 'user_name': '陆星辰'}
|
||||
# 调用模型进行对话生成
|
||||
response, history = model.chat(
|
||||
tokenizer,
|
||||
session_meta,
|
||||
prompt,
|
||||
history=history,
|
||||
max_length=max_length if max_length else 2048, # 如果未提供最大长度,默认使用2048
|
||||
top_p=top_p if top_p else 0.7, # 如果未提供top_p参数,默认使用0.7
|
||||
temperature=temperature if temperature else 0.95 # 如果未提供温度参数,默认使用0.95
|
||||
)
|
||||
now = datetime.datetime.now() # 获取当前时间
|
||||
time = now.strftime("%Y-%m-%d %H:%M:%S") # 格式化时间为字符串
|
||||
# 构建响应JSON
|
||||
answer = {
|
||||
"response": response,
|
||||
"history": history,
|
||||
"status": 200,
|
||||
"time": time
|
||||
}
|
||||
# 构建日志信息
|
||||
log = "[" + time + "] " + '", prompt:"' + prompt + '", response:"' + repr(response) + '"'
|
||||
print(log) # 打印日志
|
||||
torch_gc() # 执行GPU内存清理
|
||||
return answer # 返回响应
|
||||
|
||||
# 主函数入口
|
||||
if __name__ == '__main__':
|
||||
# 加载预训练的分词器和模型
|
||||
tokenizer = AutoTokenizer.from_pretrained("/root/autodl-tmp/THUCoAI/CharacterGLM-6B", trust_remote_code=True)
|
||||
model = AutoModelForCausalLM.from_pretrained("/root/autodl-tmp/THUCoAI/CharacterGLM-6B", trust_remote_code=True).to(torch.bfloat16).cuda()
|
||||
model.eval() # 设置模型为评估模式
|
||||
# 启动FastAPI应用
|
||||
# 用6006端口可以将autodl的端口映射到本地,从而在本地使用api
|
||||
uvicorn.run(app, host='0.0.0.0', port=6006, workers=1) # 在指定端口和主机上启动应用
|
||||
```
|
||||
|
||||
## Api部署调用
|
||||
|
||||
在终端输入以下命令启动api服务
|
||||
|
||||
```python
|
||||
|
||||
cd /root/autodl-tmp
|
||||
python api.py
|
||||
|
||||
```
|
||||
|
||||
默认部署在 6006 端口,通过 POST 方法进行调用,可以使用curl调用,如下所示:
|
||||
|
||||
```python
|
||||
|
||||
curl -X POST "http://127.0.0.1:6006" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"prompt": "你好", "history": []}'
|
||||
|
||||
```
|
||||
|
||||
调用示例结果如下图所示
|
||||
|
||||

|
||||
|
||||
|
||||
也可以使用python中的requests库进行调用,新建api-requests.py文件,写入如下代码:
|
||||
|
||||
```python
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
def get_completion(prompt):
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
data = {"prompt": prompt, "history": []}
|
||||
response = requests.post(url='http://127.0.0.1:6006', headers=headers, data=json.dumps(data))
|
||||
return response.json()['response']
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(get_completion('你是谁呀?'))
|
||||
|
||||
```
|
||||
|
||||
新开一个终端,输入如下指令
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp
|
||||
python api-requests.py
|
||||
|
||||
```
|
||||
|
||||
得到的返回值及结果展示如下
|
||||
|
||||
```python
|
||||
{
|
||||
'response': '嗨,你好,我叫苏梦远。(微笑着向对方走去)',
|
||||
'history': [['你是谁呀?', '嗨,你好,我叫苏梦远。(微笑着向对方走去)']],
|
||||
'status': 200,
|
||||
'time': '2024-03-05 22:44:35'
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
@@ -1,96 +1,96 @@
|
||||
# CharacterGLM-6B-chat
|
||||
|
||||
## 环境准备
|
||||
|
||||
在autodl平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择PyTorch-->2.0.0-->3.8(ubuntu20.04)-->11.8
|
||||
|
||||

|
||||
|
||||
|
||||
接下来打开刚刚租用服务器的JupyterLab,并且打开其中的终端开始环境配置、模型下载和运行demo。
|
||||
|
||||
pip换源和安装依赖包
|
||||
|
||||
```python
|
||||
# 升级pip
|
||||
python -m pip install --upgrade pip
|
||||
# 更换 pypi 源加速库的安装
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
pip install modelscope
|
||||
pip install transformers
|
||||
```
|
||||
|
||||
## 模型下载
|
||||
|
||||
使用 modelscope 中的snapshot_download函数下载模型,第一个参数为模型名称,参数cache_dir为模型的下载路径。
|
||||
|
||||
在 /root/autodl-tmp 路径下新建 download.py 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 python /root/autodl-tmp/download.py执行下载,模型大小为 12 GB,下载模型大概需要 10~15 分钟
|
||||
|
||||
```python
|
||||
import torch
|
||||
from modelscope import snapshot_download, AutoModel, AutoTokenizer
|
||||
import os
|
||||
model_dir = snapshot_download('THUCoAI/CharacterGLM-6B', cache_dir='/root/autodl-tmp', revision='master')
|
||||
```
|
||||
|
||||
## 代码准备
|
||||
|
||||
首先clone代码,打开autodl平台自带的学术镜像加速。学术镜像加速详细使用请看:
|
||||
https://www.autodl.com/docs/network_turbo/
|
||||
|
||||
```python
|
||||
source /etc/network_turbo
|
||||
```
|
||||
|
||||
然后切换路径, clone代码.
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp
|
||||
git clone https://github.com/thu-coai/CharacterGLM-6B
|
||||
```
|
||||
|
||||
## demo运行
|
||||
|
||||
修改代码路径,将 /root/autodl-tmp/CharacterGLM-6B/basic_demo/web_demo_streamlit.py中第20行的模型更换为本地的/root/autodl-tmp/THUCoAI/CharacterGLM-6B
|
||||
|
||||

|
||||
|
||||
|
||||
修改requirements.txt文件,将其中的torch删掉,环境中已经有了torch,不需要再安装。然后执行下面的命令:
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp/CharacterGLM-6B
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
在终端运行以下命令即可启动推理服务,尽量cd到basic_demo文件夹下,防止找不到character.json文件
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp/CharacterGLM-6B/basic_demo
|
||||
streamlit run ./web_demo2.py --server.address 127.0.0.1 --server.port 6006
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
在将 autodl 的端口映射到本地的 http://localhost:6006 后,即可看到demo界面。具体映射步骤参考文档General-Setting文件夹下/02-AutoDL开放端口.md文档。
|
||||
|
||||
在浏览器打开 http://localhost:6006 界面,模型加载,即可使用,如下图所示。
|
||||
|
||||

|
||||
|
||||
|
||||
## 命令行运行
|
||||
|
||||
修改代码路径,将 /root/autodl-tmp/CharacterGLM-6B/basic_demo/cli_demo.py中的模型路径更换为本地的/root/autodl-tmp/THUCoAI/CharacterGLM-6B
|
||||
|
||||
在终端运行以下命令即可启动推理服务
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp/CharacterGLM-6B/basic_demo
|
||||
python ./cli_demo.py
|
||||
```
|
||||
|
||||

|
||||
|
||||
# CharacterGLM-6B-chat
|
||||
|
||||
## 环境准备
|
||||
|
||||
在autodl平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择PyTorch-->2.0.0-->3.8(ubuntu20.04)-->11.8
|
||||
|
||||

|
||||
|
||||
|
||||
接下来打开刚刚租用服务器的JupyterLab,并且打开其中的终端开始环境配置、模型下载和运行demo。
|
||||
|
||||
pip换源和安装依赖包
|
||||
|
||||
```python
|
||||
# 升级pip
|
||||
python -m pip install --upgrade pip
|
||||
# 更换 pypi 源加速库的安装
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
pip install modelscope
|
||||
pip install transformers
|
||||
```
|
||||
|
||||
## 模型下载
|
||||
|
||||
使用 modelscope 中的snapshot_download函数下载模型,第一个参数为模型名称,参数cache_dir为模型的下载路径。
|
||||
|
||||
在 /root/autodl-tmp 路径下新建 download.py 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 python /root/autodl-tmp/download.py执行下载,模型大小为 12 GB,下载模型大概需要 10~15 分钟
|
||||
|
||||
```python
|
||||
import torch
|
||||
from modelscope import snapshot_download, AutoModel, AutoTokenizer
|
||||
import os
|
||||
model_dir = snapshot_download('THUCoAI/CharacterGLM-6B', cache_dir='/root/autodl-tmp', revision='master')
|
||||
```
|
||||
|
||||
## 代码准备
|
||||
|
||||
首先clone代码,打开autodl平台自带的学术镜像加速。学术镜像加速详细使用请看:
|
||||
https://www.autodl.com/docs/network_turbo/
|
||||
|
||||
```python
|
||||
source /etc/network_turbo
|
||||
```
|
||||
|
||||
然后切换路径, clone代码.
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp
|
||||
git clone https://github.com/thu-coai/CharacterGLM-6B
|
||||
```
|
||||
|
||||
## demo运行
|
||||
|
||||
修改代码路径,将 /root/autodl-tmp/CharacterGLM-6B/basic_demo/web_demo_streamlit.py中第20行的模型更换为本地的/root/autodl-tmp/THUCoAI/CharacterGLM-6B
|
||||
|
||||

|
||||
|
||||
|
||||
修改requirements.txt文件,将其中的torch删掉,环境中已经有了torch,不需要再安装。然后执行下面的命令:
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp/CharacterGLM-6B
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
在终端运行以下命令即可启动推理服务,尽量cd到basic_demo文件夹下,防止找不到character.json文件
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp/CharacterGLM-6B/basic_demo
|
||||
streamlit run ./web_demo2.py --server.address 127.0.0.1 --server.port 6006
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
在将 autodl 的端口映射到本地的 http://localhost:6006 后,即可看到demo界面。具体映射步骤参考文档General-Setting文件夹下/02-AutoDL开放端口.md文档。
|
||||
|
||||
在浏览器打开 http://localhost:6006 界面,模型加载,即可使用,如下图所示。
|
||||
|
||||

|
||||
|
||||
|
||||
## 命令行运行
|
||||
|
||||
修改代码路径,将 /root/autodl-tmp/CharacterGLM-6B/basic_demo/cli_demo.py中的模型路径更换为本地的/root/autodl-tmp/THUCoAI/CharacterGLM-6B
|
||||
|
||||
在终端运行以下命令即可启动推理服务
|
||||
|
||||
```python
|
||||
cd /root/autodl-tmp/CharacterGLM-6B/basic_demo
|
||||
python ./cli_demo.py
|
||||
```
|
||||
|
||||

|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
# 04-CharacterGLM-6B-Chat Lora微调
|
||||
|
||||
## 概述
|
||||
|
||||
本文简要介绍如何基于transformers、peft等框架,对CharacterGLM-6B-chat模型进行Lora微调。Lora原理可参考博客:[知乎|深入浅出Lora](https://zhuanlan.zhihu.com/p/650197598)
|
||||
本文代码未使用分布式框架,微调 ChatGLM3-6B-Chat 模型至少需要 21G 及以上的显存,且需要修改脚本文件中的模型路径和数据集路径。
|
||||
|
||||
## 环境配置
|
||||
|
||||
在完成基本环境配置和本地模型部署的情况下,还需要安装一些第三方库,可以使用如下命令:
|
||||
|
||||
```python
|
||||
pip install transformers==4.37.2
|
||||
pip install peft==0.4.0.dev0
|
||||
pip install datasets==2.10.1
|
||||
pip install accelerate==0.21.0
|
||||
|
||||
```
|
||||
|
||||
在本节内容中,将微调数据集放置在根目录[/dataset](https://github.com/datawhalechina/self-llm/blob/master/dataset/huanhuan.json)。
|
||||
|
||||
## 指令集构建
|
||||
|
||||
LLM微调一般指指令微调过程。所谓指令微调,是说我们使用的微调数据形如:
|
||||
|
||||
```python
|
||||
{
|
||||
"instruction":"回答用户以下问题,直接给出结果。"
|
||||
"input":"中国第一个诺贝尔奖得主是谁?"
|
||||
"output":"莫言"
|
||||
}
|
||||
```
|
||||
|
||||
其中instruction是用户指令,告知模型需要完成的任务;input是用户输入,是完成用户指令所必需的输入内容;output是模型应该给出的输出。
|
||||
|
||||
即我们的核心训练目标是让模型具有理解并遵循用户指令的能力。因此,在指令集构建时,我们应针对我们的目标任务,针对性构建任务指令集。在本文我们使用由笔者合作开源的[Chat-甄嬛项目](https://github.com/KMnO4-zx/huanhuan-chat)作为示例,我们的目标是构建一个能够模拟甄嬛对话风格的个性化LLM,因此我们构建的指令形如:
|
||||
|
||||
```python
|
||||
{
|
||||
"instruction": "",
|
||||
"input":"你是谁?",
|
||||
"output":"家父是大理寺少卿甄远道。"
|
||||
}
|
||||
```
|
||||
|
||||
我们构造的全部指令数据集在根目录下。
|
||||
|
||||
## QA和Instruction的区别和联系
|
||||
|
||||
QA是指一问一答的形式,通常是用户提问,模型给出回答。而instruction则源自于Prompt Engineering,将问题拆分成两个部分:Instruction用于描述任务,Input用于描述待处理的对象。
|
||||
|
||||
问答(QA)格式的训练数据通常用于训练模型执行具体任务。例如,对于问题“请解释INFJ和ENTP两种MBTI性格之间的区别”
|
||||
|
||||
*问答(QA)格式:
|
||||
|
||||
```python
|
||||
指令(instruction):
|
||||
输入(input):INFJ和ENTP这两种MBTI性格之间的区别是什么?
|
||||
```
|
||||
|
||||
*指令(Instruction)格式:
|
||||
|
||||
```python
|
||||
指令(Instruction):请解释下面两种MBTI性格的区别
|
||||
输入(input):INFJ和ENTP
|
||||
```
|
||||
|
||||
## 数据格式化
|
||||
|
||||
Lora训练的数据是需要经过格式化、编码之后再输入给模型进行训练的,我们一般需要将输入文本编码为input_ids,将输出文本编码为labels,编码之后的结果都是多维向量。我们首先定义一个与处理函数,这个函数用于对每一个样本,编码其输入,输出文本并返回一个编码后的字典:
|
||||
|
||||
```python
|
||||
def process_func(example):
|
||||
MAX_LENGTH = 512
|
||||
input_ids, labels = [], []
|
||||
prompt = tokenizer.encode("用户:\n"+"现在你要扮演皇帝身边的女人--甄嬛。", add_special_tokens=False)
|
||||
instruction_ = tokenizer.encode("\n".join([example["instruction"], example["input"]]).strip(), add_special_tokens=False,max_length=512)
|
||||
instruction = tokenizer.encode(prompt + instruction_)
|
||||
response = tokenizer.encode("CharacterGLM-6B:\n:" + example["output"], add_special_tokens=False)
|
||||
input_ids = instruction + response + [tokenizer.eos_token_id]
|
||||
labels = [tokenizer.pad_token_id] * len(instruction) + response + [tokenizer.eos_token_id]
|
||||
pad_len = MAX_LENGTH - len(input_ids)
|
||||
# print()
|
||||
input_ids += [tokenizer.pad_token_id] * pad_len
|
||||
labels += [tokenizer.pad_token_id] * pad_len
|
||||
labels = [(l if l != tokenizer.pad_token_id else -100) for l in labels]
|
||||
|
||||
return {
|
||||
"input_ids": input_ids,
|
||||
"labels": labels
|
||||
}
|
||||
```
|
||||
|
||||
经过格式化的数据,也就是送入模型的每一条数据,都是一个字典,包含了input_ids、labels两个键值对,其中input_ids是输入文本的编码,labels是输出文本的编码。
|
||||
|
||||
## 加载tokenizer和半精度模型
|
||||
|
||||
模型以版精度形式加载,如果显卡比较新,可以用torch.bfloat形式加载,对于自定义的模型一定要指定trust_remote_code参数为True
|
||||
|
||||
```python
|
||||
tokenizer=AutoTokenizer.from_pretrained('/root/autodl-tmp/THUCoAI/CharacterGLM-6B',use_fast=False,trust_remote_code=True)
|
||||
|
||||
model=AutoModelForCausalLM.from_pretrained('/root/autodl-tmp/THUCoAI/CharacterGLM-6B',trust_remote_code=True,torch_dtype=torch.half,device_map="auto")
|
||||
```
|
||||
|
||||
## 定义LoraConfig
|
||||
|
||||
LoraConfig这个类中可以设置很多参数,部分参数展示如下:
|
||||
task_type:模型类型
|
||||
target——modules:需要训练的模型层的名字,主要就是attention部分的层,不同的模型对应的层的名字不同,可以传入数组,也可以字符串,也可以正则表达式。
|
||||
r:lora的秩
|
||||
lora_alpha:Lora alpha
|
||||
modules_to_save:指定的是除了拆成lora的模块,其它的模块可以完整的指定训练
|
||||
|
||||
Lora的所方式lora_alpha/r,在这个LoraConfig中缩放就是4倍。这个缩放的本质并没有改变Lora的参数量大小,本质在于将里面的参数数值做广播乘法,进行线性的缩放。
|
||||
|
||||
```python
|
||||
config=LoraConfig(
|
||||
task_type=TaskType.CAUSAL_LM,
|
||||
target_modules=["query_key_value"],
|
||||
inference_mode=False,
|
||||
r=8,
|
||||
lora_alpha=32,
|
||||
lora_dropout=0.1
|
||||
)
|
||||
```
|
||||
|
||||
## 自定义TraininArguments参数
|
||||
|
||||
TrainingArguments这个类的源码也介绍了每个参数的具体作用,常用的参数如下:
|
||||
output_dir:模型的输出路径
|
||||
per_device_train_batch_size:batch_size
|
||||
gradient_accumulation_steps:梯度累加,如果显存比较小,可以把batch_size设置小一点,梯度累积增大一点
|
||||
logging_steps:多少步,输出一次log
|
||||
num_train_epochs:顾名思义epoch
|
||||
gradient_chechpointing:梯度检查,这个一旦开启,模型就必须执行
|
||||
model.enable_input_require_grads()
|
||||
|
||||
```python
|
||||
data_collator=DataCollatorForSeq2Seq(
|
||||
tokenizer,
|
||||
model=model,
|
||||
label_pad_token_id=-100,
|
||||
pad_to_multiple_of=None,
|
||||
padding=False
|
||||
)
|
||||
args=TrainingArguments(
|
||||
output_dir="./output/CharacterGLM",
|
||||
per_device_train_batch_size=4,
|
||||
gradient_accumulation_steps=2,
|
||||
logging_steps=10,
|
||||
num_train_epochs=3,
|
||||
gradient_checkpointing=True,
|
||||
save_steps=100,
|
||||
learning_rate=1e-4,
|
||||
)
|
||||
```
|
||||
|
||||
## 使用Trainer训练
|
||||
|
||||
把model放进去,把上面设置的参数放进去,数据集放进去,开始训练
|
||||
|
||||
```python
|
||||
trainer=Trainer(
|
||||
model=model,
|
||||
args=args,
|
||||
train_dataset=tokenized_id,
|
||||
data_collator=data_collator,
|
||||
)
|
||||
trainer.train()
|
||||
```
|
||||
|
||||
## 模型推理
|
||||
|
||||
```python
|
||||
model = model.cuda()
|
||||
ipt = tokenizer("用户:{}\n{}".format("现在你要扮演皇帝身边的女人--甄嬛。你是谁?", "").strip() + "characterGLM-6B:\n", return_tensors="pt").to(model.device)
|
||||
tokenizer.decode(model.generate(**ipt, max_length=128, do_sample=True)[0], skip_special_tokens=True)
|
||||
```
|
||||
|
||||
## 从新加载
|
||||
|
||||
通过PEFT所微调的模型,都可以使用下面的方法进行重新加载,并推理:
|
||||
|
||||
加载源model与tokenizer;
|
||||
使用PeftModel合并源model与PEFT微调后的参数
|
||||
|
||||
```python
|
||||
from peft import Peftmodel
|
||||
model=AutoModelForCausalLM.from_pretrained("/root/autodl-tmp/THUCoAI/CharacterGLM-6B",trust_remote_code=True,low_cpu_mem_usage=True)
|
||||
tokenizer=AutoTokenizer.from_pretrained("root/autodl-tmp/THUCoAI/CharacterGLM-6B",use_fast=False,trust_remote_code=True)
|
||||
p_model=PeftModel.from_pretrained(model,model_id="./output/CharatcerGLM/checkpoint-1000/")
|
||||
ipt = tokenizer("用户:{}\n{}".format("现在你要扮演皇帝身边的女人--甄嬛。你是谁?", "").strip() + "characterGLM-6B:\n", return_tensors="pt").to(model.device)
|
||||
tokenizer.decode(p_model.generate(**ipt,max_length=128,do_sample=True)[0],skip_special_tokens=True)
|
||||
```
|
||||
# 04-CharacterGLM-6B-Chat Lora微调
|
||||
|
||||
## 概述
|
||||
|
||||
本文简要介绍如何基于transformers、peft等框架,对CharacterGLM-6B-chat模型进行Lora微调。Lora原理可参考博客:[知乎|深入浅出Lora](https://zhuanlan.zhihu.com/p/650197598)
|
||||
本文代码未使用分布式框架,微调 ChatGLM3-6B-Chat 模型至少需要 21G 及以上的显存,且需要修改脚本文件中的模型路径和数据集路径。
|
||||
|
||||
## 环境配置
|
||||
|
||||
在完成基本环境配置和本地模型部署的情况下,还需要安装一些第三方库,可以使用如下命令:
|
||||
|
||||
```python
|
||||
pip install transformers==4.37.2
|
||||
pip install peft==0.4.0.dev0
|
||||
pip install datasets==2.10.1
|
||||
pip install accelerate==0.21.0
|
||||
|
||||
```
|
||||
|
||||
在本节内容中,将微调数据集放置在根目录[/dataset](https://github.com/datawhalechina/self-llm/blob/master/dataset/huanhuan.json)。
|
||||
|
||||
## 指令集构建
|
||||
|
||||
LLM微调一般指指令微调过程。所谓指令微调,是说我们使用的微调数据形如:
|
||||
|
||||
```python
|
||||
{
|
||||
"instruction":"回答用户以下问题,直接给出结果。"
|
||||
"input":"中国第一个诺贝尔奖得主是谁?"
|
||||
"output":"莫言"
|
||||
}
|
||||
```
|
||||
|
||||
其中instruction是用户指令,告知模型需要完成的任务;input是用户输入,是完成用户指令所必需的输入内容;output是模型应该给出的输出。
|
||||
|
||||
即我们的核心训练目标是让模型具有理解并遵循用户指令的能力。因此,在指令集构建时,我们应针对我们的目标任务,针对性构建任务指令集。在本文我们使用由笔者合作开源的[Chat-甄嬛项目](https://github.com/KMnO4-zx/huanhuan-chat)作为示例,我们的目标是构建一个能够模拟甄嬛对话风格的个性化LLM,因此我们构建的指令形如:
|
||||
|
||||
```python
|
||||
{
|
||||
"instruction": "",
|
||||
"input":"你是谁?",
|
||||
"output":"家父是大理寺少卿甄远道。"
|
||||
}
|
||||
```
|
||||
|
||||
我们构造的全部指令数据集在根目录下。
|
||||
|
||||
## QA和Instruction的区别和联系
|
||||
|
||||
QA是指一问一答的形式,通常是用户提问,模型给出回答。而instruction则源自于Prompt Engineering,将问题拆分成两个部分:Instruction用于描述任务,Input用于描述待处理的对象。
|
||||
|
||||
问答(QA)格式的训练数据通常用于训练模型执行具体任务。例如,对于问题“请解释INFJ和ENTP两种MBTI性格之间的区别”
|
||||
|
||||
*问答(QA)格式:
|
||||
|
||||
```python
|
||||
指令(instruction):
|
||||
输入(input):INFJ和ENTP这两种MBTI性格之间的区别是什么?
|
||||
```
|
||||
|
||||
*指令(Instruction)格式:
|
||||
|
||||
```python
|
||||
指令(Instruction):请解释下面两种MBTI性格的区别
|
||||
输入(input):INFJ和ENTP
|
||||
```
|
||||
|
||||
## 数据格式化
|
||||
|
||||
Lora训练的数据是需要经过格式化、编码之后再输入给模型进行训练的,我们一般需要将输入文本编码为input_ids,将输出文本编码为labels,编码之后的结果都是多维向量。我们首先定义一个与处理函数,这个函数用于对每一个样本,编码其输入,输出文本并返回一个编码后的字典:
|
||||
|
||||
```python
|
||||
def process_func(example):
|
||||
MAX_LENGTH = 512
|
||||
input_ids, labels = [], []
|
||||
prompt = tokenizer.encode("用户:\n"+"现在你要扮演皇帝身边的女人--甄嬛。", add_special_tokens=False)
|
||||
instruction_ = tokenizer.encode("\n".join([example["instruction"], example["input"]]).strip(), add_special_tokens=False,max_length=512)
|
||||
instruction = tokenizer.encode(prompt + instruction_)
|
||||
response = tokenizer.encode("CharacterGLM-6B:\n:" + example["output"], add_special_tokens=False)
|
||||
input_ids = instruction + response + [tokenizer.eos_token_id]
|
||||
labels = [tokenizer.pad_token_id] * len(instruction) + response + [tokenizer.eos_token_id]
|
||||
pad_len = MAX_LENGTH - len(input_ids)
|
||||
# print()
|
||||
input_ids += [tokenizer.pad_token_id] * pad_len
|
||||
labels += [tokenizer.pad_token_id] * pad_len
|
||||
labels = [(l if l != tokenizer.pad_token_id else -100) for l in labels]
|
||||
|
||||
return {
|
||||
"input_ids": input_ids,
|
||||
"labels": labels
|
||||
}
|
||||
```
|
||||
|
||||
经过格式化的数据,也就是送入模型的每一条数据,都是一个字典,包含了input_ids、labels两个键值对,其中input_ids是输入文本的编码,labels是输出文本的编码。
|
||||
|
||||
## 加载tokenizer和半精度模型
|
||||
|
||||
模型以版精度形式加载,如果显卡比较新,可以用torch.bfloat形式加载,对于自定义的模型一定要指定trust_remote_code参数为True
|
||||
|
||||
```python
|
||||
tokenizer=AutoTokenizer.from_pretrained('/root/autodl-tmp/THUCoAI/CharacterGLM-6B',use_fast=False,trust_remote_code=True)
|
||||
|
||||
model=AutoModelForCausalLM.from_pretrained('/root/autodl-tmp/THUCoAI/CharacterGLM-6B',trust_remote_code=True,torch_dtype=torch.half,device_map="auto")
|
||||
```
|
||||
|
||||
## 定义LoraConfig
|
||||
|
||||
LoraConfig这个类中可以设置很多参数,部分参数展示如下:
|
||||
task_type:模型类型
|
||||
target——modules:需要训练的模型层的名字,主要就是attention部分的层,不同的模型对应的层的名字不同,可以传入数组,也可以字符串,也可以正则表达式。
|
||||
r:lora的秩
|
||||
lora_alpha:Lora alpha
|
||||
modules_to_save:指定的是除了拆成lora的模块,其它的模块可以完整的指定训练
|
||||
|
||||
Lora的所方式lora_alpha/r,在这个LoraConfig中缩放就是4倍。这个缩放的本质并没有改变Lora的参数量大小,本质在于将里面的参数数值做广播乘法,进行线性的缩放。
|
||||
|
||||
```python
|
||||
config=LoraConfig(
|
||||
task_type=TaskType.CAUSAL_LM,
|
||||
target_modules=["query_key_value"],
|
||||
inference_mode=False,
|
||||
r=8,
|
||||
lora_alpha=32,
|
||||
lora_dropout=0.1
|
||||
)
|
||||
```
|
||||
|
||||
## 自定义TraininArguments参数
|
||||
|
||||
TrainingArguments这个类的源码也介绍了每个参数的具体作用,常用的参数如下:
|
||||
output_dir:模型的输出路径
|
||||
per_device_train_batch_size:batch_size
|
||||
gradient_accumulation_steps:梯度累加,如果显存比较小,可以把batch_size设置小一点,梯度累积增大一点
|
||||
logging_steps:多少步,输出一次log
|
||||
num_train_epochs:顾名思义epoch
|
||||
gradient_chechpointing:梯度检查,这个一旦开启,模型就必须执行
|
||||
model.enable_input_require_grads()
|
||||
|
||||
```python
|
||||
data_collator=DataCollatorForSeq2Seq(
|
||||
tokenizer,
|
||||
model=model,
|
||||
label_pad_token_id=-100,
|
||||
pad_to_multiple_of=None,
|
||||
padding=False
|
||||
)
|
||||
args=TrainingArguments(
|
||||
output_dir="./output/CharacterGLM",
|
||||
per_device_train_batch_size=4,
|
||||
gradient_accumulation_steps=2,
|
||||
logging_steps=10,
|
||||
num_train_epochs=3,
|
||||
gradient_checkpointing=True,
|
||||
save_steps=100,
|
||||
learning_rate=1e-4,
|
||||
)
|
||||
```
|
||||
|
||||
## 使用Trainer训练
|
||||
|
||||
把model放进去,把上面设置的参数放进去,数据集放进去,开始训练
|
||||
|
||||
```python
|
||||
trainer=Trainer(
|
||||
model=model,
|
||||
args=args,
|
||||
train_dataset=tokenized_id,
|
||||
data_collator=data_collator,
|
||||
)
|
||||
trainer.train()
|
||||
```
|
||||
|
||||
## 模型推理
|
||||
|
||||
```python
|
||||
model = model.cuda()
|
||||
ipt = tokenizer("用户:{}\n{}".format("现在你要扮演皇帝身边的女人--甄嬛。你是谁?", "").strip() + "characterGLM-6B:\n", return_tensors="pt").to(model.device)
|
||||
tokenizer.decode(model.generate(**ipt, max_length=128, do_sample=True)[0], skip_special_tokens=True)
|
||||
```
|
||||
|
||||
## 从新加载
|
||||
|
||||
通过PEFT所微调的模型,都可以使用下面的方法进行重新加载,并推理:
|
||||
|
||||
加载源model与tokenizer;
|
||||
使用PeftModel合并源model与PEFT微调后的参数
|
||||
|
||||
```python
|
||||
from peft import Peftmodel
|
||||
model=AutoModelForCausalLM.from_pretrained("/root/autodl-tmp/THUCoAI/CharacterGLM-6B",trust_remote_code=True,low_cpu_mem_usage=True)
|
||||
tokenizer=AutoTokenizer.from_pretrained("root/autodl-tmp/THUCoAI/CharacterGLM-6B",use_fast=False,trust_remote_code=True)
|
||||
p_model=PeftModel.from_pretrained(model,model_id="./output/CharatcerGLM/checkpoint-1000/")
|
||||
ipt = tokenizer("用户:{}\n{}".format("现在你要扮演皇帝身边的女人--甄嬛。你是谁?", "").strip() + "characterGLM-6B:\n", return_tensors="pt").to(model.device)
|
||||
tokenizer.decode(p_model.generate(**ipt,max_length=128,do_sample=True)[0],skip_special_tokens=True)
|
||||
```
|
||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 143 KiB |
|
Before Width: | Height: | Size: 223 KiB After Width: | Height: | Size: 223 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |