From 55ef5d57436cc28093b75979190cb74acd54fc30 Mon Sep 17 00:00:00 2001 From: Elvin-Ma Date: Sun, 2 Jul 2023 23:51:05 +0800 Subject: [PATCH] update chatglm deploy --- 12-model_deploy_guide/flask_deploy/app.py | 13 ----- .../container_deploy/Dockerfile | 2 + .../container_deploy/README.md | 16 +++--- .../cpp_deploy/mnist/.CMakeLists.txt.swp | Bin 0 -> 12288 bytes .../cpp_deploy/mnist/CMakeLists.txt | 5 +- .../cpp_deploy/mnist/mnist-infer.cpp | 7 ++- .../flask_deploy/flask_demo/hello.py | 10 ++++ .../flask_deploy/flask_demo/resnet_infer.py | 4 +- .../flask_deploy/flask_demo/upload_image.py | 1 + 13-model_deploy_guide/java_deploy/README.md | 31 ++++++++++ .../{READEME.md => README.md} | 0 .../README.md | 0 .../chatGLM/README.md | 9 ++- .../miniGPT/README.md | 0 .../miniGPT/chatgpt_demo.py | 0 6-save_load_guide/save_load_demo.py | 54 +++++++++--------- 16 files changed, 97 insertions(+), 55 deletions(-) delete mode 100644 12-model_deploy_guide/flask_deploy/app.py create mode 100644 13-model_deploy_guide/container_deploy/Dockerfile create mode 100644 13-model_deploy_guide/cpp_deploy/mnist/.CMakeLists.txt.swp create mode 100644 13-model_deploy_guide/flask_deploy/flask_demo/hello.py create mode 100644 13-model_deploy_guide/java_deploy/README.md rename 14-docker_image_container_guide/{READEME.md => README.md} (100%) rename {14-model_learning => 15-model_learning}/README.md (100%) rename {14-model_learning => 15-model_learning}/chatGLM/README.md (67%) rename {14-model_learning => 15-model_learning}/miniGPT/README.md (100%) rename {14-model_learning => 15-model_learning}/miniGPT/chatgpt_demo.py (100%) diff --git a/12-model_deploy_guide/flask_deploy/app.py b/12-model_deploy_guide/flask_deploy/app.py deleted file mode 100644 index ab016f3..0000000 --- a/12-model_deploy_guide/flask_deploy/app.py +++ /dev/null @@ -1,13 +0,0 @@ -from flask import Flask - -app = Flask(__name__) - -@app.route("/") -def hello_world(): - return "

Hello, World!

