本地部署 ChatGLM-6b

ChatGLM-6B 是一個開源的、支持中英雙語的對話語言模型?;?General Language Model (GLM) 架構(gòu),具有 62 億參數(shù)。結(jié)合模型量化技術(shù),用戶可以在消費級的顯卡上進行本地部署(INT4 量化級別下最低只需 6GB 顯存)。

從零環(huán)境開始配置

1、安裝 python

https://www.python.org/downloads/windows/

2、下載代碼

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

安裝依賴

pip install -r requirements.txt -i https://mirror.sjtu.edu.cn/pypi/web/simple

3、安裝 Pytorch(GPU版)

檢查是否啟用GPU

import torch
print(torch.__version__)   #顯示Pytorch版本
print(torch.cuda.is_available()) #返回False為版本不匹配,報該錯誤;返回Ture,解決問題

3.1 安裝 CUDA

查看 NVIDIA 控制面板 => 系統(tǒng)信息 => 驅(qū)動程序版本 => 511.81

查看 NVIDIA 對應(yīng) CUDA 的版本 地址

下載地址

新建 cmd 命令查看是否安裝成功:nvcc -V,如果沒有還需要配置環(huán)境變量

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin

3.2 下載 cuDNN

需要注冊 NVIDIA 賬號

下載地址

下載完成后解壓里面的文件夾后復(fù)制到對應(yīng)的 CUDA 中:

復(fù)制 /bin 下的文件 到 \CUDA\v11.6\bin

復(fù)制 /lib/x64 下的文件 到 \CUDA\v11.6\lib\x64

復(fù)制 /include 下的文件 到 \CUDA\v11.6\include

3.3 安裝 Pytorch

如果已安裝還需要卸載 pip uninstall torch

pytorch 網(wǎng)站 https://pytorch.org/get-started/locally/#windows-anaconda

然后再運行命令

import torch
print(torch.__version__)   #顯示Pytorch版本
print(torch.cuda.is_available()) #返回False為版本不匹配,報該錯誤;返回Ture,解決問題

4、安裝 TDM-GCC (CPU上運行)

下載地址

安裝 TDM-GCC 時勾選 openmp

5、安裝 Git LFS

Git LFS 用于下載大文件

下載地址

https://git-lfs.com/

6、配置模型

下載模型實現(xiàn) git clone https://huggingface.co/THUDM/chatglm-6b

單獨下載模型 https://cloud.tsinghua.edu.cn/d/674208019e314311ab5c/

可在更目錄下創(chuàng)建 chatglm-6b 或其他模型目錄

然后配置模型目錄:

tokenizer = AutoTokenizer.from_pretrained("chatglm-6b-int4", trust_remote_code=True) # chatglm-6b-int4 為模型目錄
# model = AutoModel.from_pretrained("chatglm-6b", trust_remote_code=True).half().cuda() # 使用GPU
model = AutoModel.from_pretrained("chatglm-6b-int4",trust_remote_code=True).float() # 使用CPU

7、運行

python web_demo.py

1.png

8、參考

https://github.com/THUDM/ChatGLM-6B

https://www.heywhale.com/mw/project/6436d82948f7da1fee2be59e

https://huggingface.co/THUDM

https://blog.csdn.net/moyong1572/article/details/119438286

https://blog.csdn.net/qq_46941656/article/details/119701547

https://blog.csdn.net/sinat_24948419/article/details/105532537

https://zhuanlan.zhihu.com/p/479848495

https://zhuanlan.zhihu.com/p/535100411

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容