ChatGLM3-6B大模型windows部署

概述

ChatGLM3 是由智谱AI和清华大学 KEG 实验室联合发布的新一代对话预训练模型。ChatGLM3-6B 是 ChatGLM3 系列中的开源模型,继承了前两代模型对话流畅、部署门槛低等众多优秀特性,并在此基础上进行了全面的性能提升和创新性功能扩展。

系统要求

操作系统:Windows、Linux 或 macOS。本教程使用Windows进行安装。
python 版本推荐3.10.12
transformers 库版本推荐为 4.30.2
torch 推荐使用 2.0 及以上的版本,以获得最佳的推理性能
CUDA:如果你打算在 GPU 上运行模型,需要安装 CUDA(仅限 Windows 和 Linux)

部署

部署gpu驱动

#下载rtx4060驱动
https://www.nvidia.cn/drivers/lookup/ 

步骤 1:创建虚拟环境

打开终端cmd,安装并创建一个新的 Anaconda 环境。这将有助于隔离项目依赖项。
Anaconda 下载地址:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2022.10-Windows-x86_64.exe
下载安装过程可以参考此文:https://blog.csdn.net/Q_fairy/article/details/129158178
执行命令:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
conda create -n py3.10 python=3.10
conda  activate py3.10

步骤 2:安装依赖项

安装NVIDIA驱动以及CUDA Toolkit 11.8,地址如下:
https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Linux。选择对应的安装包进行下载并安装

image.png

安装PyTorch,到此地址
https://pytorch.org/get-started/locally/并根据本机硬件选择的版本,如下图所示:
image.png

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

#确认安装成功
(py3.10) F:\>python
Python 3.10.16 | packaged by Anaconda, Inc. | (main, Dec 11 2024, 16:19:12) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.2.1+cpu
>>> torch.cuda.is_available()
True

步骤 3:下载 ChatGLM3-6B 模型

git clone https://github.com/THUDM/ChatGLM3
cd ChatGLM3

步骤 4:安装模型依赖项

pip install -r requirements.txt

步骤 5:下载模型文件

mkdir THUDM
cd THUDM
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git

步骤 6:运行模型

  • 命令界面
python basic_demo/cli_demo.py
pip install streamlit
streamlit run basic_demo\web_demo_streamlit.py

在浏览器中打开 http://localhost:8501 来访问 Streamlit 界面。

  • REST API
python openai_api_demo\api_server.py

注意:国内不能访问https://huggingface.co/,因此需要修改文件:

D:\Program Files\anaconda3\envs\py3.10\Lib\site-packages\huggingface_hub\constants.py
#HUGGINGFACE_CO_URL_HOME = "https://huggingface.co/"
HUGGINGFACE_CO_URL_HOME = "https://hf-mirror.com"
#_HF_DEFAULT_ENDPOINT = "https://huggingface.co"
_HF_DEFAULT_ENDPOINT = "https://hf-mirror.com"

设置github代理

git config --global http.proxy http://127.0.0.1:7777
git config --global https.proxy http://127.0.0.1:7777

取消github代理

git config --global --unset http.proxy  
git config --global --unset https.proxy  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容