柚子快報(bào)邀請(qǐng)碼778899分享:數(shù)據(jù)庫(kù) DB-GPT部署驗(yàn)證
柚子快報(bào)邀請(qǐng)碼778899分享:數(shù)據(jù)庫(kù) DB-GPT部署驗(yàn)證
一、DB-GPT簡(jiǎn)介
????????DB-GPT是一個(gè)開(kāi)源的數(shù)據(jù)庫(kù)領(lǐng)域大模型框架。目的是構(gòu)建大模型領(lǐng)域的基礎(chǔ)設(shè)施,通過(guò)開(kāi)發(fā)多模型管理、Text2SQL效果優(yōu)化、RAG框架以及優(yōu)化、Multi-Agents框架協(xié)作等多種技術(shù)能力,讓圍繞數(shù)據(jù)庫(kù)構(gòu)建大模型應(yīng)用更簡(jiǎn)單,更方便。
????????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 Technologyhttps://github.com/eosphoros-ai/DB-GPT.git
1、名詞術(shù)語(yǔ)
名詞 說(shuō)明 DB-GPT DataBase Generative Pre-trained Transformer,一個(gè)圍繞數(shù)據(jù)庫(kù)與大模型的開(kāi)源框架 Text2SQL/NL2SQL Text to SQL,利用大語(yǔ)言模型能力,根據(jù)自然語(yǔ)言生成SQL語(yǔ)句,或者根據(jù)SQL語(yǔ)句給出解釋說(shuō)明 KBQA Knowledge-Based Q&A 基于知識(shí)庫(kù)的問(wèn)答系統(tǒng) GBI Generative Business Intelligence 生成式商業(yè)智能,基于大模型與數(shù)據(jù)分析,通過(guò)對(duì)話(huà)方式提供商業(yè)智能分析與決策 LLMOps 大語(yǔ)言模型操作框架,提供標(biāo)準(zhǔn)的端到端工作流程,用于訓(xùn)練、調(diào)整、部署和監(jiān)控LLM,以加速生成AI模型的應(yīng)用程序部署 Embedding 將文本、音頻、視頻等資料轉(zhuǎn)換為向量的方法 RAG Retrieval-Augmented Generation 檢索能力增強(qiáng)
2、系統(tǒng)架構(gòu)
Model Controller:
Model Worker:
Web Server:
API Server:
3、環(huán)境要求
二、源碼部署
1、環(huán)境要求
啟動(dòng)模式 CPU * MEM GPU 備注 代理模型 4C*8G 代理模型不依賴(lài)GPU 本地模型 8C*32G 24G 本地啟動(dòng)最好有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 是一個(gè) Anaconda 的輕量級(jí)替代,默認(rèn)只包含了 python 和 conda,但是可以通過(guò) pip 和 conda 來(lái)安裝所需要的包。
????????Miniconda 安裝包可以到清華站下載:Index of /anaconda/miniconda/ | 清華大學(xué)開(kāi)源軟件鏡像站 | Tsinghua Open Source MirrorIndex of /anaconda/miniconda/ | 清華大學(xué)開(kāi)源軟件鏡像站,致力于為國(guó)內(nèi)和校內(nèi)用戶(hù)提供高質(zhì)量的開(kāi)源軟件鏡像、Linux 鏡像源服務(wù),幫助用戶(hù)更方便地獲取開(kāi)源軟件。本鏡像站由清華大學(xué) TUNA 協(xié)會(huì)負(fù)責(zé)運(yùn)行維護(hù)。https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
????????也可以在miniconda官網(wǎng)下載最新安裝包:Miniconda — miniconda documentation
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
source ~/.bashrc
?4、配置國(guó)內(nèi)conda源
????????各系統(tǒng)都可以通過(guò)修改用戶(hù)目錄下的?.condarc?文件來(lái)使用清華鏡像源? ? ? ??
conda config --set show_channel_urls yes
? ? ? ? 修改~/.condarc的配置文件
channels:
- defaults
show_channel_urls: true
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
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
? ? ? ? ?清華源幫助文檔地址:anaconda | 鏡像站使用幫助 | 清華大學(xué)開(kāi)源軟件鏡像站 | Tsinghua Open Source Mirroranaconda 使用幫助 | 鏡像站使用幫助 | 清華大學(xué)開(kāi)源軟件鏡像站,致力于為國(guó)內(nèi)和校內(nèi)用戶(hù)提供高質(zhì)量的開(kāi)源軟件鏡像、Linux 鏡像源服務(wù),幫助用戶(hù)更方便地獲取開(kāi)源軟件。本鏡像站由清華大學(xué) TUNA 協(xié)會(huì)負(fù)責(zé)運(yùn)行維護(hù)。https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/????????也可以選擇其他國(guó)內(nèi)源
# 中科大鏡像源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/
?
# 阿里鏡像源
conda config --add channels https://mirrors.aliyun.com/pypi/simple/
?
# 豆瓣的python的源
conda config --add channels http://pypi.douban.com/simple/?
?
# 顯示檢索路徑,每次安裝包時(shí)會(huì)將包源路徑顯示出來(lái)
conda config --set show_channel_urls yes
conda config --set always_yes True
conda config --set auto_activate_base False
?
#執(zhí)行以下命令清除索引緩存,保證用的是鏡像站提供的索引
conda clean -i
?
# 顯示所有鏡像通道路徑命令
conda config --show channels
5、創(chuàng)建Python環(huán)境
????????因?yàn)榫幾g源碼需要python >= 3.10,所以使用conda創(chuàng)建python環(huán)境
conda create -n dbgpt_env python=3.10
conda activate dbgpt_env
6、配置國(guó)內(nèi)pip源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
? ? ? ? 或修改pip配置文件,如 vi /root/.config/pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
? ? ? ? 其他國(guó)內(nèi)源:
? ? ? ? 阿里云:https://mirrors.aliyun.com/pypi/simple/
7、編譯源碼
tar -zxf v0.4.3.tar.gz
cd DB-GPT-0.4.3
pip install -e ".[default]"
? ? ? ? ?編譯時(shí)間較長(zhǎng),知道提示編譯成功
三、模型部署
? ? ? ? 直接是用git下載huggingface.co開(kāi)源網(wǎng)站的模型文件會(huì)使用到git-lfs,需要提前安裝。
apt-get install git-lfs
? ? ? ? 在DB-GPT目錄下創(chuàng)建models目錄,用于存放下載的本地模型文件
cd DB-GPT-0.4.3
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?硬件需求說(shuō)明
ModelQuantizeVRAM SizeVicuna-7b-1.54-bit8GBVicuna-7b-1.58-bit12GBvicuna-13b-v1.54-bit12GBvicuna-13b-v1.58-bit24GB
2.1.2 下載地址
git clone https://huggingface.co/lmsys/vicuna-13b-v1.5
2.1.3 環(huán)境變量配置
????????在 .env 文件中配置LLM_MODEL參數(shù)
LLM_MODEL=vicuna-13b-v1.5
2.2 ChatGLM2
?2.1.1?硬件需求說(shuō)明
ModelQuantizeVRAM SizeChatGLM-6b4-bit7GBChatGLM-6b8-bit9GBChatGLM-6bFP1614GB
2.1.2 下載地址
git clone https://huggingface.co/THUDM/chatglm2-6b
2.1.3 環(huán)境變量配置
????????在 .env 文件中配置LLM_MODEL參數(shù)
LLM_MODEL=chatglm2-6b
2.3 llama.cpp(CPU運(yùn)行)
2.3.1 直接下載
????????下載已經(jīng)轉(zhuǎn)換好的文件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 手工轉(zhuǎn)換
? ? ? ? 自行轉(zhuǎn)換模型文件,將模型重命名為: ggml-model-q4_0.gguf,存放在models目錄
# obtain the original LLaMA model weights and place them in ./models
ls ./models
65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model
# [Optional] for models using BPE tokenizers
ls ./models
65B 30B 13B 7B vocab.json
# install Python dependencies
python3 -m pip install -r requirements.txt
# convert the 7B model to ggml FP16 format
python3 convert.py models/7B/
# [Optional] for models using BPE tokenizers
python convert.py models/7B/ --vocabtype bpe
# quantize the model to 4-bits (using q4_0 method)
./quantize ./models/7B/ggml-model-f16.gguf ./models/7B/ggml-model-q4_0.gguf q4_0
# update the gguf filetype to current if older version is unsupported by another application
./quantize ./models/7B/ggml-model-q4_0.gguf ./models/7B/ggml-model-q4_0-v2.gguf COPY
# run the inference
./main -m ./models/7B/ggml-model-q4_0.gguf -n 128
2.3.3 安裝依賴(lài)
????????llama.cpp在DB-GPT中是可選安裝項(xiàng), 你可以通過(guò)以下命令進(jìn)行安裝
pip install -e ".[llama_cpp]"
2.3.4 環(huán)境變量修改
????????修改.env文件使用llama.cpp
LLM_MODEL=llama-cpp
llama_cpp_prompt_template=vicuna_v1.1
四、數(shù)據(jù)庫(kù)部署
1、安裝Mysql
# 更新apt源
apt update
#下載mysql-server
apt install mysql-server
#查看mysql的狀態(tài),開(kāi)啟mysql
service mysql status
service mysql start
#進(jìn)入mysql終端
mysql
#設(shè)置root密碼,注意這里的密碼應(yīng)該和DB-GPT中的.env文件保持一致
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Mysql2023';
#登錄mysql,這里會(huì)提示輸入密碼,可以查看自己密碼創(chuàng)建是否正確
mysql -u root -p
2、數(shù)據(jù)庫(kù)配置
? ? ? ? 修改.env文件中數(shù)據(jù)庫(kù)的配置
#*******************************************************************#
#** ? ? ? ? ? ? ? ? ?DB-GPT METADATA DATABASE SETTINGS ? ? ? ? ? ?**#
#*******************************************************************#
### SQLite database (Current default database)
#LOCAL_DB_TYPE=sqlite
### MYSQL database
LOCAL_DB_TYPE=mysql
LOCAL_DB_USER=root
LOCAL_DB_PASSWORD={your_password}
LOCAL_DB_HOST=127.0.0.1
LOCAL_DB_PORT=3306
LOCAL_DB_NAME=dbgpt
3、測(cè)試數(shù)據(jù)
bash ./scripts/examples/load_examples.sh
五、運(yùn)行服務(wù)
1、整體啟動(dòng)
? ? ? ? 通過(guò)命令一鍵啟動(dòng)整個(gè)DB-GPT服務(wù)
python dbgpt/app/dbgpt_server.py
2、分服務(wù)啟動(dòng)
2.1 啟動(dòng)Model Controller
? ? ? ? Model Server默認(rèn)端口為8000
dbgpt start controller
? ? ? ? 啟動(dòng)成功如下:?
2.2?啟動(dòng)Model Worker
2.2.1?啟動(dòng)chatglm2-6b模型Worker
dbgpt start worker --model_name chatglm2-6b \
--model_path /DB-GPT-0.4.3/models/chatglm2-6b \
--port 8001 \
--controller_addr http://127.0.0.1:8000
? 如果報(bào)錯(cuò)?'ChatGLMTokenizer' object has no attribute 'tokenizer',則需要降級(jí)transformers,存在問(wèn)題的版本為4.36.0,改為4.33.3
pip uninstall transformers
pip install transformers==4.33.3
2.2.2?啟動(dòng)vicuna-13b-v1.5模型Worker
dbgpt start worker --model_name vicuna-13b-v1.5 \
--model_path /DB-GPT-0.4.3/models/vicuna-13b-v1.5 \
--port 8002 \
--controller_addr http://127.0.0.1:8000
2.3 啟動(dòng)Embedding模型服務(wù)
dbgpt start worker --model_name text2vec \
--model_path /DB-GPT-0.4.3/models/text2vec-large-chinese \
--worker_type text2vec \
--port 8003 \
--controller_addr http://127.0.0.1:8000
2.4 查看并檢查已部署模型
dbgpt model list
????????顯示當(dāng)前運(yùn)行的模型信息如下
2.5?啟動(dòng)Web Server服務(wù)
????????--light 表示不啟動(dòng)嵌入式模型服務(wù),嵌入式模型服務(wù)默認(rèn)為
dbgpt start webserver --light
2.6?瀏覽頁(yè)面
? ? ? ? 使用瀏覽器訪(fǎng)問(wèn)頁(yè)面http://localhost:5000/
2.7?查看顯存使用
nvidia-smi
? ? ? ? 顯示顯卡使用信息如下:
?????????
柚子快報(bào)邀請(qǐng)碼778899分享:數(shù)據(jù)庫(kù) DB-GPT部署驗(yàn)證
相關(guān)閱讀
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。