" - - -if __name__ == '__main__': - # app.debug = True - # app.run(host='0.0.0.0', port=8987, debug=True) - app.run(host='0.0.0.0', port=5000) diff --git a/13-model_deploy_guide/container_deploy/Dockerfile b/13-model_deploy_guide/container_deploy/Dockerfile new file mode 100644 index 0000000..68563fe --- /dev/null +++ b/13-model_deploy_guide/container_deploy/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx +RUN echo '这是一个本地构建的nginx镜像' > /usr/share/nginx/html/index.html \ No newline at end of file diff --git a/13-model_deploy_guide/container_deploy/README.md b/13-model_deploy_guide/container_deploy/README.md index e953687..ff99025 100644 --- a/13-model_deploy_guide/container_deploy/README.md +++ b/13-model_deploy_guide/container_deploy/README.md @@ -1,6 +1,8 @@ # 镜像与容器 概念介绍 **docker:管理镜像和容器** + ![docker](https://www.runoob.com/wp-content/uploads/2016/04/docker01.png) + [docker 入门教程](https://www.runoob.com/docker/docker-tutorial.html) # 理解docker @@ -12,12 +14,12 @@ - 镜像是可以保存的,就可以不用每次都run dockerfile了。 # 一些重要网站 -[docker 官网](https://www.docker.com) -[docker github](https://github.com/docker/docker-ce) -[docker guide page](https://dockerdocs.cn/get-started/index.html) -[dockerfile]https://www.runoob.com/docker/docker-dockerfile.html -[docker 命令查询](https://docs.docker.com/engine/reference/commandline/docker/) -[dockerfile 命令查询](https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact) +[docker 官网](https://www.docker.com)
+[docker github](https://github.com/docker/docker-ce)
+[docker guide page](https://dockerdocs.cn/get-started/index.html)
+[dockerfile]https://www.runoob.com/docker/docker-dockerfile.html
+[docker 命令查询](https://docs.docker.com/engine/reference/commandline/docker/)
+[dockerfile 命令查询](https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact)
#得到image的几种方法 方法1:docker pull # 拉取仓库的镜像 @@ -90,4 +92,4 @@ EXPOSE 5000 # 启动应用程序 CMD ["python", "app.py"] ``` -**docker build . 从上述dockerfile中创建镜像** +**docker build -t . 从上述dockerfile中创建镜像** diff --git a/13-model_deploy_guide/cpp_deploy/mnist/.CMakeLists.txt.swp b/13-model_deploy_guide/cpp_deploy/mnist/.CMakeLists.txt.swp new file mode 100644 index 0000000000000000000000000000000000000000..15c182d4c598213a155eda1f47dec268a6b72d36 GIT binary patch literal 12288 zcmeI2&yU+g6vtmd910W=+|iJ(P>hs#!y>V&5Rwx+#nef*PO>bg!LcXFu>OTTDZ8oy zmkKTjP9RZn;Q$8?TOke=NL1p&g$w@!s=6nHio}Hr&p$T1TV=bwR*a=@Y>#K=z4v*~ z2P<#1x@mUEdVLk}cn09pFTeKo`j5h!j{`9O3JtaWo;+%Xe2}l9}Gcm5M zpM$lR8~Lk#zVZTj?%AOvBMC?Xl7J*22}lBxfFvLZNCN*O0wO*GA7Z?ZlrgWA=QH=5 z%UgMp1SA1TKoXDyBmqf45|9KW0ZBj-kOU-whme5d0sL_m;4}QcKl}gx;QRmgrvZLJ zeT(`A^%3fM)DKSqe1ZBLbqVz<>MZJ?a{zm&Pf#4yM?Hr6_ep@iQFl?lqOPOfLA{9j z>j{9LP(Pw>pi4>kX<~R)4;H$5yY?(YiWWx!USz zmke6o&q>W7ZWQlQKBnl^m?bO}%eUC*^#`;$G%X#UJDx|~St_D{x=|1~p;s+jCb_3L zW6XV4y=e8C~v1oe5ijX$Hr zNjOWZxrrJN(OV3t*xoXmwq~0~f3Dnjl}H>O-ftC#6Qk>N%p5UG?yRLTbFP6+P zM}%ZqIzC=hXTB@l#9U}i%OK095K{9NmDn`9n*DZG`QeDabM!Cy|ShS8?co09M~%*e4bJq_E36T)3Yz zQ6P#1kHW*i3sj43h?uhD_{cbkf_#{Vf+Zmn71C?B6@W1hJsLaic9xMr)-6tKn=w`YxTxz{t_LzO}SvT(m;xs(1Myy zorI}wfX(GTLXx`toI7;>5Btu2ZP>gt-Ulg29wU;^J|t|;CQ1# +#include // #include #include #include #include #include #include -void mnist_train() { + +int mnist_train() { torch::DeviceType device_type = torch::kCPU; torch::Device device(device_type); auto input = torch::rand({1, 1, 28, 28}, torch::kFloat32); @@ -14,6 +15,7 @@ void mnist_train() { auto max_result = output.max(1, true); auto max_index = std::get<1>(max_result).item(); std::cout << "=========cpu max_index: " << max_index << std::endl; + return max_index; } int main() { @@ -21,4 +23,3 @@ int main() { std::cout << "run mnist-infer.cpp successfully !!!" << std::endl; return 0; } - diff --git a/13-model_deploy_guide/flask_deploy/flask_demo/hello.py b/13-model_deploy_guide/flask_deploy/flask_demo/hello.py new file mode 100644 index 0000000..507ff5c --- /dev/null +++ b/13-model_deploy_guide/flask_deploy/flask_demo/hello.py @@ -0,0 +1,10 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +if __name__ =="__main__": + app.run(host='0.0.0.0', port=5000) diff --git a/13-model_deploy_guide/flask_deploy/flask_demo/resnet_infer.py b/13-model_deploy_guide/flask_deploy/flask_demo/resnet_infer.py index 10ceb87..407a9c8 100755 --- a/13-model_deploy_guide/flask_deploy/flask_demo/resnet_infer.py +++ b/13-model_deploy_guide/flask_deploy/flask_demo/resnet_infer.py @@ -1,5 +1,5 @@ import onnx -import onnxruntime +#import onnxruntime import numpy as np from PIL import Image import torch @@ -55,4 +55,4 @@ def image_infer(path, model_path): if __name__ == "__main__": get_onnx_model("resnet50.onnx") # image_infer("cat.jpg", "resnet50.onnx") - print("run resnet_infer.py successfully") \ No newline at end of file + print("run resnet_infer.py successfully") diff --git a/13-model_deploy_guide/flask_deploy/flask_demo/upload_image.py b/13-model_deploy_guide/flask_deploy/flask_demo/upload_image.py index 41e05d5..2d7c964 100755 --- a/13-model_deploy_guide/flask_deploy/flask_demo/upload_image.py +++ b/13-model_deploy_guide/flask_deploy/flask_demo/upload_image.py @@ -60,4 +60,5 @@ def upload(): # app.run(host='0.0.0.0', port=8987, debug=True) app.run(host='0.0.0.0', port=8987) # app.run() + \ No newline at end of file diff --git a/13-model_deploy_guide/java_deploy/README.md b/13-model_deploy_guide/java_deploy/README.md new file mode 100644 index 0000000..eb44813 --- /dev/null +++ b/13-model_deploy_guide/java_deploy/README.md @@ -0,0 +1,31 @@ +# 1. 部署我们自己的聊天机器人 + +## 1.1 代码准备 +git clone git@github.com:wenda-LLM/wenda.git +*自己download 也可以* + +## 1.2 模型准备 +- [链接](https://pan.baidu.com/s/1VPRGReHfnnqe_ULKjquoaQ?pwd=oaae) +- 提取码:oaae +- 将pretrained model 放到 wenda/model 下(建议); + +## 1.3 环境准备 +```shell +- conda create -n python3.10 python=3.10(建议) +- pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 +- cd */wenda/requirements/ +- pip install -r requirements.txt # update transformers==4.27.1 +- pip install requirements-glm6b-lora.txt +- pip install protobuf transformers==4.27.1 cpm_kernels +``` +## 1.4 运行程序 +cp example.config.yml config.yml +source run_GLM6B.sh + +## 1.5 连接网络进行访问 +http://172.29.240.181:17860 +**注意:IP要换成自己的IP,端口号 和 config.yml 保存一致** + +# 2 [参考资料] +[参考资料2](https://huggingface.co/THUDM/chatglm-6b-int4) +[参考资料](https://github.com/wenda-LLM/wenda/tree/main) \ No newline at end of file diff --git a/14-docker_image_container_guide/READEME.md b/14-docker_image_container_guide/README.md similarity index 100% rename from 14-docker_image_container_guide/READEME.md rename to 14-docker_image_container_guide/README.md diff --git a/14-model_learning/README.md b/15-model_learning/README.md similarity index 100% rename from 14-model_learning/README.md rename to 15-model_learning/README.md diff --git a/14-model_learning/chatGLM/README.md b/15-model_learning/chatGLM/README.md similarity index 67% rename from 14-model_learning/chatGLM/README.md rename to 15-model_learning/chatGLM/README.md index 8cb3264..194a730 100644 --- a/14-model_learning/chatGLM/README.md +++ b/15-model_learning/chatGLM/README.md @@ -1,6 +1,13 @@ # 聊天机器人 + +## 1.1 环境搭建 ```shell -pip install protobuf transformers==4.27.1 cpm_kernels +- conda create -n python3.10 python=3.10(建议) +- pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 +- cd */wenda/requirements/ +- pip install -r requirements.txt # update transformers==4.27.1 +- pip install requirements-glm6b-lora.txt +- pip install protobuf transformers==4.27.1 cpm_kernels ``` ## coding ```python diff --git a/14-model_learning/miniGPT/README.md b/15-model_learning/miniGPT/README.md similarity index 100% rename from 14-model_learning/miniGPT/README.md rename to 15-model_learning/miniGPT/README.md diff --git a/14-model_learning/miniGPT/chatgpt_demo.py b/15-model_learning/miniGPT/chatgpt_demo.py similarity index 100% rename from 14-model_learning/miniGPT/chatgpt_demo.py rename to 15-model_learning/miniGPT/chatgpt_demo.py diff --git a/6-save_load_guide/save_load_demo.py b/6-save_load_guide/save_load_demo.py index 52bf2b6..8a6cacd 100644 --- a/6-save_load_guide/save_load_demo.py +++ b/6-save_load_guide/save_load_demo.py @@ -5,30 +5,30 @@ import torch.nn.functional as F import torch.optim as optim -# class Net(nn.Module): -# def __init__(self): -# super(Net, self).__init__() -# self.conv1 = nn.Conv2d(1, 32, 3, 1) -# self.conv2 = nn.Conv2d(32, 64, 3, 1) -# self.dropout1 = nn.Dropout(0.25) -# self.dropout2 = nn.Dropout(0.5) -# self.fc1 = nn.Linear(9216, 128) -# self.fc2 = nn.Linear(128, 10) +class Net(nn.Module): + def __init__(self): + super(Net, self).__init__() + self.conv1 = nn.Conv2d(1, 32, 3, 1) + self.conv2 = nn.Conv2d(32, 64, 3, 1) + self.dropout1 = nn.Dropout(0.25) + self.dropout2 = nn.Dropout(0.5) + self.fc1 = nn.Linear(9216, 128) + self.fc2 = nn.Linear(128, 10) -# def forward(self, x): -# x = self.conv1(x) -# x = F.relu(x) -# x = self.conv2(x) -# x = F.relu(x) -# x = F.max_pool2d(x, 2) -# x = self.dropout1(x) -# x = torch.flatten(x, 1) -# x = self.fc1(x) -# x = F.relu(x) -# x = self.dropout2(x) -# x = self.fc2(x) -# output = F.log_softmax(x, dim=1) -# return output + def forward(self, x): + x = self.conv1(x) + x = F.relu(x) + x = self.conv2(x) + x = F.relu(x) + x = F.max_pool2d(x, 2) + x = self.dropout1(x) + x = torch.flatten(x, 1) + x = self.fc1(x) + x = F.relu(x) + x = self.dropout2(x) + x = self.fc2(x) + output = F.log_softmax(x, dim=1) + return output def save_demo_v1(): model = Net() @@ -93,7 +93,7 @@ def load_ckpt_demo(): print("output shape: ", output.shape) def save_trace_model(): - model = Net() + model = Net().eval() # 通过trace 得到了一个新的model,我们最终保存的是这个新的model traced_model = torch.jit.trace(model, torch.randn(1, 1, 28, 28)) traced_model.save("traced_model.pt") @@ -112,8 +112,8 @@ def load_trace_model(): # load_para_demo() # tensor_save() # load_to_gpu() - # save_trace_model() - load_trace_model() + save_trace_model() + # load_trace_model() # save_ckpt_demo() # load_ckpt_demo() - print("run save_load_demo.py successfully !!!") \ No newline at end of file + print("run save_load_demo.py successfully !!!")