46
README.md
46
README.md
@@ -91,34 +91,35 @@ adb devices
|
||||
|
||||
### 3. 启动模型服务
|
||||
|
||||
1. 按照 `requirements.txt` 中 `For Model Deployment` 章节自行安装推理引擎框架。
|
||||
1. 按照 `requirements.txt` 中 `For Model Deployment` 章节自行安装推理引擎框架。
|
||||
|
||||
对于SGLang, 除了使用pip安装,你也可以使用官方docker:
|
||||
对于SGLang, 除了使用pip安装,你也可以使用官方docker:
|
||||
>
|
||||
> ```shell
|
||||
> docker pull lmsysorg/sglang:v0.5.6.post1
|
||||
> ```
|
||||
>
|
||||
> 进入容器,执行
|
||||
> 进入容器,执行
|
||||
>
|
||||
> ```
|
||||
> pip install nvidia-cudnn-cu12==9.16.0.29
|
||||
> ```
|
||||
|
||||
对于 vLLM,除了使用pip 安装,你也可以使用官方docker:
|
||||
对于 vLLM,除了使用pip 安装,你也可以使用官方docker:
|
||||
>
|
||||
> ```shell
|
||||
> docker pull vllm/vllm-openai:v0.12.0
|
||||
> ```
|
||||
>
|
||||
> 进入容器,执行
|
||||
> 进入容器,执行
|
||||
>
|
||||
> ```
|
||||
> pip install -U transformers --pre
|
||||
> ```
|
||||
|
||||
|
||||
**注意**: 上述步骤出现的关于 transformers 的依赖冲突可以忽略。
|
||||
|
||||
2. 在对应容器或者实体机中(非容器安装)下载模型,通过 SGlang / vLLM 启动,得到 OpenAI 格式服务。这里提供一个 vLLM部署方案,请严格遵循我们提供的启动参数:
|
||||
1. 在对应容器或者实体机中(非容器安装)下载模型,通过 SGlang / vLLM 启动,得到 OpenAI 格式服务。这里提供一个 vLLM部署方案,请严格遵循我们提供的启动参数:
|
||||
|
||||
- vLLM:
|
||||
|
||||
@@ -152,6 +153,37 @@ python3 -m sglang.launch_server --model-path zai-org/AutoGLM-Phone-9B \
|
||||
|
||||
- 运行成功后,将可以通过 `http://localhost:8000/v1` 访问模型服务。 如果您在远程服务器部署模型, 使用该服务器的IP访问模型.
|
||||
|
||||
### 4. 检查模型部署
|
||||
|
||||
模型服务启动后,可以使用检查脚本验证部署是否成功:
|
||||
|
||||
```bash
|
||||
python scripts/check_deployment_cn.py --base-url http://你的IP:你的端口/v1 --model 模型名称
|
||||
```
|
||||
|
||||
脚本将发送测试请求并展示模型的推理结果,你可以根据输出判断模型部署是否正常工作。
|
||||
|
||||
基于给定的任务, 预期输出如下。**如果思维链长度很短, 或者出现了乱码, 很可能是模型部署失败**, 请仔细检查文档要求的配置和依赖。
|
||||
|
||||
```
|
||||
<think>用户想要比较这个洗发水在京东和淘宝上的价格,然后选择最便宜的平台下单。当前在小红书app上,显示的是一个关于LUMMI MOOD洗发水的帖子。
|
||||
|
||||
我需要:
|
||||
1. 先启动京东app,搜索这个洗发水
|
||||
2. 查看京东的价格
|
||||
3. 再启动淘宝app,搜索这个洗发水
|
||||
4. 查看淘宝的价格
|
||||
5. 比较价格后,选择最便宜的京东或淘宝下单
|
||||
|
||||
首先,我需要从当前的小红书界面退出,然后启动京东app。</think>
|
||||
<answer>do(action="Launch", app="京东")
|
||||
```
|
||||
|
||||
**参数说明:**
|
||||
- `--base-url`: 模型服务地址(根据实际部署地址修改)
|
||||
- `--model`: 模型名称
|
||||
- `--messages-file`: 可选,指定自定义测试消息文件(默认使用 `scripts/sample_messages.json`)
|
||||
|
||||
## 使用 AutoGLM
|
||||
|
||||
### 命令行
|
||||
|
||||
115
scripts/check_deployment_cn.py
Normal file
115
scripts/check_deployment_cn.py
Normal file
@@ -0,0 +1,115 @@
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
|
||||
from openai import OpenAI
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description="检查模型部署是否成功的工具",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
使用示例:
|
||||
python scripts/check_deployment_cn.py --base-url http://localhost:8000/v1 --apikey your-key --model autoglm-phone-9b
|
||||
python scripts/check_deployment_cn.py --base-url http://localhost:8000/v1 --apikey your-key --model autoglm-phone-9b --messages-file custom.json
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--base-url",
|
||||
type=str,
|
||||
required=True,
|
||||
help="API 服务的 base URL,例如: http://localhost:8000/v1",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--apikey", type=str, default="EMPTY", help="API 密钥 (默认: EMPTY)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--model",
|
||||
type=str,
|
||||
required=True,
|
||||
help="要测试的模型名称,例如: autoglm-phone-9b",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--messages-file",
|
||||
type=str,
|
||||
default="scripts/sample_messages.json",
|
||||
help="包含测试消息的 JSON 文件路径 (默认: scripts/sample_messages.json)",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--max-tokens", type=int, default=3000, help="最大生成 token 数 (默认: 3000)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--temperature", type=float, default=0.0, help="采样温度 (默认: 0.0)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--top_p", type=float, default=0.85, help="nucleus sampling 参数 (默认: 0.85)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--frequency_penalty", type=float, default=0.2, help="频率惩罚参数 (默认: 0.2)"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# 读取测试消息
|
||||
if not os.path.exists(args.messages_file):
|
||||
print(f"错误: 消息文件 {args.messages_file} 不存在")
|
||||
exit(1)
|
||||
|
||||
with open(args.messages_file) as f:
|
||||
messages = json.load(f)
|
||||
|
||||
base_url = args.base_url
|
||||
api_key = args.apikey
|
||||
model = args.model
|
||||
|
||||
print(f"开始测试模型推理...")
|
||||
print(f"Base URL: {base_url}")
|
||||
print(f"Model: {model}")
|
||||
print(f"Messages file: {args.messages_file}")
|
||||
print("=" * 80)
|
||||
|
||||
try:
|
||||
client = OpenAI(
|
||||
base_url=base_url,
|
||||
api_key=api_key,
|
||||
)
|
||||
|
||||
response = client.chat.completions.create(
|
||||
messages=messages,
|
||||
model=model,
|
||||
max_tokens=args.max_tokens,
|
||||
temperature=args.temperature,
|
||||
top_p=args.top_p,
|
||||
frequency_penalty=args.frequency_penalty,
|
||||
extra_body={"skip_special_tokens": False},
|
||||
)
|
||||
|
||||
print("\n模型推理结果:")
|
||||
print("=" * 80)
|
||||
print(response.choices[0].message.content)
|
||||
print("=" * 80)
|
||||
|
||||
if response.usage:
|
||||
print(f"\n统计信息:")
|
||||
print(f" - Prompt tokens: {response.usage.prompt_tokens}")
|
||||
print(f" - Completion tokens: {response.usage.completion_tokens}")
|
||||
print(f" - Total tokens: {response.usage.total_tokens}")
|
||||
|
||||
print(f"\n请根据上述推理结果判断模型部署是否符合预期。")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n调用 API 时发生错误:")
|
||||
print(f"错误类型: {type(e).__name__}")
|
||||
print(f"错误信息: {str(e)}")
|
||||
print(
|
||||
"\n提示: 请检查 base_url、api_key 和 model 参数是否正确,以及服务是否正在运行。"
|
||||
)
|
||||
exit(1)
|
||||
21
scripts/sample_messages.json
Normal file
21
scripts/sample_messages.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user