Skip to content

Commit

Permalink
update chatglm deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Elvin-Ma committed Jul 2, 2023
1 parent d380db2 commit 55ef5d5
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 55 deletions.
13 changes: 0 additions & 13 deletions 12-model_deploy_guide/flask_deploy/app.py

This file was deleted.

2 changes: 2 additions & 0 deletions 13-model_deploy_guide/container_deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx
RUN echo '这是一个本地构建的nginx镜像' > /usr/share/nginx/html/index.html
16 changes: 9 additions & 7 deletions 13-model_deploy_guide/container_deploy/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)<br>
[docker github](https://github.com/docker/docker-ce)<br>
[docker guide page](https://dockerdocs.cn/get-started/index.html)<br>
[dockerfile]https://www.runoob.com/docker/docker-dockerfile.html<br>
[docker 命令查询](https://docs.docker.com/engine/reference/commandline/docker/)<br>
[dockerfile 命令查询](https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact)<br>

#得到image的几种方法
方法1:docker pull # 拉取仓库的镜像
Expand Down Expand Up @@ -90,4 +92,4 @@ EXPOSE 5000
# 启动应用程序
CMD ["python", "app.py"]
```
**docker build . 从上述dockerfile中创建镜像**
**docker build -t . 从上述dockerfile中创建镜像**
Binary file not shown.
5 changes: 3 additions & 2 deletions 13-model_deploy_guide/cpp_deploy/mnist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ project(mnist)
set(CMAKE_CXX_STANDARD 14)

# 设置自己的 torch 路径
set(Torch_DIR /home/elvin/.conda/envs/pytorch_env/lib/python3.8/site-packages/torch/share/cmake/Torch)
#set(Torch_DIR /home/elvin/.conda/envs/pytorch_env/lib/python3.8/site-packages/torch/share/cmake/Torch)
set(Torch_DIR /home/elvin/miniconda3/envs/python3.10/lib/python3.10/site-packages/torch/share/cmake/Torch)
find_package(Torch REQUIRED)

option(DOWNLOAD_MNIST "Download the MNIST dataset from the internet" ON)
option(DOWNLOAD_MNIST "Download the MNIST dataset from the internet" OFF)
if (DOWNLOAD_MNIST)
message(STATUS "Downloading MNIST dataset")
execute_process(
Expand Down
7 changes: 4 additions & 3 deletions 13-model_deploy_guide/cpp_deploy/mnist/mnist-infer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <torch/torch.h>
#include <torch/torch.h> //
#include <torch/script.h>
#include <cstddef>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
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);
Expand All @@ -14,11 +15,11 @@ void mnist_train() {
auto max_result = output.max(1, true);
auto max_index = std::get<1>(max_result).item<float>();
std::cout << "=========cpu max_index: " << max_index << std::endl;
return max_index;
}

int main() {
mnist_train();
std::cout << "run mnist-infer.cpp successfully !!!" << std::endl;
return 0;
}

10 changes: 10 additions & 0 deletions 13-model_deploy_guide/flask_deploy/flask_demo/hello.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions 13-model_deploy_guide/flask_deploy/flask_demo/resnet_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import onnx
import onnxruntime
#import onnxruntime
import numpy as np
from PIL import Image
import torch
Expand Down Expand Up @@ -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")
print("run resnet_infer.py successfully")
Original file line number Diff line number Diff line change
Expand Up @@ -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()


31 changes: 31 additions & 0 deletions 13-model_deploy_guide/java_deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 1. 部署我们自己的聊天机器人

## 1.1 代码准备
git clone [email protected]: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)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
54 changes: 27 additions & 27 deletions 6-save_load_guide/save_load_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand All @@ -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 !!!")
print("run save_load_demo.py successfully !!!")

0 comments on commit 55ef5d5

Please sign in to comment.