云端部署ChatGLM-6B

大模型这里更新是挺快的,我参考的视频教程就和我这个稍微有些不一样,这距离教程发布只过去4天而已…

不过基本操作也差不多


AutoDL算力云:https://www.autodl.com/home

ChatGLM3:https://github.com/THUDM/ChatGLM3/tree/main

Hugging Face:https://huggingface.co/THUDM/chatglm3-6b/tree/main

视频教程:https://www.bilibili.com/video/BV1E94y1V7Lz

租用

按量计费

  1. 注册账号。新用户有免费一个月的会员,学生的话认证后每次认证有一年的会员,会员95折,能便宜一点是一点

  2. 租用一个3090的GPU,有很多地区选,多点点,找个便宜的就行

在这里插入图片描述

  1. 基础镜像里面的pytorch选最新的就行

需要注意,cuda版本不能超过当前主机最高支持的版本

在这里插入图片描述

  1. 租用完成后,在控制台页面先关机,然后选择以无卡方式启动,这个省钱,毕竟部署的时候还不需要GPU

在这里插入图片描述

  1. 使用jupyterLab打开

在这里插入图片描述

  1. 点击进入数据盘【autodl-tmp】,在数据盘打开终端

在这里插入图片描述

  1. 在终端中执行后续操作

在这里插入图片描述

部署

  1. 开启学术加速
source /etc/network_turbo

在这里插入图片描述

  1. 初始化git lfs
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash

sudo apt-get install git-lfs

在这里插入图片描述

  1. 克隆github仓库
git clone https://github.com/THUDM/ChatGLM3

在这里插入图片描述

  1. 到ChatGLM3目录下
cd ChatGLM3

clear
  1. 升级pip
python -m pip install --upgrade pip

在这里插入图片描述

  1. 安装依赖【看见successfully就表示安装成功】
pip install -r requirements.txt

在这里插入图片描述

  1. 拉取 Hugging Face下的模型

根据官方的如果从 HuggingFace 下载比较慢,也可以从 ModelScope 中下载。

使用这个我也试了,确实是快一些,可以直接跳到第十步,后面几步都不需要执行了

git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
git clone https://huggingface.co/THUDM/chatglm3-6b
  1. 拉取的时候大的模型文件可能拉不下来,需要手动下载。如果【chatglm3-6b】文件夹下有以下10个文件,可以按【Ctrl+C】终止git克隆,手动安装模型权重文件

在这里插入图片描述

  1. 依次执行以下代码,下载模型权重文件

一定要在chatglm3-6b文件夹下执行

cd chatglm3-6b

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00001-of-00007.bin

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00002-of-00007.bin

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00003-of-00007.bin

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00004-of-00007.bin

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00005-of-00007.bin

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00006-of-00007.bin

wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model-00007-of-00007.bin
  1. 关机,重启,因为刚才是以无卡模式启动的,现在需要跑模型了,需要使用GPU。

测试

  1. 修改模型路径。打开【basic_demo】文件夹下的cli_demo.py文件,将里面的model_path改为你刚才下载Hugging Face里面的模型的路径,【“…/chatglm3-6b/”】

关于这个路径的问题,大家一定要看好你执行的这个文件相对于模型文件夹的位置关系,ChatGLM另一个git仓库有的python文件没有放到文件夹中,直接就在根目录里面了

如果路径不对,他就会报错,说你的格式不对,***之类的,这时候不要怀疑你之前没有作对,仅仅只是路径没写对

# 一些报错

huggingface_hub.utils._validators.HFValidationError: Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'chatglm3-6b/'.

OSError: ChatGLM3/chatglm3-6b is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.

在这里插入图片描述

  1. 运行cli_demo.py,在终端窗口内进行对话
cd basic_demo
python cli_demo.py

在这里插入图片描述

  1. 运行基于gradio的网页端的模型,web_demo.py

运行生成的网址是不能直接访问的,根据官方的教程,安装Windows桌面工具下载

然后就可以在本地访问gradio生成的网页

下面streamlit 生成的网页也是这样,但是streamlit生成的网址,我们只需要访问这个端口号就行,直接点击那个生成的网址即使挂代理了也打不开

python web_demo.py

在这里插入图片描述

在这里插入图片描述

  1. 运行基于streamlit 的网页端的模型,web_demo2.py

直接访问端口号,不用访问他生成的

在这里插入图片描述

streamlit run web_demo2.py

在这里插入图片描述

综合 Demo

集成了以下功能

  • Chat: 对话模式,在此模式下可以与模型进行对话。
  • Tool: 工具模式,模型除了对话外,还可以通过工具进行其他操作。
  • Code Interpreter: 代码解释器模式,模型可以在一个 Jupyter 环境中执行代码并获取结果,以完成复杂任务。
  1. 新建一个 conda 环境并安装所需依赖
conda create -n chatglm3-demo python=3.10

source activate

source deactivate

conda activate chatglm3-demo

pip install -r requirements.txt
  1. 使用 Code Interpreter 还需要安装 Jupyter 内核:
ipython kernel install --name chatglm3-demo --user
  1. 运行
streamlit run main.py

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_61228493/article/details/134365970