大模型部署手记(1)ChatGLM2+Windows GPU

1.简介:

组织机构:智谱/清华

代码仓:https://github.com/THUDM/ChatGLM2-6B

模型:THUDM/chatglm2-6b

下载:https://huggingface.co/THUDM/chatglm2-6b

镜像下载:https://aliendao.cn/models/THUDM/chatglm2-6b

硬件环境:暗影精灵7Plus

Windows版本:Windows 11家庭中文版 Insider Preview 22H2

内存 32G

GPU显卡:Nvidia GTX 3080 Laptop (16G)

大模型部署手记(1)ChatGLM2+Windows GPU_第1张图片

torch推荐使用 2.0 及以上的版本,以获得最佳的推理性能 :

大模型部署手记(1)ChatGLM2+Windows GPU_第2张图片

nvidia-smi

大模型部署手记(1)ChatGLM2+Windows GPU_第3张图片

CUDA是12.2版本。

nvcc -V

大模型部署手记(1)ChatGLM2+Windows GPU_第4张图片

nvcc显示CUDA 11.6版本。

查看Nvidia控制面板:

大模型部署手记(1)ChatGLM2+Windows GPU_第5张图片

2.代码和模型下载:

下载代码仓:

git clone https://github.com/THUDM/ChatGLM2-6B

大模型部署手记(1)ChatGLM2+Windows GPU_第6张图片

浏览器打开 https://huggingface.co/THUDMM/chatglm2-6b/tree/main,选择 Files and versions,将所有文件都下载下来:

大模型部署手记(1)ChatGLM2+Windows GPU_第7张图片

大模型部署手记(1)ChatGLM2+Windows GPU_第8张图片

或者换这个地址:

https://cloud.tsinghua.edu.cn/d/674208019e314311ab5c/?p=%2Fchatglm2-6b&mode=list

大模型部署手记(1)ChatGLM2+Windows GPU_第9张图片

或者换这个地址:

https://aliendao.cn/models/THUDM/chatglm2-6b

大模型部署手记(1)ChatGLM2+Windows GPU_第10张图片

可以切换到Linux,执行以下命令,从镜像下载模型:

cd /home1/zhanghui/aliendao

python3 model_download.py --mirror --repo_id THUDM/chatglm2-6b

大模型部署手记(1)ChatGLM2+Windows GPU_第11张图片

实验表明镜像站下载大的模型文件大概率还是会出现下载卡住的情形。

将下载好的文件移动到 /home1/zhanghui/ChatGLM2-6B/THUDM/chatglm2-6b 目录下(gitattributes文件可以改名为 .gitattributes)

大模型部署手记(1)ChatGLM2+Windows GPU_第12张图片

将前面从Linux上下载好的ChatGLM2-6b的模型文件传到 D:\ChatGLM2-6B 目录下:

大模型部署手记(1)ChatGLM2+Windows GPU_第13张图片

3.安装依赖

进入Anaconda提示符界面:

conda create -n torch2.0 python=3.8

大模型部署手记(1)ChatGLM2+Windows GPU_第14张图片

conda activate torch2.0

d:

cd ChatGLM2-6B

安装pip依赖:

pip install -r requirements.txt

大模型部署手记(1)ChatGLM2+Windows GPU_第15张图片

大模型部署手记(1)ChatGLM2+Windows GPU_第16张图片

4.部署验证

启动:

python web_demo.py

大模型部署手记(1)ChatGLM2+Windows GPU_第17张图片

修改 web_demo.py,将模型路径改为文件路径:

大模型部署手记(1)ChatGLM2+Windows GPU_第18张图片

重试:

python web_demo.py

大模型部署手记(1)ChatGLM2+Windows GPU_第19张图片

查看 https://betheme.net/qianduan/121637.html

降级一下transformers试试:

pip install transformers==4.26.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

大模型部署手记(1)ChatGLM2+Windows GPU_第20张图片

重试:

python web_demo.py

大模型部署手记(1)ChatGLM2+Windows GPU_第21张图片

这个torch安装的是一个非GPU的版本啊。

参考:https://pytorch.org/get-started/locally/

大模型部署手记(1)ChatGLM2+Windows GPU_第22张图片

安装GPU版本的pytorch:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

大模型部署手记(1)ChatGLM2+Windows GPU_第23张图片

重试:

python web_demo.py

大模型部署手记(1)ChatGLM2+Windows GPU_第24张图片

错误还是一样的。

换种方法,使用conda方式安装pytorch 2.0.1 for CUDA 11.8版本:

大模型部署手记(1)ChatGLM2+Windows GPU_第25张图片

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

大模型部署手记(1)ChatGLM2+Windows GPU_第26张图片

大模型部署手记(1)ChatGLM2+Windows GPU_第27张图片

大模型部署手记(1)ChatGLM2+Windows GPU_第28张图片

安装的是pytorch2.0.1+torchvision 0.15.2

大模型部署手记(1)ChatGLM2+Windows GPU_第29张图片

大模型部署手记(1)ChatGLM2+Windows GPU_第30张图片

重试:

python web_demo.py

大模型部署手记(1)ChatGLM2+Windows GPU_第31张图片

pip install chardet

重试:

python web_demo.py

终于启动起来了。

浏览器打开 http://127.0.0.1:7860

大模型部署手记(1)ChatGLM2+Windows GPU_第32张图片

感觉有点奇怪,回答怎么没有呢?

换成streamlit方式启动试试吧:

streamlit run web_demo2.py

大模型部署手记(1)ChatGLM2+Windows GPU_第33张图片

根据提示,使用浏览器打开 http://127.0.0.1:8501/

大模型部署手记(1)ChatGLM2+Windows GPU_第34张图片

问两个问题吧:

大模型部署手记(1)ChatGLM2+Windows GPU_第35张图片

回答的时候,GPU情况如下:

大模型部署手记(1)ChatGLM2+Windows GPU_第36张图片

可以接着问:

大模型部署手记(1)ChatGLM2+Windows GPU_第37张图片

好了,你知道得太多了。该睡觉了。

(全文完,谢谢阅读)

你可能感兴趣的:(大模型,深度学习,llama)