当前位置:   article > 正文

DB-GPT部署验证

DB-GPT部署验证

一、DB-GPT简介

        DB-GPT是一个开源的数据库领域大模型框架。目的是构建大模型领域的基础设施,通过开发多模型管理、Text2SQL效果优化、RAG框架以及优化、Multi-Agents框架协作等多种技术能力,让围绕数据库构建大模型应用更简单,更方便。

        GITHUB源码地址:GitHub - eosphoros-ai/DB-GPT: Revolutionizing Database Interactions with Private LLM TechnologyRevolutionizing Database Interactions with Private LLM Technology - GitHub - eosphoros-ai/DB-GPT: Revolutionizing Database Interactions with Private LLM Technologyicon-default.png?t=N7T8https://github.com/eosphoros-ai/DB-GPT.git

1、名词术语

名词

说明

DB-GPT

DataBase Generative Pre-trained Transformer,一个围绕数据库与大模型的开源框架

Text2SQL/NL2SQL

Text to SQL,利用大语言模型能力,根据自然语言生成SQL语句,或者根据SQL语句给出解释说明

KBQA

Knowledge-Based Q&A 基于知识库的问答系统

GBI

Generative Business Intelligence 生成式商业智能,基于大模型与数据分析,通过对话方式提供商业智能分析与决策

LLMOps

大语言模型操作框架,提供标准的端到端工作流程,用于训练、调整、部署和监控LLM,以加速生成AI模型的应用程序部署

Embedding

将文本、音频、视频等资料转换为向量的方法

RAG

Retrieval-Augmented Generation 检索能力增强

2、系统架构

Model Controller:

Model Worker:

Web Server:

API Server:

3、环境要求

二、源码部署

1、环境要求

启动模式

CPU * MEM

GPU

备注

代理模型

4C*8G

代理模型不依赖GPU

本地模型

8C*32G

24G

本地启动最好有24G以上GPU

2、源码下载

        可以在Github上下载最新版本:https://github.com/eosphoros-ai/DB-GPT/releases

wget https://github.com/eosphoros-ai/DB-GPT/archive/refs/tags/v0.4.3.tar.gz

3、Miniconda安装

        Miniconda 是一个 Anaconda 的轻量级替代,默认只包含了 python 和 conda,但是可以通过 pip 和 conda 来安装所需要的包。

        Miniconda 安装包可以到清华站下载:Index of /anaconda/miniconda/ | 清华大学开源软件镜像站 | Tsinghua Open Source MirrorIndex of /anaconda/miniconda/ | 清华大学开源软件镜像站,致力于为国内和校内用户提供高质量的开源软件镜像、Linux 镜像源服务,帮助用户更方便地获取开源软件。本镜像站由清华大学 TUNA 协会负责运行维护。icon-default.png?t=N7T8https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/

        也可以在miniconda官网下载最新安装包:Miniconda — miniconda documentation

  1. mkdir -p ~/miniconda3
  2. wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
  3. bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
  4. rm -rf ~/miniconda3/miniconda.sh
  5. ~/miniconda3/bin/conda init bash
  6. source ~/.bashrc

 4、配置国内conda源

        各系统都可以通过修改用户目录下的 .condarc 文件来使用清华镜像源        

