From 8d8cb07c59696f55823473d88f5b1de2eaf4cbae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E0=A6=8F=E8=A8=B1=E6=88=91=E8=BE=9E=E5=BF=A7=E0=BF=90?=
=?UTF-8?q?=E2=99=A1?=
<127636623+Smiling-Weeping-zhr@users.noreply.github.com>
Date: Thu, 14 Mar 2024 23:56:18 +0800
Subject: [PATCH 1/4] Add files via upload
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加本地部署fastapi
---
deploy/api-file.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
create mode 100644 deploy/api-file.py
diff --git a/deploy/api-file.py b/deploy/api-file.py
new file mode 100644
index 0000000..f79c0e1
--- /dev/null
+++ b/deploy/api-file.py
@@ -0,0 +1,85 @@
+from fastapi import FastAPI, Request
+from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
+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设备信息
+# 加载模型
+from transformers.utils import logging
+from openxlab.model import download
+
+logger = logging.get_logger(__name__)
+
+# 可修改
+download(model_repo='ajupyter/EmoLLM_aiwei',
+ output='model')
+
+# 清理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') # 获取请求中的温度参数
+ # 调用模型进行对话生成
+ response, history = model.chat(
+ tokenizer,
+ 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("model", trust_remote_code=True)
+ model = (
+ AutoModelForCausalLM.from_pretrained("model", device_map="auto", trust_remote_code=True)
+ .to(torch.bfloat16)
+ .cuda()
+ )
+ # model = AutoModelForCausalLM.from_pretrained("model", device_map="auto", trust_remote_code=True).eval()
+ model.generation_config = GenerationConfig(max_length=2048, top_p=0.7, temperature=0.95) # 可指定
+ model.eval() # 设置模型为评估模式
+ # 启动FastAPI应用
+ # 用6006端口可以将autodl的端口映射到本地,从而在本地使用api
+ uvicorn.run(app, host='127.0.0.1', port=6006, workers=1) # 在指定端口和主机上启动应用
From 000491f1befab3f8b5989b0b54b568c29e017768 Mon Sep 17 00:00:00 2001
From: Anooyman <875734078@qq.com>
Date: Fri, 15 Mar 2024 19:51:04 +0800
Subject: [PATCH 2/4] Merge Main code (#2)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Add files via upload
* 新增ENmd文档
* Update README.md
* Update README_EN.md
* Update LICENSE
* [docs] update lmdeploy file
* add ocr.md
* Update tutorial.md
* Update tutorial_EN.md
* Update General_evaluation_EN.md
* Update General_evaluation_EN.md
* Update README.md
Add InternLM2_7B_chat_full's professional evaluation results
* Update Professional_evaluation.md
* Update Professional_evaluation.md
* Update Professional_evaluation.md
* Update Professional_evaluation.md
* Update Professional_evaluation_EN.md
* Update README.md
* Update README.md
* Update README_EN.md
* Update README_EN.md
* Update README_EN.md
* [DOC] update readme
* Update LICENSE
* Update LICENSE
* update personal info and small format optimizations
* update personal info and translations for contents in a table
* Update RAG README
* Update demo link in README.md
* Update xlab app link
* Update xlab link
* add xlab model
* Update web_demo-aiwei.py
* add bitex
---------
Co-authored-by: xzw <62385492+aJupyter@users.noreply.github.com>
Co-authored-by: এ許我辞忧࿐♡ <127636623+Smiling-Weeping-zhr@users.noreply.github.com>
Co-authored-by: Vicky
- 简体中文| English
+
-
+EmoLLM
-
@@ -103,22 +119,23 @@
## 目录
- [EmoLLM-心理健康大模型](#emollm-心理健康大模型)
- - [最近更新](#最近更新)
+ - [🎇最近更新](#最近更新)
+ - [🎯路线图](#路线图)
- [目录](#目录)
- [开发前的配置要求](#开发前的配置要求)
- [**使用指南**](#使用指南)
- - [文件目录说明](#文件目录说明)
- [数据构建](#数据构建)
- [微调指南](#微调指南)
- [部署指南](#部署指南)
+ - [RAG(检索增强生成)Pipeline](#rag检索增强生成pipeline)
- [使用到的框架](#使用到的框架)
- [如何参与本项目](#如何参与本项目)
- - [版本控制](#版本控制)
- [作者(排名不分先后)](#作者排名不分先后)
- [版权说明](#版权说明)
- [特别鸣谢](#特别鸣谢)
- [Star History](#star-history)
- [🌟 Contributors](#-contributors)
+ - [交流群](#交流群)
###### 开发前的配置要求
@@ -133,31 +150,17 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git
```
2. 依次阅读或者选择感兴趣的部分阅读:
- - [文件目录说明](#文件目录说明)
- [数据构建](#数据构建)
- [微调指南](#微调指南)
- [部署指南](#部署指南)
+ - [RAG](#rag检索增强生成pipeline)
- 查看更多详情
-
-### 文件目录说明
-
-```
-├─assets:图像资源
-├─datasets:数据集
-├─demo:demo脚本
-├─generate_data:生成数据指南
-│ └─xinghuo
-├─scripts:一些可用工具
-└─xtuner_config:微调指南
- └─images
-```
-
### 数据构建
-请阅读[数据构建指南](generate_data/tutorial.md)查阅
+- 请阅读[数据构建指南](generate_data/tutorial.md)查阅
-本次微调用到的数据集见[datasets](datasets/data.json)
+- 微调用到的数据集见[datasets](datasets/data.json)
### 微调指南
@@ -165,16 +168,24 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git
### 部署指南
-详见[部署指南](demo/README.md)
+- Demo部署:详见[部署指南](demo/README.md)
+- 基于[LMDeploy](https://github.com/InternLM/lmdeploy/)的量化部署:详见[deploy](./deploy/lmdeploy.md)
+
+### RAG(检索增强生成)Pipeline
+
+- 详见[RAG](./rag/)
+
+
-
- }8Q71dLK~x9NVCmsj1OZz;FGsHOnCez@88
z+SH2i@y^$Wqw%slx+XOFZl !u#qEiY更多详情
### 使用到的框架
-- [Xtuner](https://github.com/InternLM/xtuner)
+- [Xtuner](https://github.com/InternLM/xtuner):用于微调
- [Transformers](https://github.com/huggingface/transformers)
- [Pytorch](https://pytorch.org/)
+- [LMDeploy](https://github.com/InternLM/lmdeploy/):用于量化部署
+- [Stremlit](https://streamlit.io/):用于构建Demo
+- [DeepSpeed](https://github.com/microsoft/DeepSpeed):并行训练
- …
#### 如何参与本项目
@@ -187,45 +198,44 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
-### 版本控制
-
-该项目使用Git进行版本管理。您可以在repository参看当前可用版本。
-
+
+
+
-
-
-
+
EmoLLM
@@ -35,24 +41,31 @@
-**EmoLLM** is a series of large language models designed to understand, support and help customers in mental health counseling. It is fine-tuned from the LLM instructions. We really appreciate it if you can give it a star~⭐⭐. The open-sourced configuration is as follows:
+**EmoLLM** is a series of large language models designed to understand, support and help customers in mental health counseling. It is fine-tuned from the LLM instructions. We really appreciate it if you could give it a star~⭐⭐. The open-sourced configuration is as follows:
-| model | type |
+Additional Details
@@ -179,6 +201,9 @@ For details, see the [deployment guide](demo/README.md)
- [Xtuner](https://github.com/InternLM/xtuner)
- [Transformers](https://github.com/huggingface/transformers)
- [Pytorch](https://pytorch.org/)
+- [LMDeploy](https://github.com/InternLM/lmdeploy/): for quantitative deployment
+- [Stremlit](https://streamlit.io/): for building demos
+- [DeepSpeed](https://github.com/microsoft/DeepSpeed): for parallel training
- …
#### How to participate in this project
@@ -193,39 +218,31 @@ Contributions make the open-source community an excellent place for learning, in
### Version control
-This project uses Git for version control. You can see the current available versions in the repository.
+This project uses Git for version control. You can see the currently available versions in the repository.
-!9#5y{*UmKDV*KrK9WKN!|J
zvcH7AYFE09o$WxeN6kWcxb`p+jI$DWU8U6-Vs
dbGcUu!&Epub{{r1We
{Qoq*yvVi&Xl1A&wU)NI7i$+o5=0GSVvhK&%a
zt*@P3LU=7kGDCD9FcFY%UidsRhgFiWu~z#(RF(G=y5opAwN8zdhcom7I3xh+d(;+d
zaUpB2l}z)#{00n7-Vj?z;k)>9W_J&-eP6i`RI+crW-VcAWBRN;<}te;-#<~;1BGdz
zfbOYy7gBDAS1`m<=nJKh(H*TwKDYK84%2ybgUiwqz0+%lJyvn^3=PvkSzSUpfo!Kb
zfm*!9p}GyAW&cz9>MqEu7ETs8(F7uaN6s`--HV#9kFvS7`6f1QHHmu{Q*#zDy4Ci2
zD6u9M`MpGlmySC7=?W$NfvXCq(oxi2e4!+!b0=D2r>jJxtfRqhJm0k0ui^G2e4N4;
z^f;~XB7iwd)bakR1AV}=xgMWCIn^EXu<)UaOPZyu8vzF3sO|A@fQ&A9j}Tlq&=c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