Win11 部署 Langchain-Chatchat

发布时间 2023-11-14 13:38:54作者: sun8134

LangChain-Chatchat (原 Langchain-ChatGLM)

基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。

项目地址:https://github.com/chatchat-space/Langchain-Chatchat


部署还是比较简单的,照着文档一步一步来就行

先看下 python 版本,最好 3.10:https://www.python.org/download/releases/

python --version

image



然后拉取仓库,安装依赖

# 拉取仓库 git clone https://github.com/chatchat-space/Langchain-Chatchat.git # 进入目录 cd Langchain-Chatchat # 安装全部依赖 pip install -r requirements.txt

我 webui 和 api 都安装,可以按需安装的

#安装API

pip install -r requirements_api.txt


#安装webui

pip install -r requirements_webui.txt


下面需要下载模型,受限需要装下 Git LFS:https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage

git lfs install


模型一般从 HuggingFace 下载:   https://huggingface.co/models

不过由于某些原因可能无法访问,我们可以从镜像站点下载:https://hf-mirror.com/models

下载模型:

git clone https://hf-mirror.com/THUDM/chatglm2-6b git clone https://hf-mirror.com/moka-ai/m3e-base

下面复制下默认的配置文件

python copy_config_example.py


初始化知识库

python init_database.py --recreate-vs


然后启动

python startup.py -a

顺利的话可以看到当前配置:

image


浏览器打开web界面:

image


API也顺利运行:

image


仍本水浒传进去,看看效果:

image


貌似还行,主要是 cpu 的话实在太慢…

看下我们的 pytorch 是否支持使用 GPU

python
import torch
torch.__version__
print(torch.cuda.is_available())

image

False 说明当前 pytorch 不支持 cuda


要用 gpu,需要装 cuda,然后装支持 cuda 的 pytorch

先下载 cuda toolkit :https://developer.nvidia.com/cuda-toolkit-archive

目前 pytorch 用的比较多的是 11.8 和 12.1

安装完成后,运行查看下 cuda 版本

nvcc –V

image


然后上 https://pytorch.org/ ,安装支持 cuda 的 pytorch

image


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


但我们已经装过 pytorch 的话,这样不一定能装上…

需要上 https://download.pytorch.org/whl/torch_stable.html

找到需要的版本,本地安装,

像CPU版本的,支持 python3.10 的,win版的是这个:

image


支持 cuda 12.1,python3.10 的,win版的是这个:

image


下载到本地,安装:

pip install g:/AI/torch-2.1.0+cu121-cp310-cp310-win_amd64.whl


安装完成后再看下是否支持 cuda:

python
import torch
torch.__version__
print(torch.cuda.is_available())

image


现在再启动 Langchain-Chatchat,就可以支持 GPU 了

但是我的 8G 显存太小了,使用 chatglm2-6b 的时候会报显存不足无法启动….

image


可以使用量化过的 chatglm2-6b-int4 模型(当然量化过的模型会傻一点…)

先下载模型:

git clone https://hf-mirror.com/THUDM/chatglm2-6b-int4


然后修改 model_config.py,修改 LLM 模型名称(注意上面 MODEL_PATH 的 llm_model 里指定了 chatglm2-6b-int4 模型的路径,需要的话可以自己修改模型路径)

image


然后运行

python startup.py -a


可以看到我们已经是 cuda 的版本了

image


随便试试…

速度比 cpu 快了很多…

原来 智多星 是 李逵…

image