Metadata-Version: 2.4
Name: dai-bench
Version: 0.2.0.post0
Summary: A comprehensive LLM benchmarking tool
Author: Daocloud Team
License-Expression: Apache-2.0
Classifier: Development Status :: 3 - Alpha
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: <3.14,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0.0
Requires-Dist: vllm>=0.22.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: kubernetes>=28.0.0
Requires-Dist: openai>=1.0.0
Requires-Dist: aiperf>=0.5.0
Provides-Extra: dev
Requires-Dist: pytest>=7.3.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.3.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: mypy>=1.3.0; extra == "dev"
Requires-Dist: pre-commit>=4.0.0; extra == "dev"
Dynamic: license-file

# dai-bench

\=======

# dai-bench 项目结构

## 如何运行

```bash
uv pip install -e .
```

> 由于依赖的 llm-d/llm-d-benchmark 没有Python包，采用的 `config-explorer @ git+https://github.com/llm-d/llm-d-benchmark.git@v0.4.0#subdirectory=config_explorer` 的方式声明的依赖，如果由于网络原因卡在这里可以尝试使用 git clone https://github.com/llm-d/llm-d-benchmark.git 后运行 pip install -e ./config_explorer 安装

创建项目和运行实验

```bash
dai-bench setup --name test1
cd test1
dai-bench run --experiment 1
```

## 在 Kubernetes 上运行

本仓库内置了一个最小可用的 K8S 部署示例，使用 `deploy/common` 目录下的清单即可在集群中直接运行基准测试。

### 1. 准备依赖

- **PVC**: `deploy/common/deployment.yaml` 中默认使用名为 `dai-bench-common-pvc` 的 PVC 作为输出目录挂载点，需要提前创建：
  - 该 PVC 会挂载到容器内 `/outputs`，用于存储 `dai-bench` 生成的项目目录和结果。
- **模型目录**: 默认通过 `hostPath` 挂载 `/gpfs/rd/models` 到容器内 `/models`，需要根据实际环境调整：
  - 修改 `deploy/common/deployment.yaml` 中：
    - `spec.template.spec.containers[0].volumeMounts[*].mountPath: /models`
    - `spec.template.spec.volumes[*].hostPath.path: /gpfs/rd/models`
  - 确保模型目录内包含 `Qwen3-0.6B` 或按需调整 `deploy/common/config.yaml` 中的 `server.model_name` 和 `tokenizer.path`。

### 2. 配置压测参数

`deploy/common/config.yaml` 定义了一个 `ConfigMap`，其中：

- **`config.yaml`**:
  - 包含 `project_name`，用于在容器启动时自动创建项目目录（相当于执行 `dai-bench setup --name <project_name> --output-dir /outputs`）。
- **`bench.yaml`**:
  - 定义负载（`load`）、接口类型（`api`）、服务端信息（`server`）、tokenizer、数据源等。
  - 启动时会被复制到 `/outputs/<project_name>/experiments/01/treatment/bench.yaml`。

如需调整压测参数，只需修改该文件中的 `bench.yaml` 部分并重新应用 ConfigMap：

```bash
kubectl apply -f deploy/common/config.yaml
```

### 3. 启动 benchmark 容器

部署 `Deployment`：

```bash
kubectl apply -f deploy/common/deployment.yaml
```

该 Deployment 中容器启动命令等价于：

```bash
dai-bench run \
  --init \
  --from-config /config/config.yaml \
  --from-bench /config/bench.yaml \
  --output-dir /outputs \
  --experiment 01
```

其中：

- `--init --from-config` 会：
  - 读取 `/config/config.yaml` 中的 `project_name`；
  - 在 `/outputs` 下创建对应项目目录结构；
  - 将 `config.yaml` 覆盖到 `setup/config.yaml`。
- `--from-bench` 会：
  - 将 `/config/bench.yaml` 复制到 `experiments/01/treatment/bench.yaml`，覆盖默认配置。

### 4. 查看运行结果

压测完成后，结果会写入 PVC 对应的存储卷中，目录结构类似：

```bash
/outputs/
└── <project_name>
    ├── experiments/
    ├── results/
    └── setup/
```

可以通过以下方式查看：

- 在节点上直接查看挂载路径（如果使用 `hostPath`）。
- 或通过临时 Pod 访问 PVC 内容，例如：

```bash
kubectl run -it --rm debug --image=busybox --restart=Never -- sh
# 挂载同一个 PVC 后在容器内查看 /outputs 下的数据
```

### 运行 llm-d-benchmark config explorer 可视化结果

```bash
# 安装 llm-d-benchmark 依赖
git clone https://github.com/llm-d/llm-d-benchmark.git
cd llm-d-benchmark
pip install -e ./config_explorer  # 如果已经安装可以跳过
pip install -r config_explorer/requirements-streamlit.txt
streamlit run ./config_explorer/Capacity_Planner.py
```

## 输出目录结构

```bash
outputs/
└── test1
    ├── experiments
    │   ├── 01
    │   │   └── treatment
    │   │       ├── bench.yaml
    │   │       └── run.sh
    │   └── 02
    │       └── treatment
    │           ├── bench.yaml
    │           └── run.sh
    ├── README.md
    ├── results
    │   └── 01
    │       └── Qwen_Qwen3-0.6B
    │           └── data
    │               ├── stage1-c1_2-i100-o100
    │               │   ├── benchmark_report,_infqps-concurrency1-20251216-185633.json.yaml
    │               │   ├── benchmark_report,_infqps-concurrency2-20251216-185658.json.yaml
    │               │   ├── infqps-concurrency1-20251216-185633.json
    │               │   └── infqps-concurrency2-20251216-185658.json
    │               └── stage2-c1_2-i1000-o100
    │                   ├── benchmark_report,_infqps-concurrency1-20251216-185705.json.yaml
    │                   ├── benchmark_report,_infqps-concurrency2-20251216-185715.json.yaml
    │                   ├── infqps-concurrency1-20251216-185705.json
    │                   └── infqps-concurrency2-20251216-185715.json
    └── setup
        ├── config.yaml
        └── metadata.json
```
