benchscope 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. benchscope-1.0.0/LICENSE +176 -0
  2. benchscope-1.0.0/PKG-INFO +136 -0
  3. benchscope-1.0.0/README.md +102 -0
  4. benchscope-1.0.0/benchscope/__init__.py +3 -0
  5. benchscope-1.0.0/benchscope/__main__.py +4 -0
  6. benchscope-1.0.0/benchscope/benches/__init__.py +1 -0
  7. benchscope-1.0.0/benchscope/benches/base.py +54 -0
  8. benchscope-1.0.0/benchscope/benches/runner.py +185 -0
  9. benchscope-1.0.0/benchscope/benches/sglang_bench.py +77 -0
  10. benchscope-1.0.0/benchscope/benches/vllm_bench.py +94 -0
  11. benchscope-1.0.0/benchscope/cli.py +46 -0
  12. benchscope-1.0.0/benchscope/config.py +91 -0
  13. benchscope-1.0.0/benchscope/constants.py +49 -0
  14. benchscope-1.0.0/benchscope/datasets.py +200 -0
  15. benchscope-1.0.0/benchscope/gpu.py +39 -0
  16. benchscope-1.0.0/benchscope/parser.py +93 -0
  17. benchscope-1.0.0/benchscope/server/__init__.py +3 -0
  18. benchscope-1.0.0/benchscope/server/api_config.py +97 -0
  19. benchscope-1.0.0/benchscope/server/api_logs.py +356 -0
  20. benchscope-1.0.0/benchscope/server/api_test.py +64 -0
  21. benchscope-1.0.0/benchscope/server/app.py +99 -0
  22. benchscope-1.0.0/benchscope/server/state.py +18 -0
  23. benchscope-1.0.0/benchscope/server/status.py +97 -0
  24. benchscope-1.0.0/benchscope/server/test_manager.py +367 -0
  25. benchscope-1.0.0/benchscope/server/ws.py +56 -0
  26. benchscope-1.0.0/benchscope/summary.py +148 -0
  27. benchscope-1.0.0/benchscope/webui/assets/LogView-BDFIduo7.css +1 -0
  28. benchscope-1.0.0/benchscope/webui/assets/LogView-BMsVPLVq.js +1 -0
  29. benchscope-1.0.0/benchscope/webui/assets/MetricsCharts-D1wU0LbK.css +1 -0
  30. benchscope-1.0.0/benchscope/webui/assets/MetricsCharts-DHO93JrC.js +1 -0
  31. benchscope-1.0.0/benchscope/webui/assets/SettingsView-7uuTFqXU.css +1 -0
  32. benchscope-1.0.0/benchscope/webui/assets/SettingsView-DJmFSQbU.js +1 -0
  33. benchscope-1.0.0/benchscope/webui/assets/TestView-81VlxBZU.js +4 -0
  34. benchscope-1.0.0/benchscope/webui/assets/TestView-BAwcOtR2.css +1 -0
  35. benchscope-1.0.0/benchscope/webui/assets/antd-DWALckI0.js +478 -0
  36. benchscope-1.0.0/benchscope/webui/assets/echarts-Bb6yjXMn.js +60 -0
  37. benchscope-1.0.0/benchscope/webui/assets/index-Dfr0hp72.js +2 -0
  38. benchscope-1.0.0/benchscope/webui/assets/index-EhoNt9Gv.css +1 -0
  39. benchscope-1.0.0/benchscope/webui/assets/vue-Ch4zjUb1.js +37 -0
  40. benchscope-1.0.0/benchscope/webui/index.html +19 -0
  41. benchscope-1.0.0/benchscope.egg-info/PKG-INFO +136 -0
  42. benchscope-1.0.0/benchscope.egg-info/SOURCES.txt +46 -0
  43. benchscope-1.0.0/benchscope.egg-info/dependency_links.txt +1 -0
  44. benchscope-1.0.0/benchscope.egg-info/entry_points.txt +2 -0
  45. benchscope-1.0.0/benchscope.egg-info/requires.txt +9 -0
  46. benchscope-1.0.0/benchscope.egg-info/top_level.txt +1 -0
  47. benchscope-1.0.0/pyproject.toml +61 -0
  48. benchscope-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: benchscope
