uopdate chatglm chat && readme

This commit is contained in:
KMnO4-zx
2023-11-17 11:25:42 +08:00
parent 01b0946793
commit e8aa52f5e2
5 changed files with 154 additions and 5 deletions
+87
View File
@@ -0,0 +1,87 @@
# ChatGLM3-6B-chat
## 环境准备
在[autodl](https://www.autodl.com/)平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择`PyTorch`-->`2.0.0`-->`3.8(ubuntu20.04)`-->`11.8`
![Alt text](images/image-1.png)
接下来打开刚刚租用服务器的`JupyterLab`,并且打开其中的终端开始环境配置、模型下载和运行`demo`
pip换源和安装依赖包
```shell
# 更换 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`执行下载,模型大小为 14 GB,下载模型大概需要 10~20 分钟
```python
import torch
from modelscope import snapshot_download, AutoModel, AutoTokenizer
import os
model_dir = snapshot_download('ZhipuAI/chatglm3-6b', cache_dir='/root/autodl-tmp', revision='master')
```
## 代码准备
首先`clone`代码,打开autodl平台自带的学术镜像加速。学术镜像加速详细使用请看:https://www.autodl.com/docs/network_turbo/
```shell
source /etc/network_turbo
```
然后切换路径, clone代码.
```shell
cd /root/autodl-tmp
git clone https://github.com/THUDM/ChatGLM3.git
```
切换commit版本,与教程commit版本保持一致,可以让大家更好的复现。
```shell
cd ChatGLM3
git checkout f823b4a3be9666b9b2a9daa43b29659e876a040d
```
最后取消镜像加速,因为该加速可能对正常网络造成一定影响,避免对后续下载其他模型造成困扰。
```shell
unset http_proxy && unset https_proxy
```
修改代码路径,将 `/root/autodl-tmp/ChatGLM3/basic_demo/web_demo2.py`中 13 行的模型更换为本地的`/root/autodl-tmp/ZhipuAI/chatglm3-6b`
![Alt text](images/image-2.png)
## demo运行
修改`requirements.txt`文件,将其中的`torch`删掉,环境中已经有了`torch`,不需要再安装。然后执行下面的命令:
```shell
cd /root/autodl-tmp/ChatGLM3
pip install -r requirements.txt
```
运行以下命令即可启动推理服务
```shell
cd /root/autodl-tmp/ChatGLM3
streamlit run ./basic_demo/web_demo2.py --server.address 127.0.0.1 --server.port 6006
```
`autodl `的端口映射到本地的 [http://localhost:6006](http://localhost:6006/) 即可看到demo界面。
注意:要在浏览器打开`http://localhost:6006`页面后,模型才会加载,如下图所示:
![Alt text](images/image-3.png)
Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

+67 -5
View File
@@ -1,5 +1,12 @@
# llm-QuicklyDeploy
基于AutoDL快速部署开源大模型,更适合中国宝宝的部署教程。
  什么是大模型?
>大模型(LLM)狭义上指基于深度学习算法进行训练的自然语言处理(NLP)模型,主要应用于自然语言理解和生成等领域,广义上还包括机器视觉(CV)大模型、多模态大模型和科学计算大模型等。
  如今国内外已经涌现了太多的开源大模型,国内也有很多优秀的开源大模型如:InternLM(书生·蒲语),ChatGLM,Qwen(通义千问),Yi(零一万物)等等。当前普通用户想要使用这些大模型,需要具备一定的技术能力,才能完成模型的部署和使用。本项目旨在简化大模型的部署和使用,让更多的人能够使用大模型,利用大模型更好的学习和工作。
  本项目基于AutoDL快速部署开源大模型,更适合中国宝宝的部署教程。
# 模型
@@ -8,16 +15,71 @@
- [x] Lagent+InternLM-Chat-7B-V1.1
- [x] 浦语灵笔图文理解&创作
- ChatGLM
- [ ] ChatGLM3-6B
- [ ] CogVlm
- [x] ChatGLM3-6B chat
- [ ] ChatGLM3-6B Code Interpreter
- Qwen
- [ ] Qwen-7B
- [ ] Qwen-VL
- [ ] Qwen-7B-chat
- Yi
- [ ] Yi-7B-chat
- 欢迎提交新模型
# 通用环境配置
## pip、conda 换源
更多详细内容可移步至[MirrorZ Help](https://help.mirrors.cernet.edu.cn/)查看。
### pip 换源
临时使用镜像源安装,如下所示:`some-package` 为你需要安装的包名
```shell
pip install -i https://mirrors.cernet.edu.cn/pypi/web/simple some-package
```
设置pip默认镜像源,升级 pip 到最新的版本 (>=10.0.0) 后进行配置,如下所示:
```shell
python -m pip install --upgrade pip
pip config set global.index-url https://mirrors.cernet.edu.cn/pypi/web/simple
```
如果您的 pip 默认源的网络连接较差,临时使用镜像源升级 pip:
```shell
python -m pip install -i https://mirrors.cernet.edu.cn/pypi/web/simple --upgrade pip
```
### conda 换源
镜像站提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch 等,各系统都可以通过修改用户目录下的 .condarc 文件来使用镜像站。
不同系统下的.condarc目录如下:
- Linux: ${HOME}/.condarc
- macOS: ${HOME}/.condarc
- Windows: C:\Users\<YourUserName>\.condarc
注意:
- Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。
快速配置
```shell
cat <<'EOF' > ~/.condarc
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
EOF
```
## 开放端口
`autodl `的端口映射到本地的 [http://localhost:6006](http://localhost:6006/) 仅在此处展示一次,以下两个 Demo 都是同样的方法把 `autodl `中的 `6006 `端口映射到本机的 `http://localhost:6006`的方法都是相同的,方法如图所示。