# 使用 MLPerf 测试 ML 训练性能

[MLPerf™ Storage](https://github.com/mlcommons/storage) 基准测试套件由 MLCommons® 设计，旨在衡量存储系统在真实机器学习 (ML) 训练工作负载下的性能。它模拟了 `BERT` 和 `U-Net3D` 等模型的 I/O 模式，以评估存储吞吐量和 I/O 效率。

本指南介绍了如何使用 MLPerf Storage 基准测试来测试 Alluxio 集群的性能。

## 基准测试亮点

以下结果是使用 MLPerf Storage v0.5 基准测试得出的，数据完全缓存在 Alluxio 中，并使用 A100 GPU 作为训练加速器。“加速器利用率 (AU)” 指标显示了存储系统使 GPU 保持繁忙状态的效率。

| 模型      | 加速器数量 (GPU) | 数据集大小  | 加速器利用率 (AU) | 吞吐量 (MB/秒) | 吞吐量 (样本/秒) |
| ------- | ----------- | ------ | ----------- | ---------- | ---------- |
| BERT    | 1           | 1.3 TB | 99%         | 0.1        | 49.3       |
| BERT    | 128         | 2.4 TB | 98%         | 14.8       | 6,217      |
| U-Net3D | 1           | 719 GB | 99%         | 409.5      | 2.9        |
| U-Net3D | 20          | 3.8 TB | 97%-99%     | 7,911.4    | 56.59      |

## 测试环境

基准测试结果是使用以下环境生成的，所有实例都部署在同一个 AWS 可用区中。

* **Alluxio 集群**:
  * 2 个工作节点 (`i3en.metal`: 96 核, 768GB RAM, 8 个 NVMe SSD)
  * 1 个 FUSE 客户端节点 (`c6in.metal`: 128 核, 256GB RAM)
* **操作系统**: Ubuntu 22.04

## 设置和配置

### 1. 安装 MLPerf Storage 工具

在您将运行基准测试的客户端节点上：

```bash
# 安装 MPI 依赖
sudo apt-get install mpich

# 克隆基准测试仓库并安装 Python 依赖
git clone -b v0.5 --recurse-submodules https://github.com/mlcommons/storage.git
cd storage
pip3 install -r dlio_benchmark/requirements.txt
```

### 2. 配置 Alluxio

为了在 ML 训练期间获得最佳读取性能，我们建议在 Alluxio 集群节点的 `conf/alluxio-site.properties` 文件中设置以下属性。

```properties
alluxio.user.position.reader.streaming.async.prefetch.enable=true
alluxio.user.position.reader.streaming.async.prefetch.thread=256
alluxio.user.position.reader.streaming.async.prefetch.part.length=4MB
alluxio.user.position.reader.streaming.async.prefetch.max.part.number=4
```

在运行基准测试之前，请确保：

* Alluxio FUSE 进程正在客户端节点上运行。
* 训练数据集已完全加载到 Alluxio 缓存中。

## 运行基准测试

基准测试过程包括生成一个合成数据集，然后对其运行训练模拟。

### 步骤 1：生成数据集

首先，根据您的模拟硬件确定所需的数据集大小。

```bash
# U-Net3D 使用 4 个模拟加速器的示例
./benchmark.sh datasize --workload unet3d --num-accelerators 4 --host-memory-in-gb 32
```

此命令将输出所需的文件数。使用此值生成实际的数据文件。

```bash
# 数据生成命令示例
./benchmark.sh datagen --workload unet3d --num-parallel 8 --param dataset.num_files_train=1600 --param dataset.data_folder=${dataset.data_folder}
```

生成数据集后，将其上传到您的 UFS 并确保已加载到 Alluxio 中。

### 步骤 2：运行基准测试

使用 `run` 命令执行基准测试。`data_folder` 参数应指向 Alluxio FUSE 挂载点内的数据集。

```bash
./benchmark.sh run --workload unet3d --num-accelerators 4 --results-dir ${results-dir} --param dataset.data_folder=${dataset.data_folder} --param dataset.num_files_train=${dataset.num_files_train}
```

### 步骤 3：审查和汇总结果

运行完成后，将在您的结果目录中创建一个 `summary.json` 文件。该文件包含详细的指标，包括 GPU 利用率 (`train_au_percentage`) 和吞吐量。

### `summary.json` 示例

```json
{
  "model": "unet3d",
  "start": "2024-05-27T14:46:24.458325",
  "num_accelerators": 20,
  "metric": {
    "train_au_percentage": [
      99.18125818824699,
      99.01649117920554,
      ...
    ],
    "train_au_mean_percentage": 98.74588296364462,
    "train_throughput_mean_samples_per_second": 56.90265822935148,
    "train_io_mean_MB_per_second": 7955.518180172248
  },
  ...
}
```

为了获得最终结果，基准测试应多次运行（例如 5 次）。整理每次运行的输出目录，并使用 `reportgen` 命令生成汇总摘要。

```bash
# 汇总多次运行的结果
./benchmark.sh reportgen --results-dir sample-results
```

这将生成一个最终的 JSON 输出，其中包含所有运行中吞吐量和其他关键指标的总体平均值和标准差。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.alluxio.io/ee-ai-cn/ai-3.7/benchmark/benchmarking-ml-training-performance-with-mlperf.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