3
+ Version: 1.0.0
4
+ Summary: vLLM / SGLang 推理服务性能测试 Web 工具 (benchscope)
5
+ Author-email: benchscope <benchscope@example.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/benchscope/benchscope
8
+ Project-URL: Documentation, https://github.com/benchscope/benchscope#readme
9
+ Project-URL: Source, https://github.com/benchscope/benchscope
10
+ Keywords: vllm,sglang,benchmark,llm,performance-test,inference,openai-api,web-ui,benchscope
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: System :: Benchmark
21
+ Classifier: Framework :: FastAPI
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: fastapi>=0.110
26
+ Requires-Dist: uvicorn[standard]>=0.29
27
+ Requires-Dist: requests>=2.31
28
+ Requires-Dist: openpyxl>=3.1
29
+ Requires-Dist: pydantic>=2
30
+ Requires-Dist: python-multipart>=0.0.9
31
+ Provides-Extra: modelscope
32
+ Requires-Dist: modelscope>=1.15; extra == "modelscope"
33
+ Dynamic: license-file
34
+
35
+ # benchscope
36
+
37
+ vLLM / SGLang 推理服务性能测试 Web 工具(类似 tensorboard-dashboard 的单进程 pip 工具)。
38
+
39
+ 连接 vLLM / SGLang(或任意 OpenAI 兼容)推理服务的 API 即可进行性能压测,
40
+ 实时展示并发数-吞吐/时延曲线、日志管理与 xlsx 汇总分析。
41
+
42
+ ## 功能特性(V1)
43
+
44
+ - **双框架**:vLLM(`vllm bench serve`)与 SGLang(`sglang.bench_serving`),
45
+ bench 工具在 benchscope 所在机器以子进程运行,**推理服务端无需安装任何插件**,只需提供 OpenAI 兼容 API。
46
+ - **数据集**:
47
+ - `random`:可多选输入/输出长度组合(默认 3K/1K、1K/1K、256/256,可自定义);
48
+ - `sharegpt`:自动从 modelscope 下载
49
+ [gliang1001/ShareGPT_V3_unfiltered_cleaned_split](https://www.modelscope.cn/datasets/gliang1001/ShareGPT_V3_unfiltered_cleaned_split)
50
+ (JSON 数组自动流式转换为 jsonl 缓存);
51
+ - `自定义数据集`:支持网页上传 jsonl 或填写服务器本地路径,功能与 sharegpt 一致。
52
+ - **测试配置**:并发数列表可编辑(默认 1,4,8,16,32,40,64,128),
53
+ `--max-concurrency` 与 `--num-prompts` 保持一致,请求速率可选 `inf`(不限速);
54
+ GPU 型号/数量自动检测(nvidia-smi)并可手动编辑;TPOT 阈值设置与最佳并发高亮;
55
+ 框架常用参数表单 + 自由参数编辑器。
56
+ - **实时结果**:每个并发结果实时入表(表头中英双语),
57
+ 六条曲线(Output 吞吐 / Total 吞吐 / TTFT mean / TPOT mean / TTFT P99 / TPOT P99),横轴并发数。
58
+ - **日志**:每次测试一个 `月日-时分秒` 目录,含原始 bench 日志、mean 汇总 CSV、P99 汇总 CSV、
59
+ `benchmark-*.xlsx`(均值 / P99 双 sheet,列:GPU、模型、精度、推理框架、输入长度、输出长度、
60
+ 并发数、output、peakoutput、total、ttft、itl、tpot、单用户=1000/tpot),支持预览与下载。
61
+ - **分析**:均值 / P99 两大分析块,output/peakoutput/total/ttft/itl/tpot 六曲线;
62
+ 指定 TPOT 阈值后自动标记最接近(低于)阈值的记录为最佳并发。
63
+ - **状态监控**:顶部导航实时显示 网站服务 / 推理服务 就绪或离线,推理服务断开自动变更状态。
64
+
65
+ ## 安装与启动
66
+
67
+ ```bash
68
+ # 后端依赖
69
+ pip install -e .
70
+
71
+ # 前端(可选,若 webui/ 已有构建产物可跳过)
72
+ cd web && npm install && npm run build && cd ..
73
+
74
+ # 启动(默认 http://0.0.0.0:8080,自动打开浏览器)
75
+ benchscope
76
+ # 或指定端口 / 不自动开浏览器
77
+ benchscope --port 8080 --no-browser
78
+ ```
79
+
80
+ 开发模式:
81
+
82
+ ```bash
83
+ # 终端 1:后端
84
+ python -m benchscope.cli --port 8080 --no-browser
85
+ # 终端 2:前端热更新(代理到 8080)
86
+ cd web && npm run dev # http://127.0.0.1:5173
87
+ ```
88
+
89
+ ## 服务设置
90
+
91
+ 打开页面右上角「服务设置」:
92
+
93
+ - Base URL:推理服务 OpenAI 兼容地址(默认 `http://192.168.1.67:8000`),
94
+ Endpoint、API Key、额外请求头;
95
+ - GPU 自动检测(nvidia-smi)或手动填写;
96
+ - 日志目录 `logs_dir` 与数据集缓存目录 `datasets_dir`(默认 `./logs`、`./datasets`);
97
+ - TPOT 阈值默认值、请求速率默认值;
98
+ - bench 执行命令模板:`vllm bench serve` / `python -m sglang.bench_serving`。
99
+
100
+ ## 使用流程
101
+
102
+ 1. 打开页面,确认顶部「推理服务:就绪」;
103
+ 2. 进入 vLLM 或 SGLang 测试页,选择模型(来自 `/v1/models`)、数据集、并发数等;
104
+ 3. 点击「命令预览」确认将要执行的 bench 命令,点击「开始测试」;
105
+ 4. 实时结果面板逐条刷新,曲线实时更新;日志分析面板可查看原始日志、汇总与 xlsx;
106
+ 5. 测试完成后自动生成 `logs/<月日-时分秒>/benchmark-*.xlsx`(均值 + P99 双 sheet)。
107
+
108
+ ## 目录结构
109
+
110
+ ```
111
+ benchscope/
112
+ ├── benchscope/
113
+ │ ├── cli.py # benchscope 命令入口
114
+ │ ├── config.py # 配置持久化 (~/.benchscope/config.json)
115
+ │ ├── constants.py # 默认值(并发列表、长度组合等)
116
+ │ ├── datasets.py # sharegpt 下载/转换、自定义数据集
117
+ │ ├── gpu.py # GPU 自动检测
118
+ │ ├── parser.py # bench 输出解析(mean + P99)
119
+ │ ├── summary.py # CSV 与 xlsx 汇总生成
120
+ │ ├── benches/ # vllm/sglang 命令构建与执行
121
+ │ └── server/ # FastAPI + WebSocket + 测试编排
122
+ ├── web/ # Vue3 + Ant Design Vue 前端源码
123
+ ├── asserts/ # 参考脚本与样例日志(test-non.py 等)
124
+ └── tests/mock_openai_server.py # 本地联调用模拟 OpenAI 服务
125
+ ```
126
+
127
+ ## 开发调试
128
+
129
+ - 无 vllm/sglang 环境联调:设置环境变量 `BENCHSCOPE_FAKE_BENCH=1` 后启动,bench 将以仿真数据执行;
130
+ - 本地模拟推理服务:`python tests/mock_openai_server.py`(端口 8001),
131
+ 在服务设置中把 Base URL 指向 `http://127.0.0.1:8001`。
132
+
133
+ ## 规划
134
+
135
+ V1 纯文本性能测试(本版本)→ V2 多模态模型测试 → V3 全模态 → V4 世界模型;
136
+ V5 常见数据集精度测试 → V6 modelscope 官方模型对比分析。
@@ -0,0 +1,102 @@
1
+ # benchscope
2
+
3
+ vLLM / SGLang 推理服务性能测试 Web 工具(类似 tensorboard-dashboard 的单进程 pip 工具)。
4
+
5
+ 连接 vLLM / SGLang(或任意 OpenAI 兼容)推理服务的 API 即可进行性能压测,
6
+ 实时展示并发数-吞吐/时延曲线、日志管理与 xlsx 汇总分析。
7
+
8
+ ## 功能特性(V1)
9
+
10
+ - **双框架**:vLLM(`vllm bench serve`)与 SGLang(`sglang.bench_serving`),
11
+ bench 工具在 benchscope 所在机器以子进程运行,**推理服务端无需安装任何插件**,只需提供 OpenAI 兼容 API。
12
+ - **数据集**:
13
+ - `random`:可多选输入/输出长度组合(默认 3K/1K、1K/1K、256/256,可自定义);
14
+ - `sharegpt`:自动从 modelscope 下载
15
+ [gliang1001/ShareGPT_V3_unfiltered_cleaned_split](https://www.modelscope.cn/datasets/gliang1001/ShareGPT_V3_unfiltered_cleaned_split)
16
+ (JSON 数组自动流式转换为 jsonl 缓存);
17
+ - `自定义数据集`:支持网页上传 jsonl 或填写服务器本地路径,功能与 sharegpt 一致。
18
+ - **测试配置**:并发数列表可编辑(默认 1,4,8,16,32,40,64,128),
19
+ `--max-concurrency` 与 `--num-prompts` 保持一致,请求速率可选 `inf`(不限速);
20
+ GPU 型号/数量自动检测(nvidia-smi)并可手动编辑;TPOT 阈值设置与最佳并发高亮;
21
+ 框架常用参数表单 + 自由参数编辑器。
22
+ - **实时结果**:每个并发结果实时入表(表头中英双语),
23
+ 六条曲线(Output 吞吐 / Total 吞吐 / TTFT mean / TPOT mean / TTFT P99 / TPOT P99),横轴并发数。
24
+ - **日志**:每次测试一个 `月日-时分秒` 目录,含原始 bench 日志、mean 汇总 CSV、P99 汇总 CSV、
25
+ `benchmark-*.xlsx`(均值 / P99 双 sheet,列:GPU、模型、精度、推理框架、输入长度、输出长度、
26
+ 并发数、output、peakoutput、total、ttft、itl、tpot、单用户=1000/tpot),支持预览与下载。
27
+ - **分析**:均值 / P99 两大分析块,output/peakoutput/total/ttft/itl/tpot 六曲线;
28
+ 指定 TPOT 阈值后自动标记最接近(低于)阈值的记录为最佳并发。
29
+ - **状态监控**:顶部导航实时显示 网站服务 / 推理服务 就绪或离线,推理服务断开自动变更状态。
30
+
31
+ ## 安装与启动
32
+
33
+ ```bash
34
+ # 后端依赖
35
+ pip install -e .
36
+
37
+ # 前端(可选,若 webui/ 已有构建产物可跳过)
38
+ cd web && npm install && npm run build && cd ..
39
+
40
+ # 启动(默认 http://0.0.0.0:8080,自动打开浏览器)
41
+ benchscope
42
+ # 或指定端口 / 不自动开浏览器
43
+ benchscope --port 8080 --no-browser
44
+ ```
45
+
46
+ 开发模式:
47
+
48
+ ```bash
49
+ # 终端 1:后端
50
+ python -m benchscope.cli --port 8080 --no-browser
51
+ # 终端 2:前端热更新(代理到 8080)
52
+ cd web && npm run dev # http://127.0.0.1:5173
53
+ ```
54
+
55
+ ## 服务设置
56
+
57
+ 打开页面右上角「服务设置」:
58
+
59
+ - Base URL:推理服务 OpenAI 兼容地址(默认 `http://192.168.1.67:8000`),
60
+ Endpoint、API Key、额外请求头;
61
+ - GPU 自动检测(nvidia-smi)或手动填写;
62
+ - 日志目录 `logs_dir` 与数据集缓存目录 `datasets_dir`(默认 `./logs`、`./datasets`);
63
+ - TPOT 阈值默认值、请求速率默认值;
64
+ - bench 执行命令模板:`vllm bench serve` / `python -m sglang.bench_serving`。
65
+
66
+ ## 使用流程
67
+
68
+ 1. 打开页面,确认顶部「推理服务:就绪」;
69
+ 2. 进入 vLLM 或 SGLang 测试页,选择模型(来自 `/v1/models`)、数据集、并发数等;
70
+ 3. 点击「命令预览」确认将要执行的 bench 命令,点击「开始测试」;
71
+ 4. 实时结果面板逐条刷新,曲线实时更新;日志分析面板可查看原始日志、汇总与 xlsx;
72
+ 5. 测试完成后自动生成 `logs/<月日-时分秒>/benchmark-*.xlsx`(均值 + P99 双 sheet)。
73
+
74
+ ## 目录结构
75
+
76
+ ```
77
+ benchscope/
78
+ ├── benchscope/
79
+ │ ├── cli.py # benchscope 命令入口
80
+ │ ├── config.py # 配置持久化 (~/.benchscope/config.json)
81
+ │ ├── constants.py # 默认值(并发列表、长度组合等)
82
+ │ ├── datasets.py # sharegpt 下载/转换、自定义数据集
83
+ │ ├── gpu.py # GPU 自动检测
84
+ │ ├── parser.py # bench 输出解析(mean + P99)
85
+ │ ├── summary.py # CSV 与 xlsx 汇总生成
86
+ │ ├── benches/ # vllm/sglang 命令构建与执行
87
+ │ └── server/ # FastAPI + WebSocket + 测试编排
88
+ ├── web/ # Vue3 + Ant Design Vue 前端源码
89
+ ├── asserts/ # 参考脚本与样例日志(test-non.py 等)
90
+ └── tests/mock_openai_server.py # 本地联调用模拟 OpenAI 服务
91
+ ```
92
+
93
+ ## 开发调试
94
+
95
+ - 无 vllm/sglang 环境联调:设置环境变量 `BENCHSCOPE_FAKE_BENCH=1` 后启动,bench 将以仿真数据执行;
96
+ - 本地模拟推理服务:`python tests/mock_openai_server.py`(端口 8001),
97
+ 在服务设置中把 Base URL 指向 `http://127.0.0.1:8001`。
98
+
99
+ ## 规划
100
+
101
+ V1 纯文本性能测试(本版本)→ V2 多模态模型测试 → V3 全模态 → V4 世界模型;
102
+ V5 常见数据集精度测试 → V6 modelscope 官方模型对比分析。
@@ -0,0 +1,3 @@
1
+ """benchscope - vLLM / SGLang 推理服务性能测试 Web 工具."""
2
+
3
+ __version__ = "1.0.0"
@@ -0,0 +1,4 @@
1
+ from benchscope.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1 @@
1
+ """bench 命令构建与执行。"""
@@ -0,0 +1,54 @@
1
+ """bench 命令构建的公共定义。"""
2
+ from __future__ import annotations
3
+
4
+ from dataclasses import dataclass, field
5
+ from typing import Any
6
+
7
+
8
+ @dataclass
9
+ class ParamDef:
10
+ """UI 表单中一个可配置参数的定义。"""
11
+
12
+ key: str # 表单字段名
13
+ flag: str # 实际 CLI flag,如 "--temperature"
14
+ label: str # 中文标签
15
+ help: str = ""
16
+ type: str = "str" # str | int | float | bool | select
17
+ default: Any = None
18
+ options: list = field(default_factory=list)
19
+ advanced: bool = False # 是否归入“高级参数”折叠区
20
+
21
+
22
+ @dataclass
23
+ class BenchOptions:
24
+ """一次 bench 执行所需的全部选项。"""
25
+
26
+ framework: str
27
+ model: str
28
+ api: dict # {host, port, base_url, endpoint, api_key, extra_headers}
29
+ dataset: dict # {type, path, input_len, output_len, sharegpt_output_len}
30
+ concurrency: int
31
+ request_rate: str | float = "inf"
32
+ curated: dict = field(default_factory=dict) # 表单参数 key -> value
33
+ extra_args: list = field(default_factory=list) # [{"flag": "--x", "value": "y"}]
34
+
35
+
36
+ def build_arg_list(flags: list[list]) -> list[str]:
37
+ """将 [["--flag","value"], ["--bool",""]] 展开为命令行列表。"""
38
+ out: list[str] = []
39
+ for item in flags:
40
+ flag, value = item[0], item[1] if len(item) > 1 else ""
41
+ if isinstance(value, bool):
42
+ if value:
43
+ out.append(flag)
44
+ continue
45
+ if value is None or value == "":
46
+ out.append(flag)
47
+ else:
48
+ out.extend([flag, str(value)])
49
+ return out
50
+
51
+
52
+ def flag_value(flag: str, value: Any) -> list[str]:
53
+ """单个 flag 的展开(供参数校验后使用)。"""
54
+ return build_arg_list([[flag, value]])
@@ -0,0 +1,185 @@
1
+ """bench 子进程流式执行器。
2
+
3
+ 支持真实执行(vllm/sglang CLI)与 FAKE 模式(BENCHSCOPE_FAKE_BENCH=1,
4
+ 生成仿真输出,便于无 vllm/sglang 环境下联调 UI 全流程)。
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import logging
9
+ import math
10
+ import os
11
+ import random
12
+ import shlex
13
+ import subprocess
14
+ import sys
15
+ import threading
16
+ import time
17
+ from typing import Callable, Optional
18
+
19
+ from benchscope.parser import parse_metrics
20
+
21
+ log = logging.getLogger("benchscope.runner")
22
+
23
+ StreamCallback = Callable[[str], None] # 每行输出回调
24
+
25
+
26
+ class StopRequested(RuntimeError):
27
+ """测试被人为停止。"""
28
+
29
+
30
+ class BenchRunner:
31
+ def __init__(self, command_template: str | None = None):
32
+ """command_template 形如 "vllm bench serve" / "python -m sglang.bench_serving"。"""
33
+ self.command_template = command_template or "vllm bench serve"
34
+ self._proc: Optional[subprocess.Popen] = None
35
+ self._stop_flag = threading.Event()
36
+
37
+ def kill(self) -> None:
38
+ """终止当前执行的子进程(用于停止测试)。"""
39
+ self._stop_flag.set()
40
+ proc = self._proc
41
+ if proc and proc.poll() is None:
42
+ try:
43
+ proc.kill()
44
+ except Exception:
45
+ pass
46
+
47
+ # ------------------------------------------------------------------
48
+ def run(
49
+ self,
50
+ cmd: list[str],
51
+ stream_cb: Optional[StreamCallback] = None,
52
+ timeout: float | None = None,
53
+ ) -> dict:
54
+ """执行命令,返回 parse_metrics 结果(含 raw)。失败抛 RuntimeError。"""
55
+ self._stop_flag.clear()
56
+ if os.environ.get("BENCHSCOPE_FAKE_BENCH") == "1":
57
+ return self._run_fake(cmd, stream_cb)
58
+
59
+ # 用模板指定的可执行文件替换命令头部(vllm / python -m sglang...)
60
+ full_cmd = self._resolve(cmd)
61
+ log.info("执行命令: %s", " ".join(full_cmd))
62
+ if stream_cb:
63
+ stream_cb("$ " + " ".join(full_cmd) + "\n")
64
+
65
+ try:
66
+ proc = subprocess.Popen(
67
+ full_cmd,
68
+ stdout=subprocess.PIPE,
69
+ stderr=subprocess.STDOUT,
70
+ text=True,
71
+ encoding="utf-8",
72
+ errors="replace",
73
+ bufsize=1,
74
+ )
75
+ self._proc = proc
76
+ except FileNotFoundError as e:
77
+ raise RuntimeError(
78
+ f"未找到命令执行环境:{full_cmd[0]}。请确认已安装 "
79
+ f"{self.command_template.split()[0]} 相关 CLI(并在服务设置中配置 bench 命令)。"
80
+ ) from e
81
+
82
+ chunks: list[str] = []
83
+ start = time.time()
84
+ try:
85
+ assert proc.stdout is not None
86
+ for line in proc.stdout:
87
+ chunks.append(line)
88
+ if stream_cb:
89
+ stream_cb(line)
90
+ if timeout and time.time() - start > timeout:
91
+ proc.kill()
92
+ raise RuntimeError(f"bench 执行超时(>{timeout}s)")
93
+ proc.wait()
94
+ except KeyboardInterrupt:
95
+ proc.kill()
96
+ raise
97
+ finally:
98
+ self._proc = None
99
+ if proc.returncode != 0:
100
+ output = "".join(chunks)
101
+ if proc.returncode == -9 or proc.returncode == 137:
102
+ raise StopRequested("测试已被停止")
103
+ raise RuntimeError(
104
+ f"bench 命令执行失败(返回码 {proc.returncode})。\n完整日志:\n{output[-4000:]}"
105
+ )
106
+ output = "".join(chunks)
107
+ metrics = parse_metrics(output)
108
+ if "output_mean" not in metrics:
109
+ raise RuntimeError(f"未能从 bench 输出解析出指标,输出如下:\n{output[-3000:]}")
110
+ return metrics
111
+
112
+ # ------------------------------------------------------------------
113
+ def _resolve(self, cmd: list[str]) -> list[str]:
114
+ """把命令头替换为模板指定的执行方式。"""
115
+ tmpl = shlex.split(self.command_template)
116
+ # 保留原始参数(从模板之后开始)
117
+ return tmpl + cmd[len(tmpl):] if cmd[:len(tmpl)] == tmpl else tmpl + cmd
118
+
119
+ # ------------------------------------------------------------------
120
+ # FAKE 模式:生成仿真 vllm 风格输出
121
+ def _run_fake(self, cmd: list[str], stream_cb: Optional[StreamCallback] = None) -> dict:
122
+ args = " ".join(cmd)
123
+ concurrency = 1
124
+ input_len, output_len = 1024, 1024
125
+ for i, tok in enumerate(cmd):
126
+ if tok == "--max-concurrency" and i + 1 < len(cmd):
127
+ concurrency = int(cmd[i + 1])
128
+ if tok == "--random-input-len" and i + 1 < len(cmd):
129
+ input_len = int(cmd[i + 1])
130
+ if tok == "--random-output-len" and i + 1 < len(cmd):
131
+ output_len = int(cmd[i + 1])
132
+ rng = random.Random(int(time.time() * 1000) % 2**31)
133
+
134
+ c = max(concurrency, 1)
135
+ out_tps = round(50 * c**0.62 * rng.uniform(0.95, 1.05), 2)
136
+ total = round(out_tps * (input_len + output_len) / output_len, 2)
137
+ ttft = round(60 + 9 * c + rng.uniform(0, 20), 2)
138
+ tpot = round(18 + 0.55 * c + rng.uniform(0, 3), 2)
139
+ itl = round(tpot * rng.uniform(0.97, 1.02), 2)
140
+
141
+ lines = [
142
+ "============ Serving Benchmark Result ============",
143
+ "Successful requests: %d" % c,
144
+ "Failed requests: 0",
145
+ "Maximum request concurrency: %d" % c,
146
+ "Benchmark duration (s): %.2f" % rng.uniform(5, 40),
147
+ "Total input tokens: %d" % (input_len * c),
148
+ "Total generated tokens: %d" % (output_len * c),
149
+ "Request throughput (req/s): %.2f" % rng.uniform(0.1, c),
150
+ "Output token throughput (tok/s): %s" % out_tps,
151
+ "Peak output token throughput (tok/s): %s" % round(out_tps * 1.02, 2),
152
+ "Peak concurrent requests: %.2f" % c,
153
+ "Total token throughput (tok/s): %s" % total,
154
+ "---------------Time to First Token----------------",
155
+ "Mean TTFT (ms): %s" % ttft,
156
+ "Median TTFT (ms): %s" % round(ttft * 0.98, 2),
157
+ "P99 TTFT (ms): %s" % round(ttft * rng.uniform(1.05, 1.3), 2),
158
+ "-----Time per Output Token (excl. 1st token)------",
159
+ "Mean TPOT (ms): %s" % tpot,
160
+ "Median TPOT (ms): %s" % round(tpot * 0.97, 2),
161
+ "P99 TPOT (ms): %s" % round(tpot * rng.uniform(1.06, 1.35), 2),
162
+ "---------------Inter-token Latency----------------",
163
+ "Mean ITL (ms): %s" % itl,
164
+ "Median ITL (ms): %s" % round(itl * 0.97, 2),
165
+ "P99 ITL (ms): %s" % round(itl * rng.uniform(1.05, 1.3), 2),
166
+ "==================================================",
167
+ "",
168
+ ]
169
+ output = "\n".join(lines)
170
+ # 模拟耗时(可被 kill 中断)
171
+ total_sleep = min(0.6, 0.2 + c * 0.01)
172
+ slept = 0.0
173
+ while slept < total_sleep:
174
+ if self._stop_flag.is_set():
175
+ raise StopRequested("测试已被停止")
176
+ time.sleep(0.05)
177
+ slept += 0.05
178
+ if self._stop_flag.is_set():
179
+ raise StopRequested("测试已被停止")
180
+ if stream_cb:
181
+ stream_cb(f"$ {args}\n")
182
+ for ln in lines:
183
+ stream_cb(ln + "\n")
184
+ metrics = parse_metrics(output)
185
+ return metrics