0
点赞
收藏
分享

微信扫一扫

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型

实验室地址:https://developer.aliyun.com/adc/scenario/f3dc63dc55a543c3884b8dbd292adcd5


一、先买机器并开通对应安全组8501端口

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行

规格族:GPU 计算型 gn6i

实例规格:ecs.gn6i-c4g1.xlarge

安全组新增规则

入方向
端口范围:8501/8501
授权对象:0.0.0.0/0


二、最好是安装系统的时候把安装nvidia驱动安装选择上

如果安装系统没有选择,这需要手动安装。

centos7

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --add-repo https://developer.download.nvidia.cn/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean expire-cache
sudo yum install nvidia-driver-latest-dkms
sudo yum install cuda
sudo yum install cuda-drivers
#sudo reboot
nvidia-smi

centos8

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
subscription-manager repos --enable=rhel-8-for-x86_64-appstream-rpms
subscription-manager repos --enable=rhel-8-for-x86_64-baseos-rpms
subscription-manager repos --enable=codeready-builder-for-rhel-8-x86_64-rpms
sudo dnf config-manager --add-repo https://developer.download.nvidia.cn/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
sudo dnf clean expire-cache
sudo dnf module install nvidia-driver:latest-dkms
sudo dnf install cuda
sudo dnf install nvidia-gds
#sudo reboot
nvidia-smi

驱动安装官方文档: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#local-repo-installation-for-rhel-7-centos-7

https://developer.download.nvidia.cn/compute/cuda/repos/rhel7/x86_64/

https://developer.download.nvidia.cn/compute/cuda/repos/rhel8/x86_64/

使用下面这个命令来验证

nvidia-smi

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_git_02


三、安装pytorch之前的准备

1.更新操作系统。

sudo yum update -y
sudo yum upgrade -y

2.下载并安装anaconda。

a.在命令行中,输入以下命令,点击Enter,开始下载anaconda安装包。

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_代码仓库_03

wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh

b.系统系统下载完成后,输入下列命令,点击Enter,开始安装。

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_代码仓库_04

bash Anaconda3-2023.03-1-Linux-x86_64.sh

c.遇到如下界面后,点击Enter,继续安装过程。

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行_05

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行_06

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_代码仓库_07

安装完成后重新开个连接就会出现(base)字样

注:接下来所有的操作都在新的终端中完成,命令行最左边,出现(base)字样,代表anaconda已启动。


四、安装pytorch

在实际开发过程中,通常需要通过conda安装虚拟环境,在虚拟环境中继续后续操作。本实验中,略去此步骤。

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_git_08

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_git_09

可以在命令行输入python,点击Enter,进入Python界面,输入import torch,如果出现如下界面,则代表Pytorch安装成功。



五、准备模型文件、代码仓库

1.下载模型文件、代码仓库。

模型文件通常存放在 hugging face、魔搭社区等处。代码仓库通常存放在github。由于模型文件较大,本实验中,已将模型文件和代码仓库提前下载至阿里云OSS,供实验所用,请执行下列步骤的b、c、的三步下载模型文件和代码仓库。如之后在云上GPU上需要从hugging face上下载该模型文件,需要先执行下列步骤的a部分,安装git-lfs,以支持下载模型文件这样的大型文件。

a.首先安装git lfs,以便可下载模型文件。

sudo yum install git

sudo yum install git-lfs

git lfs install

b.执行如下命令,安装unzip解压包。

yum -y install unzip

c.运行如下代码从hugging face下载模型文件。模型文件较大,超过12G。需要等待一段时间。

wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/chatglm2-6b.zip
unzip chatglm2-6b.zip

d.下载ChatGLM2-6B代码仓库。

wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/ChatGLM2-6B.zip
unzip ChatGLM2-6B.zip


  1. 修改web_demo2.py文件。

a.输入如下命令,查看模型文件与代码仓库

ls

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行_10

其中,chatglm2-6b模型文件ChatGLM2-6B代码仓库

b.输入如下命令,将模型文件移动至代码仓库目录下,以方便调用。进入代码仓库

mv chatglm2-6b ./ChatGLM2-6B
cd ChatGLM2-6B

c.输入如下命令,安装依赖文件

pip install -r requirements.txt

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行_11


d.修改运行python文件。输入如下命令,进入web_demo2.py文件

vim web_demo2.py

e. 点击i进入编辑模式。将tokenizermodel两个变量内部的文件路径,做如下修改。另外,可以对st.title内的参数做个性化修改,比如修改成“我的ChatGLM2-6B",或者其他名称。完成编辑后,点击esc(注意:需要切换回英文输入法),然后输入:wq后点击回车,保存并退出web_demo2.py

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行_12



六、运行ChatGLM2-6B对话网页

  1. 输入如下命令,安装streamlit

pip install streamlit streamlit-chat

  1. 安装完成后,输入如下命令,运行网页版demo

streamlit run web_demo2.py

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_git_13


GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_git_14

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_代码仓库_15

GPU实验室-在阿里云云上部署ChatGLM2-6B大模型_命令行_16


在云上部署ChatGLM2-6B大模型(GPU版)


sudo yum update -y
sudo yum upgrade -y

wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh
bash Anaconda3-2023.03-1-Linux-x86_64.sh

注:接下来所有的操作都在新的终端中完成,命令行最左边,出现(base)字样,代表anaconda已启动。

安装Pytorch
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

python
import torch
无报错即为成功


模型文件
wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/chatglm2-6b.zip
unzip chatglm2-6b.zip
ChatGLM2-6B仓库代码
wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/ChatGLM2-6B.zip
unzip ChatGLM2-6B.zip

ls
mv chatglm2-6b ./ChatGLM2-6B
cd ChatGLM2-6B
pip install -r requirements.txt

vim web_demo2.py
修改对应模型文件《名字位置》


pip install streamlit streamlit-chat

streamlit run web_demo2.py
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx


sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --add-repo https://developer.download.nvidia.cn/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean expire-cache
sudo yum install nvidia-driver-latest-dkms
sudo yum install cuda
sudo yum install cuda-drivers
#sudo reboot
nvidia-smi


sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
subscription-manager repos --enable=rhel-8-for-x86_64-appstream-rpms
subscription-manager repos --enable=rhel-8-for-x86_64-baseos-rpms
subscription-manager repos --enable=codeready-builder-for-rhel-8-x86_64-rpms
sudo dnf config-manager --add-repo https://developer.download.nvidia.cn/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
sudo dnf clean expire-cache
sudo dnf module install nvidia-driver:latest-dkms
sudo dnf install cuda
sudo dnf install nvidia-gds
#sudo reboot
nvidia-smi


wget https://us.download.nvidia.com/tesla/515.105.01/NVIDIA-Linux-x86_64-515.105.01.run

wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda-repo-rhel7-11-7-local-11.7.1_515.65.01-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-11-7-local-11.7.1_515.65.01-1.x86_64.rpm
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms
sudo yum -y install cuda

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda-repo-ubuntu2204-11-7-local_11.7.1-515.65.01-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-11-7-local_11.7.1-515.65.01-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

举报

相关推荐

0 条评论