conda config --set show_channel_urls yes

        修改~/.condarc的配置文件

  1. channels:
  2. - defaults
  3. show_channel_urls: true
  4. default_channels:
  5. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  6. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  7. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
  8. custom_channels:
  9. conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  10. msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  11. bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  12. menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  13. pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  14. pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  15. simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  16. deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

         清华源帮助文档地址:anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirroranaconda 使用帮助 | 镜像站使用帮助 | 清华大学开源软件镜像站,致力于为国内和校内用户提供高质量的开源软件镜像、Linux 镜像源服务,帮助用户更方便地获取开源软件。本镜像站由清华大学 TUNA 协会负责运行维护。icon-default.png?t=N7T8https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/        也可以选择其他国内源

  1. # 中科大镜像源
  2. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  3. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
  4. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  5. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
  6. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
  7. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
  8. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/
  9.  
  10. # 阿里镜像源
  11. conda config --add channels https://mirrors.aliyun.com/pypi/simple/
  12.  
  13. # 豆瓣的python的源
  14. conda config --add channels http://pypi.douban.com/simple/ 
  15.  
  16. # 显示检索路径,每次安装包时会将包源路径显示出来
  17. conda config --set show_channel_urls yes
  18. conda config --set always_yes True
  19. conda config --set auto_activate_base False
  20.  
  21. #执行以下命令清除索引缓存,保证用的是镜像站提供的索引
  22. conda clean -i
  23.  
  24. # 显示所有镜像通道路径命令
  25. conda config --show channels

5、创建Python环境

        因为编译源码需要python >= 3.10,所以使用conda创建python环境

  1. conda create -n dbgpt_env python=3.10
  2. conda activate dbgpt_env

6、配置国内pip源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

        或修改pip配置文件,如 vi /root/.config/pip/pip.conf

  1. [global]
  2. index-url = https://pypi.tuna.tsinghua.edu.cn/simple

        其他国内源:

        阿里云:https://mirrors.aliyun.com/pypi/simple/

7、编译源码

  1. tar -zxf v0.4.3.tar.gz
  2. cd DB-GPT-0.4.3
  3. pip install -e ".[default]"

         编译时间较长,知道提示编译成功

三、模型部署

        直接是用git下载huggingface.co开源网站的模型文件会使用到git-lfs,需要提前安装。

apt-get install git-lfs

        在DB-GPT目录下创建models目录,用于存放下载的本地模型文件

  1. cd DB-GPT-0.4.3
  2. mkdir models

1、下载embedding model

1.1 text2vec-large-chinese

git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese

1.2 m3e-large

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

2、下载llm model

2.1 Vicuna

2.1.1 硬件需求说明
ModelQuantizeVRAM Size
Vicuna-7b-1.54-bit8GB
Vicuna-7b-1.58-bit12GB
vicuna-13b-v1.54-bit12GB
vicuna-13b-v1.58-bit24GB
2.1.2 下载地址
git clone https://huggingface.co/lmsys/vicuna-13b-v1.5
2.1.3 环境变量配置

        在 .env 文件中配置LLM_MODEL参数

LLM_MODEL=vicuna-13b-v1.5

2.2 ChatGLM2

 2.1.1 硬件需求说明
ModelQuantizeVRAM Size
ChatGLM-6b4-bit7GB
ChatGLM-6b8-bit9GB
ChatGLM-6bFP1614GB
2.1.2 下载地址
git clone https://huggingface.co/THUDM/chatglm2-6b
2.1.3 环境变量配置

        在 .env 文件中配置LLM_MODEL参数

LLM_MODEL=chatglm2-6b

2.3 llama.cpp(CPU运行)

2.3.1 直接下载

        下载已经转换好的文件TheBloke/vicuna-13B-v1.5-GGUF,将模型重命名为: ggml-model-q4_0.gguf,存放在models目录

git clone https://huggingface.co/TheBloke/vicuna-13B-v1.5-GGUF
 2.3.2 手工转换

        自行转换模型文件,将模型重命名为: ggml-model-q4_0.gguf,存放在models目录

  1. # obtain the original LLaMA model weights and place them in ./models
  2. ls ./models
  3. 65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model
  4. # [Optional] for models using BPE tokenizers
  5. ls ./models
  6. 65B 30B 13B 7B vocab.json
  7. # install Python dependencies
  8. python3 -m pip install -r requirements.txt
  9. # convert the 7B model to ggml FP16 format
  10. python3 convert.py models/7B/
  11. # [Optional] for models using BPE tokenizers
  12. python convert.py models/7B/ --vocabtype bpe
  13. # quantize the model to 4-bits (using q4_0 method)
  14. ./quantize ./models/7B/ggml-model-f16.gguf ./models/7B/ggml-model-q4_0.gguf q4_0
  15. # update the gguf filetype to current if older version is unsupported by another application
  16. ./quantize ./models/7B/ggml-model-q4_0.gguf ./models/7B/ggml-model-q4_0-v2.gguf COPY
  17. # run the inference
  18. ./main -m ./models/7B/ggml-model-q4_0.gguf -n 128
