首页 > 其他分享 >本地部署 Langchain-Chatchat & ChatGLM

本地部署 Langchain-Chatchat & ChatGLM

时间:2024-03-17 12:12:00浏览次数:21  
标签:cn ChatGLM Langchain Chatchat conda https edu

 

一、模型&环境介绍#

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
  • 然后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
  • 安装好显卡驱动, 安装 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 页面

三、自定义知识库#

。。。

作者: 七夜i

出处:https://www.cnblogs.com/qiyer/p/17730888.html

本站使用「cc by 4.0」创作共享协议,转载请在文章明显位置注明作者及出处。

标签:cn,ChatGLM,Langchain,Chatchat,conda,https,edu
From: https://www.cnblogs.com/gongzb/p/18078406

相关文章

  • langchain Chatchat windows11 CPU部署记录
    1、下载langchainChatchatgitclonehttps://github.com/chatchat-space/Langchain-Chatchat.git(可选)如果下载不下来,可能使用了代理,需要设置代理地址:gitconfig--globalhttp.proxy"localhost:你的代理端口"之后可以取消代理设置:gitconfig--global--unsethttp.proxy2......
  • LLM大语言模型(七):部署ChatGLM3-6B并提供HTTP server能力
    目录HighLight部署ChatGLM3-6B并开启HTTPserver能力下载embedding模型bge-large-zh-v1.5HTTP接口问答示例LLM讲了个尴尬的笑话~HighLight将LLM服务化(如提供HTTPserver能力),才能在其上构建自己的应用。部署ChatGLM3-6B并开启HTTPserver能力下载embedding模型bge-l......
  • 聊聊ChatGLM-6B医疗数据微调
    转载请注明出处:https://www.cnblogs.com/zhiyong-ITNote/参考了多个医疗大模型,如扁鹊、灵心等,重新思考了下微调的方案以及数据集的格式;基于ChatGLM/其它LLM整合多种微调方法的非官方实现的框架,审视其数据集格式,以及调试效果,进行微调。最终基于liucongg/ChatGLM-Finetuning开......
  • 从API到Agent:万字长文洞悉LangChain工程化设计
    我想做一个尝试,看看能不能用尽量清晰的逻辑,给“AI外行人士”(当然,我也是……)引入一下LangChain,试着从工程角度去理解LangChain的设计和使用。同时大家也可以将此文档作为LangChain的“10分钟快速上手”手册,本意是希望帮助需要的同学实现AI工程的Bootstrap。文中所有的示例代码都......
  • Langchain-Chatchat开源库使用的随笔记(一)
    转自:https://zhuanlan.zhihu.com/p/6760612691Chatchat项目结构整个结构是server 启动API,然后项目内自行调用API。API详情可见:http://xxx:7861/docs ,整个代码架构还是蛮适合深入学习 在这里插入图片描述 2Chatchat一些代码学习2.112个分块函数统一使用截止2023......
  • Langchain-ChatGLM源码解读(一)-文档数据上传
    一、简介Langchain-ChatGLM 相信大家都不陌生,近几周计划出一个源码解读,先解锁langchain的一些基础用法。文档问答过程大概分为以下5部分,在Langchain中都有体现。上传解析文档文档向量化、存储文档召回query向量化文档问答今天主要讲langchain在上传解析文档时是怎么实......
  • Langchain-ChatGLM源码解读(二)-文档embedding以及构建faiss过程
    一、简介Langchain-ChatGLM 相信大家都不陌生,近几周计划出一个源码解读,先解锁langchain的一些基础用法。文档问答过程大概分为以下5部分,在Langchain中都有体现。上传解析文档文档向量化、存储文档召回query向量化文档问答今天主要讲langchain在文档embedding以及构建fa......
  • 容器集群实现多机多卡分布式微调大模型chatglm2-6b(deepseed + LLaMA + NCCL)
    环境信息2台物理机(187.135,187.136),各两张p4显卡,安装好docker=20.10.0,安装好nvidia驱动(driverversion=470.223.02,cudaversion=11.4)构造容器集群(dockerswarm187.136节点作为manager节点,187.135节点作为worker节点)[root@host-136~]#dockerswarminit--advertise-addr......
  • 线上跑chatGLM实践
    预先准备本笔记为参加DataWhale的线上学习——进行GLM、SD部署在完成驱动云平台注册后,免费获得168算力金,使用免费算力金进行ai平台部署在平台内进行部署https://platform.virtaicloud.com/项目服务器配置创建项目后,选择添加镜像在此选择PyTorch2.0.1Conda3.9的镜像通过......
  • ChatGLM3本机部署
    环境配置参照官方说明,创建虚拟python环境,并安装所需部署包。说明https://github.com/THUDM/ChatGLM3/blob/main/composite_demo/README.md本地模型加载1、先按照官方指引,将模型下载在本地。2、修改模型加载地址。MODEL_PATH和TOKENIZER_PATH,都修改注意:通过修改client.py......