profile_api_server.md 1.74 KB
Newer Older
Lyu Han's avatar
Lyu Han committed
1
2
3
4
5
6
7
# api_server 性能测试

api_server 的测试方式与[求吞吐量测试方法](./profile_throughput.md)类似。不同的是,在测试前,需要先启动 api_server,然后再通过测试脚本发送请求进行测试。

测试脚本是 `profile_restful_api.py`。测试之前,请安装 lmdeploy 预编译包,并下载评测脚本和测试数据集。

```shell
zhouxiang's avatar
zhouxiang committed
8
pip install lmdeploy
Lyu Han's avatar
Lyu Han committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
git clone --depth=1 https://github.com/InternLM/lmdeploy
cd lmdeploy/benchmark
wget https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered/resolve/main/ShareGPT_V3_unfiltered_cleaned_split.json
```

## 测量指标

LMDeploy 统计首token延时(first_token_latency)、token吞吐量(tokens/s)和请求吞吐量(RPM)。

`first_token_latency` 只有在流式推理的情况下才会输出。

token吞吐量的计算公式为:

$$
吞吐量 = 生成的token数量 / 总时间
$$

请求吞吐量的计算公式为:

$$
吞吐量 = 请求数量 / 总时间
$$

总时间包括 prefill 时间

zhouxiang's avatar
zhouxiang committed
34
## 测量方法
Lyu Han's avatar
Lyu Han committed
35

zhouxiang's avatar
zhouxiang committed
36
我们以 [internlm/internlm-7b](https://huggingface.co/internlm/internlm-7b) 为例,展示 api_server 的性能测试流程
Lyu Han's avatar
Lyu Han committed
37

zhouxiang's avatar
zhouxiang committed
38
### 启动服务
Lyu Han's avatar
Lyu Han committed
39

zhouxiang's avatar
zhouxiang committed
40
41
```shell
lmdeploy serve api_server internlm/internlm-7b
Lyu Han's avatar
Lyu Han committed
42
43
```

zhouxiang's avatar
zhouxiang committed
44
如果你想改变 server 的端口,或者诸如推理引擎、最大批处理值等参数,请运行 `lmdeploy serve api_server -h` 或者阅读[这篇文档](../serving/api_server.md),查看详细的参数说明。
Lyu Han's avatar
Lyu Han committed
45

zhouxiang's avatar
zhouxiang committed
46
### 测速
Lyu Han's avatar
Lyu Han committed
47
48

```shell
zhouxiang's avatar
zhouxiang committed
49
python3 profile_restful_api.py http://0.0.0.0:23333 internlm/internlm-7b ./ShareGPT_V3_unfiltered_cleaned_split.json
Lyu Han's avatar
Lyu Han committed
50
51
```

zhouxiang's avatar
zhouxiang committed
52
关于 `profile_restful_api.py` 脚本中的参数,比如请求并发数、采样参数等等,可以通过运行命令 `python3 profile_restful_api.py -h` 查阅。