2.3.3 安装依赖

        llama.cpp在DB-GPT中是可选安装项, 你可以通过以下命令进行安装

pip install -e ".[llama_cpp]"
2.3.4 环境变量修改

        修改.env文件使用llama.cpp

  1. LLM_MODEL=llama-cpp
  2. llama_cpp_prompt_template=vicuna_v1.1

四、数据库部署

1、安装Mysql

  1. # 更新apt源
  2. apt update
  3. #下载mysql-server
  4. apt install mysql-server
  5. #查看mysql的状态,开启mysql
  6. service mysql status
  7. service mysql start
  8. #进入mysql终端
  9. mysql
  10. #设置root密码,注意这里的密码应该和DB-GPT中的.env文件保持一致
  11. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Mysql2023';
  12. #登录mysql,这里会提示输入密码,可以查看自己密码创建是否正确
  13. mysql -u root -p

2、数据库配置

        修改.env文件中数据库的配置

  1. #*******************************************************************#
  2. #**                  DB-GPT METADATA DATABASE SETTINGS            **#
  3. #*******************************************************************#
  4. ### SQLite database (Current default database)
  5. #LOCAL_DB_TYPE=sqlite
  6. ### MYSQL database
  7. LOCAL_DB_TYPE=mysql
  8. LOCAL_DB_USER=root
  9. LOCAL_DB_PASSWORD={your_password}
  10. LOCAL_DB_HOST=127.0.0.1
  11. LOCAL_DB_PORT=3306
  12. LOCAL_DB_NAME=dbgpt

3、测试数据

bash ./scripts/examples/load_examples.sh

五、运行服务

1、整体启动

        通过命令一键启动整个DB-GPT服务

python dbgpt/app/dbgpt_server.py

2、分服务启动

2.1 启动Model Controller

        Model Server默认端口为8000

dbgpt start controller

        启动成功如下: 

2.2 启动Model Worker

2.2.1 启动chatglm2-6b模型Worker
  1. dbgpt start worker --model_name chatglm2-6b \
  2. --model_path /DB-GPT-0.4.3/models/chatglm2-6b \
  3. --port 8001 \
  4. --controller_addr http://127.0.0.1:8000

  如果报错 'ChatGLMTokenizer' object has no attribute 'tokenizer',则需要降级transformers,存在问题的版本为4.36.0,改为4.33.3

  1. pip uninstall transformers
  2. pip install transformers==4.33.3
2.2.2 启动vicuna-13b-v1.5模型Worker
  1. dbgpt start worker --model_name vicuna-13b-v1.5 \
  2. --model_path /DB-GPT-0.4.3/models/vicuna-13b-v1.5 \
  3. --port 8002 \
  4. --controller_addr http://127.0.0.1:8000

2.3 启动Embedding模型服务

  1. dbgpt start worker --model_name text2vec \
  2. --model_path /DB-GPT-0.4.3/models/text2vec-large-chinese \
  3. --worker_type text2vec \
  4. --port 8003 \
  5. --controller_addr http://127.0.0.1:8000

2.4 查看并检查已部署模型

dbgpt model list

        显示当前运行的模型信息如下

2.5 启动Web Server服务

        --light 表示不启动嵌入式模型服务,嵌入式模型服务默认为

dbgpt start webserver --light

2.6 浏览页面

        使用浏览器访问页面http://localhost:5000/

2.7 查看显存使用

nvidia-smi

        显示显卡使用信息如下:

         

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

闽ICP备14008679号