当前位置:   article > 正文

本地部署 Langchain-Chatchat & ChatGLM_langchain-chatchat github

langchain-chatchat github

一、模型&环境介绍

1. ChatGLM
2. m3e
3. text2vec
4. Langchain-Chatchat
5. Python (建议Python 版本 3.8.1 - 3.10)
6. torch
7. conda

二、安装

作者本人电脑环境是:
  • Windows 10
  • Intel 处理器
  • N卡 3060Ti 12G
1. 建议先安装 conda (也可以不使用 conda )

https://blog.csdn.net/sonapingo/article/details/130900170
https://blog.csdn.net/qq_41264055/article/details/132092447

2. 安装后为 conda 设置清华源
  • 长期切换通道,推荐生成.condarc文件后手动编辑文件内容,而不是通过命令行一个一个添加channel
  • .condarc文件默认不生成,运行一下命令就可以在用户目录下生成:conda config –set show_channel_urls yes
  • 在.condarc文件中复制以下内容(找不到该文件的可以conda info看看"user config file"的路径)
Copy
# This is a sample .condarc file.
# It adds mirror-channel(Tsinghua University) of anaconda and enables
# the show_channel_urls option.

# channel locations. These override conda defaults, i.e., conda will
# search *only* the channels listed here, in the order given.
# Use "defaults" to automatically include all default channels.
# Non-url channels will be interpreted as Anaconda.org usernames
# (this can be changed by modifying the channel_alias key; see below).
# The default is just 'defaults'.
channels:
  - defaults
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

# Show channel URLs when displaying what is going to be downloaded
# and in 'conda list'. The default is False.
show_channel_urls: true

# For more information about this file see:
# https://conda.io/docs/user-guide/configuration/use-condarc.html
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 然后conda clean -i 清除索引缓存
3. git 和 git lfs 安装
  • 确保机器安装了 git 环境:https://git-scm.com/
  • 因为模型过大,需要安装 lfs 支持: git lfs install
4. 下载 ChatGLM2-6B 模型到本地,要根据自己的显卡显存下载合适的模型,比如作者本人需要下载 chatglm2-6b-32k-int4 或 int8(若显存小于13G)

git clone https://huggingface.co/THUDM/chatglm2-6b-32k /your_path/chatglm2-6b

注意:由于模型较大,下载经常会失败,需要根据 git 提示,重试多次。

5. 下载 m3e 或 text2vec 模型到本地

git clone https://huggingface.co/moka-ai/m3e-base /your_path/m3e

6. 下载并配置 Langchain-Chatchat
  • 下载 Langchain-Chatchat 到本地:https://github.com/chatchat-space/Langchain-Chatchat/tags ,建议下载稳定 tag 版本,要不然一堆坑。
  • git clone 或是下载 zip 解压到本地
  • cd 到 Langchain-Chatchat 目录下,使用清华源安装:pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 默认安装的 torch 是 cpu 版本,我们需要安装 gpu 版本,否则模型在你 cpu 上跑,卡死。
    可以通过 pip list 查看 torch 的安装版本,或者在 python 环境通过以下命令判断:
Copy
import torch
print(torch.__version__)  # 2.0.1+cu117 ,带 +cu117 类似格式的,表示装的 gpu 版本 ,不带这种格式的默认是 cpu 版本
print(torch.cuda.is_available())  # True  表示支持 gpu ,False 的话将使用 cpu
  • 1
  • 2
  • 3
  • 4
  • 安装好显卡驱动, 安装 cuda 支持
  • 由于网络的关系,建议去 https://pytorch.org/ 官网下载 gpu 版本的 torch .whl,然后本地使用 pip install
    安装好通过上述的两种方式检查 torch 是否支持 gpu
  • 上述步骤搞定好,开始 Langchain-Chatchat 的配置,详细参数配置可参考 Langchain-Chatchat 官方的 wiki
    a. 将chatglm 和 m3e 配置到 model_config.py
    b. 修改 server_config.py 配置
  • 在 Langchain-Chatchat 目录下,调用命令初始化本地数据库:python init_database.py --recreate-vs
  • 使用 python startup.py --all-webui 启动 web ui 页面

如何系统的去学习AI大模型LLM ?

作为一名热心肠的互联网老兵,我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在人工智能学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。

但苦于知识传播途径有限,很多互联网行业朋友无法获得正确的资料得到学习提升,故此将并将重要的 AI大模型资料 包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来

所有资料 ⚡️ ,朋友们如果有需要全套 《LLM大模型入门+进阶学习资源包》,扫码获取~

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/896170
推荐阅读
相关标签