centos7.6 搭建langchain-ChatGLM2-6B 超简易过程

发布时间 2023-07-11 15:53:03作者: Hi,虫

刚接触这个大模型项目的时候,在两台笔记本上搞来搞去,花费3、4天时间,最后由于配置太低,没能跑得起来,无奈直接到阿里云买的服务器,装了一下午大概6、7个小时,中间遇到很多环境包的问题,无非是些gcc、python、ssl等。后来在社区群里学到conda,使用conda创建和管理虚拟环境,比较方便建立隔离的python上下文空间,晚上就又买了台机器从零开始搭建,使用conda,结果异常顺利,一个多小时搞定,主要时间还花费在了上传chatglm2-6b模型(11GB左右)上,记录一下大概步骤;

1、安装miniconda,创建虚拟环境

  conda create -n langchain-chatglm python=3.10
  conda activate langchain-chatglm

2、安装torch,因为买的是GPU服务器,所以安装的torch一定是支持GPU版的,虽然CPU也能跑,只要内存足够大,但是真的是巨慢,所以建议有条件还是用GPU。在torch官网上可以选择环境和版本,拿到一个安装命令,直接执行即可。
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

3、安装其他依赖
pip install -r requirements.txt

4、上传chatglm2-6b和text2vec-large-chinese的模型到服务器,并配置config/model_config.py文件中的模型路径。
我是提前下好到本地了,怎么下载模型去看看github官方文档,写得很详细。主要改两处,一处是chatglm2-6b的本地路径,一个是要加载的模型名称,改为chatglm2-6b即可。

embedding_model_dict = {
    "ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
    "ernie-base": "nghuyong/ernie-3.0-base-zh",
    "text2vec-base": "shibing624/text2vec-base-chinese",
    "text2vec": "/opt/llm/models/text2vec-large-chinese",
    "m3e-small": "moka-ai/m3e-small",
    "m3e-base": "moka-ai/m3e-base",
}
......
# Embedding model name
EMBEDDING_MODEL = "text2vec"
    "chatglm2-6b": {
        "name": "chatglm2-6b",
        "pretrained_model_name": "THUDM/chatglm2-6b",
        "local_model_path": "/opt/llm/models/chatglm2-6b",
        "provides": "ChatGLM"
    },
......
# LLM 名称
LLM_MODEL = "chatglm2-6b"

5、到langchain-ChatGLM下启动服务即可。
python webui.py