From 44d4bacf1c01132607304b83b1bd83382fabfbbe Mon Sep 17 00:00:00 2001 From: hzg0601 Date: Thu, 17 Aug 2023 16:59:16 +0800 Subject: [PATCH] =?UTF-8?q?update=20llm=5Fapi=5Flaunch,api=5Fallinone,webu?= =?UTF-8?q?i=5Fallinone,readme:1.llm=5Fapi=5Flaunch,api=5Fallinone=5Fwebui?= =?UTF-8?q?=5Fallinone=E6=9B=B4=E5=90=8D;2.=20=E6=9B=B4=E6=96=B0readme?= =?UTF-8?q?=E5=85=B3=E4=BA=8Estartup=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 86 +++---------------- ...{api_allinone.py => api_allinone_stale.py} | 2 +- .../{llm_api_launch.py => llm_api_stale.py} | 0 .../webui_allinone_stale.py | 4 +- startup.py | 30 ++++++- 5 files changed, 41 insertions(+), 81 deletions(-) rename server/{api_allinone.py => api_allinone_stale.py} (95%) rename server/{llm_api_launch.py => llm_api_stale.py} (100%) rename webui_allinone.py => server/webui_allinone_stale.py (93%) diff --git a/README.md b/README.md index 9766035..a52d30d 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,6 @@ embedding_model_dict = { ```shell $ python init_database.py ``` - - 如果您是第一次运行本项目,知识库尚未建立,或者配置文件中的知识库类型、嵌入模型发生变化,需要以下命令初始化或重建知识库: ```shell @@ -244,6 +243,7 @@ $ python server/llm_api.py ``` 项目支持多卡加载,需在 llm_api.py 中修改 create_model_worker_app 函数中,修改如下三个参数: + ```python gpus=None, num_gpus=1, @@ -258,7 +258,7 @@ max_gpu_memory="20GiB" ##### 5.1.2 基于命令行脚本 llm_api_launch.py 启动 LLM 服务 -⚠️ **注意:** +⚠️ **注意:** **1.llm_api_launch.py脚本原生仅适用于linux,mac设备需要安装对应的linux命令,win平台请使用wls;** @@ -275,11 +275,13 @@ $ python server/llm_api_launch.py ```shell $ python server/llm_api_launch.py --model-path-addresss model1@host1@port1 model2@host2@port2 ``` + 如果出现server端口占用情况,需手动指定server端口,并同步修改model_config.py下对应模型的base_api_url为指定端口: ```shell $ python server/llm_api_launch.py --server-port 8887 ``` + 如果要启动多卡加载,示例命令如下: ```shell @@ -354,7 +356,6 @@ $ streamlit run webui.py --server.port 666 - Web UI 对话界面: ![](img/webui_0813_0.png) - - Web UI 知识库管理页面: ![](img/webui_0813_1.png) @@ -363,86 +364,21 @@ $ streamlit run webui.py --server.port 666 ### 6. 一键启动 -⚠️ **注意:** - -**1. 一键启动脚本仅原生适用于Linux,Mac 设备需要安装对应的linux命令, Winodws 平台请使用 WLS;** - -**2. 加载非默认模型需要用命令行参数 `--model-path-address` 指定模型,不会读取 `model_config.py` 配置。** - -#### 6.1 API 服务一键启动脚本 - -新增 API 一键启动脚本,可一键开启 FastChat 后台服务及本项目提供的 API 服务,调用示例: - -调用默认模型: +更新一键启动脚本startup.py,一键启动所有fastchat服务、API服务、WebUI服务实例: ```shell -$ python server/api_allinone.py +$ python startup.py --all-webui ``` -加载多个非默认模型: +可选 `all-webui,all-api,llm-api,controller,openai-api,model-worker,api,webui`. + +若想指定非默认模型,需要用--model-name选项,示例: ```shell -$ python server/api_allinone.py --model-path-address model1@host1@port1 model2@host2@port2 +$ python startup.py --all-webui --model-name Qwen-7B-Chat ``` -如果出现server端口占用情况,需手动指定server端口,并同步修改model_config.py下对应模型的base_api_url为指定端口: - -```shell -$ python server/api_allinone.py --server-port 8887 -``` - -多卡启动: - -```shell -python server/api_allinone.py --model-path-address model@host@port --num-gpus 2 --gpus 0,1 --max-gpu-memory 10GiB -``` - -其他参数详见各脚本及 FastChat 服务说明。 - -#### 6.2 webui一键启动脚本 - -加载本地模型: - -```shell -$ python webui_allinone.py -``` - -调用远程 API 服务: - -```shell -$ python webui_allinone.py --use-remote-api -``` -如果出现server端口占用情况,需手动指定server端口,并同步修改model_config.py下对应模型的base_api_url为指定端口: - -```shell -$ python webui_allinone.py --server-port 8887 -``` - -后台运行webui服务: - -```shell -$ python webui_allinone.py --nohup -``` - -加载多个非默认模型: - -```shell -$ python webui_allinone.py --model-path-address model1@host1@port1 model2@host2@port2 -``` - -多卡启动: - -```shell -$ python webui_alline.py --model-path-address model@host@port --num-gpus 2 --gpus 0,1 --max-gpu-memory 10GiB -``` - -其他参数详见各脚本及 Fastchat 服务说明。 - -上述两个一键启动脚本会后台运行多个服务,如要停止所有服务,可使用 `shutdown_all.sh` 脚本: - -```shell -bash shutdown_all.sh -``` +**注意:startup脚本用多进程方式启动各模块的服务,可能会导致打印顺序问题,请等待全部服务发起后再调用,并根据默认端口调用服务(默认api服务端口127.0.0.1:7861,默认webui服务端口:`本机IP:8501`)** ## 常见问题 diff --git a/server/api_allinone.py b/server/api_allinone_stale.py similarity index 95% rename from server/api_allinone.py rename to server/api_allinone_stale.py index 3be8581..78a7a6d 100644 --- a/server/api_allinone.py +++ b/server/api_allinone_stale.py @@ -15,7 +15,7 @@ import os sys.path.append(os.path.dirname(__file__)) sys.path.append(os.path.dirname(os.path.dirname(__file__))) -from llm_api_launch import launch_all, parser, controller_args, worker_args, server_args +from llm_api_stale import launch_all, parser, controller_args, worker_args, server_args from api import create_app import uvicorn diff --git a/server/llm_api_launch.py b/server/llm_api_stale.py similarity index 100% rename from server/llm_api_launch.py rename to server/llm_api_stale.py diff --git a/webui_allinone.py b/server/webui_allinone_stale.py similarity index 93% rename from webui_allinone.py rename to server/webui_allinone_stale.py index 2992ae5..627f956 100644 --- a/webui_allinone.py +++ b/server/webui_allinone_stale.py @@ -20,9 +20,9 @@ from webui_pages.utils import * from streamlit_option_menu import option_menu from webui_pages import * import os -from server.llm_api_launch import string_args,launch_all,controller_args,worker_args,server_args,LOG_PATH +from server.llm_api_stale import string_args,launch_all,controller_args,worker_args,server_args,LOG_PATH -from server.api_allinone import parser, api_args +from server.api_allinone_stale import parser, api_args import subprocess parser.add_argument("--use-remote-api",action="store_true") diff --git a/startup.py b/startup.py index d7c2ef9..299eec1 100644 --- a/startup.py +++ b/startup.py @@ -249,8 +249,19 @@ def run_webui(q: Queue, run_seq: int = 5): def parse_args() -> argparse.ArgumentParser: parser = argparse.ArgumentParser() parser.add_argument( - "-a", - "--all", + "--all-webui", + action="store_true", + help="run fastchat's controller/model_worker/openai_api servers, run api.py and webui.py", + dest="all", + ) + parser.add_argument( + "--all-api", + action="store_true", + help="run fastchat's controller/model_worker/openai_api servers, run api.py and webui.py", + dest="all", + ) + parser.add_argument( + "--llm-api", action="store_true", help="run fastchat's controller/model_worker/openai_api servers, run api.py and webui.py", dest="all", @@ -305,12 +316,25 @@ if __name__ == "__main__": mp.set_start_method("spawn") queue = Queue() args = parse_args() - if args.all: + if args.all_webui: args.openai_api = True args.model_worker = True args.api = True args.webui = True + elif args.all_api: + args.openai_api = True + args.model_worker = True + args.api = True + args.webui = False + + elif args.llm_api: + args.openai_api = True + args.model_worker = True + args.api = False + args.webui = False + + logger.info(f"正在启动服务:") logger.info(f"如需查看 llm_api 日志,请前往 {LOG_PATH}")