GPU 集群不是"插上线就能跑满"的。从单卡 HBM 带宽到全集群 AllReduce,每一层都有基线,每一层都可能藏着线缆、拓扑、配置的坑。本篇建立一套从单机到全集群的分层基准测试体系——定义预期值、自动化执行、存储基线、退化检测、验收闭环——让 256 卡集群上线前真正"验得过"。
GPU 集群上线前最怕的不是"跑不快",而是"不知道能跑多快"。没有基准,就没有验收标准;没有验收标准,上线后出了性能问题就无从判断到底是集群本身的问题、还是用户代码的问题。基准测试体系的核心目标:在集群交付前,逐层建立可复现、可对比、可告警的性能基线。
一个 N 卡集群的性能不是线性叠加的。从单卡到全集群,中间隔着 NVLink、PCIe、RDMA、交换机多层拓扑,每一层都可能成为瓶颈。因此基准测试必须分层进行,从最内层往外逐层扩展,每一层都有明确的预期值和通过标准。
| 层级 | 范围 | 核心指标 | 主要工具 | 预期值来源 |
|---|---|---|---|---|
| L0 单卡 | 单 GPU | HBM 带宽、FP16/FP32 算力、PCIe Gen 带宽 | gpu-burn、dcgmi、nvidia-smi | GPU 型号规格书 |
| L1 单机 | 单节点 8 GPU | NVLink 双向带宽、单机 AllReduce/AllGather | nccl-tests、nvidia-smi nvlink | NVLink 版本规格 |
| L2 多机 | 2~16 节点 | RDMA 带宽/延迟、跨节点 AllReduce | perftest、nccl-tests | 网卡型号 + 网络拓扑 |
| L3 全集群 | 全部节点 | 全量 AllReduce/AllGather/ReduceScatter、端到端 | nccl-tests、自定义调度脚本 | L2 结果外推 + 厂商参考 |
上层测试必须基于下层全部通过。如果 L1 单机 NVLink 带宽就不达标,L2 多机测试的结果没有意义——你无法区分瓶颈来自节点内还是节点间。每层测试失败时,停下来修复,不要带着已知问题往上测。
基准测试不是"上线前跑一次就完"的事。它贯穿集群的整个生命周期:
单机基准是整个体系的地基。一台 8×H100 节点内部就有 GPU→HBM、GPU→GPU(NVLink)、GPU→CPU(PCIe) 三条数据通路,加上单机集合通信,构成了 L0 和 L1 两层基线。
HBM(高带宽存储器)带宽决定了大模型推理和训练的内存搬运速度。H100 H3 的 HBM 带宽规格为 3.35 TB/s,实测应达到规格的 90% 以上。
# HBM 带宽测试 —— 使用 gpu-burn 的 copy 峰值模式
# gpu-burn 默认做矩阵乘法,这里用 -d 指定时长,观察 HBM 利用率
git clone https://github.com/wilicc/gpu-burn.git
cd gpu-burn && make
# 运行 30 秒的 copy burn,同时用 DCGM 监控 HBM 带宽
./gpu_burn 30 &
dcgmi dmon -e 1004,1005 -d 30
# 1004 = DRAM_ACTIVE_BW (HBM 读+写带宽, MB/s)
# 1005 = SM_ACTIVE (SM 占用率, %)
# 或者用 CUDA samples 中的 bandwidthTest
/usr/local/cuda/extras/demo_suite/bandwidthTest --device=all --mode=range --start=0 --end=7
# FP16 算力测试 —— 使用 gpu-burn 矩阵乘法模式
# H100 SXM FP16 算力规格: 1979 TFLOPS (含稀疏), 989 TFLOPS (不含稀疏)
./gpu_burn 60
# 同时监控 DCGM FP16 活跃度
dcgmi dmon -e 1002 -d 60
# 1002 = PIPE_TENSOR_ACTIVE (Tensor Core 利用率)
# 更精确的算力测试用 cutlass 或 NVIDIA 的 cuda-samples
# 编译并运行 sgemm/hgemm benchmark
cd /usr/local/cuda/samples/7_CUDALibraries/batchCUBLAS
make && ./batchCUBLAS -m=4096 -n=4096 -k=4096
GPU 与 CPU 之间的 PCIe 带宽影响 CPU→GPU 的数据搬运(如模型加载、CPU offload)。H100 PCIe Gen5 x16 理论双向带宽 128 GB/s,实测单向应达到 90% 以上。
# PCIe 带宽测试 —— 使用 NVIDIA 的 p2pBandwidthLatencyTest
# 包含在 CUDA samples 中
cd /usr/local/cuda/extras/demo_suite/
./p2pBandwidthLatencyTest
# 或用 perftest 测 PCIe RDMA(如果走 RNIC)
# 查看当前 PCIe 拓扑和链路速率
nvidia-smi topo -m
# 输出示例:
# GPU0 GPU1 GPU2 GPU3 GPU4 GPU5 GPU6 GPU7 CPU0 CPU1
# GPU0 X NV12 NV12 NV12 NV12 NV12 NV12 NV12 PIX SYS
# GPU1 NV12 X NV12 NV12 NV12 NV12 NV12 NV12 PIX SYS
# ...
# NV12 = NVLink 12 链路, PIX = 同 PCIe bridge, SYS = 跨 NUMA
# 确认 PCIe 链路宽度和速率
nvidia-smi query-gpu=pci.link_gen.current,pci.link_width.current --format=csv
# 输出: Gen5, 16bit (期望值)
NVLink 是节点内 GPU 间的高速互联。H100 SXM5 的 NVLink 单向带宽 50 GB/s,8 卡全互联共 18 条 NVLink/GPU。用 p2pBandwidthLatencyTest 可以测出每对 GPU 之间的 P2P 带宽。
# NVLink P2P 带宽测试 —— 全对全
cd /usr/local/cuda/extras/demo_suite/
./p2pBandwidthLatencyTest
# 输出会包含 Unidirectional 和 Bidirectional 带宽矩阵
# 重点关注 GPU0-GPU1, GPU0-GPU4 等跨 NVSwitch 的对
# 更直观的方式:用 nvidia-smi 查看 NVLink 状态
nvidia-smi nvlink -s
# 查看每条 NVLink 的连接状态和速率
nvidia-smi nvlink -g 0 -l
# 查看 GPU0 的所有 NVLink 链路统计
# H100 SXM5: 每卡 18 条 NVLink, 每条 50 GB/s 单向
单机集合通信是训练框架最频繁调用的操作。用 nccl-tests 测量不同消息大小下的 AllReduce 和 AllGather 带宽。
# 编译 nccl-tests
git clone https://github.com/NVIDIA/nccl-tests.git
cd nccl-tests
make CUDA_HOME=/usr/local/cuda NCCL_HOME=/usr/local/nccl
# 单机 8 卡 AllReduce 测试
# -b 8: 起始消息 8 字节
# -e 1G: 最大消息 1 GB
# -f 2: 每步翻 2 倍
# -g 8: 8 个 GPU
# -w 5: 预热 5 次, -n 20: 正式测 20 次
./build/all_reduce_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20 \
2>&1 | tee /tmp/allreduce_single_node.log
# 单机 8 卡 AllGather 测试
./build/all_gather_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20 \
2>&1 | tee /tmp/allgather_single_node.log
| 测试项 | 指标 | H100 SXM5 预期值 | A100 SXM4 预期值 | 达成率要求 |
|---|---|---|---|---|
| HBM 带宽 | 读+写带宽 | ≥ 3.0 TB/s | ≥ 1.4 TB/s | ≥ 90% |
| FP16 算力 | Tensor Core TFLOPS | ≥ 1800 TFLOPS | ≥ 280 TFLOPS | ≥ 90% |
| PCIe Gen5 带宽 | 单向 | ≥ 115 GB/s | ≥ 23 GB/s (Gen4) | ≥ 90% |
| NVLink P2P | 单向带宽 | ≥ 45 GB/s | ≥ 45 GB/s | ≥ 90% |
| NVLink P2P | 双向带宽 | ≥ 90 GB/s | ≥ 90 GB/s | ≥ 90% |
| 单机 AllReduce (1GB) | busbw | ≥ 270 GB/s | ≥ 120 GB/s | ≥ 90% |
| 单机 AllGather (1GB) | busbw | ≥ 350 GB/s | ≥ 150 GB/s | ≥ 90% |
| 单机 ReduceScatter (1GB) | busbw | ≥ 350 GB/s | ≥ 150 GB/s | ≥ 90% |
每台节点的基准结果以 JSON 格式存储,包含节点信息、测试时间、所有指标值和通过状态,便于后续对比和退化检测。
#!/usr/bin/env python3
"""单机基准测试结果存储"""
import json, socket, subprocess, re, time
from pathlib import Path
def run_cmd(cmd):
r = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=300)
return r.stdout + r.stderr
def parse_nccl_output(output):
"""解析 nccl-tests 输出,提取最大消息的 busbw"""
lines = output.strip().split("\n")
results = {}
for line in lines:
if line.startswith("#") or not line.strip():
continue
parts = line.split()
if len(parts) >= 7:
size = int(parts[0])
busbw = float(parts[6])
results[size] = busbw
# 返回最大消息大小的带宽
if results:
max_size = max(results.keys())
return {"max_size_bytes": max_size, "busbw_gbps": results[max_size]}
return None
def benchmark_single_node():
"""执行单机基准测试并存储结果"""
node_name = socket.gethostname()
timestamp = time.strftime("%Y%m%d_%H%M%S")
result = {
"node": node_name,
"timestamp": timestamp,
"gpu_type": "H100-SXM5",
"gpu_count": 8,
"tests": {}
}
# 1. HBM 带宽
hbm_out = run_cmd("dcgmi dmon -e 1004 -d 10 -j")
result["tests"]["hbm_bandwidth"] = {"raw": hbm_out[:500], "status": "pass"}
# 2. NVLink P2P
nvlink_out = run_cmd("/usr/local/cuda/extras/demo_suite/p2pBandwidthLatencyTest")
result["tests"]["nvlink_p2p"] = {"raw": nvlink_out[:2000], "status": "pass"}
# 3. 单机 AllReduce
ar_cmd = "./build/all_reduce_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20"
ar_out = run_cmd(ar_cmd)
ar_parsed = parse_nccl_output(ar_out)
result["tests"]["allreduce"] = {
"parsed": ar_parsed,
"expected_busbw": 270, # GB/s
"status": "pass" if ar_parsed and ar_parsed["busbw_gbps"] >= 270 else "fail"
}
# 4. 单机 AllGather
ag_cmd = "./build/all_gather_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20"
ag_out = run_cmd(ag_cmd)
ag_parsed = parse_nccl_output(ag_out)
result["tests"]["allgather"] = {
"parsed": ag_parsed,
"expected_busbw": 350, # GB/s
"status": "pass" if ag_parsed and ag_parsed["busbw_gbps"] >= 350 else "fail"
}
# 总体状态
all_pass = all(t["status"] == "pass" for t in result["tests"].values())
result["overall_status"] = "PASS" if all_pass else "FAIL"
# 存储
store_dir = Path(f"/data/benchmark/{node_name}")
store_dir.mkdir(parents=True, exist_ok=True)
store_file = store_dir / f"single_node_{timestamp}.json"
store_file.write_text(json.dumps(result, indent=2))
print(f"基准结果已存储: {store_file}")
print(f"总体状态: {result['overall_status']}")
return result
if __name__ == "__main__":
benchmark_single_node()
双机基准是多机通信的第一道关。两台节点之间通过 RDMA(RoCE 或 InfiniBand)互联,GPU 间的集合通信跨节点走网络。如果双机就不达标,全集群必然不达标。
先用 perftest(来自 rdma-core 包)测试网卡层面的 RDMA 带宽,排除 GPU 层面的干扰。这是定位"是网络问题还是 GPU/NCCL 问题"的第一步。
# === 节点 A (server 端) ===
# 查询可用 RDMA 设备
ibv_devinfo
# 输出示例:
# hca_id: mlx5_0
# transport: InfiniBand (0)
# fw_ver: 28.39.1002
# port: 1
# state: PORT_ACTIVE (4)
# max_mtu: 4096 (5)
# active_width: 4X (2)
# active_speed: 100 Gbps (16)
# 获取 GID index
ibv_query_gid mlx5_0 1 0
# GID[0]: fe80::1234:5678:9abc:def0
# Server 端启动 RDMA 写带宽测试
# -d: 设备名, -p: 端口, --report_gbits: 以 Gbps 报告
ib_write_bw -d mlx5_0 -p 18515 --report_gbits -s 4194304
# === 节点 B (client 端) ===
# 连接 Server 端,测试 RDMA 写带宽
ib_write_bw -d mlx5_0 -p 18515 --report_gbits -s 4194304 \
nodeA-ib0 # nodeA 的 IB 接口名或 IP
# 同理测试 RDMA 读带宽和双向带宽
# Server: ib_read_bw -d mlx5_0 -p 18516 --report_gbits
# Client: ib_read_bw -d mlx5_0 -p 18516 --report_gbits nodeA-ib0
# 双向带宽(最接近训练场景)
# Server: ib_write_bw -d mlx5_0 -p 18517 --report_gbits -b
# Client: ib_write_bw -d mlx5_0 -p 18517 --report_gbits -b nodeA-ib0
# RDMA 延迟测试 —— 小消息 2 字节
# Server 端
ib_write_lat -d mlx5_0 -p 18520 -s 2
# Client 端
ib_write_lat -d mlx5_0 -p 18520 -s 2 nodeA-ib0
# 输出示例:
# #bytes #iterations t_min[usec] t_max[usec] t_typical[usec]
# 2 1000000 1.82 2.94 1.91
# 200G RoCE 延迟典型值 ≈ 1.9 μs
# InfiniBand 200G 延迟典型值 ≈ 1.5 μs
# 如果延迟 > 5 μs,需要排查:
# - PFC/ECN 配置是否正确
# - 交换机缓冲区设置
# - NUMA 亲和性(网卡和 GPU 是否同 NUMA)
网卡层面 RDMA 正常后,接下来测 GPU 层面的跨节点集合通信。NCCL 通过 RDMA 实现 GPU 间的跨节点 P2P,这是 AllReduce 的基础。
# 跨节点 16 GPU AllReduce (2 节点 × 8 GPU)
# 需要设置 NCCL 的 RDMA 通信参数
export NCCL_DEBUG=INFO
export NCCL_IB_DISABLE=0 # 启用 IB/RoCE
export NCCL_IB_HCA=mlx5_0 # 指定网卡
export NCCL_NET_GDR_LEVEL=PHB # GPU Direct RDMA 级别
export NCCL_SOCKET_IFNAME=eth0 # 控制面网卡
# 使用 MPI 或 PyTorch 启动跨节点测试
# 方式 1: 使用 mpirun (需要 OpenMPI)
mpirun -np 2 -H nodeA:1,nodeB:1 \
-x NCCL_DEBUG -x NCCL_IB_DISABLE -x NCCL_IB_HCA \
-x NCCL_NET_GDR_LEVEL -x NCCL_SOCKET_IFNAME \
./build/all_reduce_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20
# 方式 2: 使用 PyTorch 的 torchrun
torchrun --nproc_per_node=8 --nnodes=2 \
--node_rank=0 --rdzv_endpoint=nodeA:29500 \
nccl_bench.py --op allreduce --min_size 8 --max_size 1073741824
| 测试项 | 指标 | 200G RoCE/IB 预期 | 400G RoCE 预期 | 达成率要求 |
|---|---|---|---|---|
| RDMA 写带宽 (单向) | GB/s | ≥ 23 | ≥ 46 | ≥ 95% |
| RDMA 写带宽 (双向) | GB/s | ≥ 24 | ≥ 48 | ≥ 95% |
| RDMA 延迟 | μs | ≤ 2.5 | ≤ 2.0 | ≤ 1.5×典型值 |
| 跨节点 P2P (GPUDirect) | GB/s | ≥ 22 | ≥ 45 | ≥ 90% |
| 跨节点 AllReduce (1GB, 16GPU) | busbw GB/s | ≥ 170 | ≥ 250 | ≥ 90% |
| 跨节点 AllGather (1GB, 16GPU) | busbw GB/s | ≥ 180 | ≥ 280 | ≥ 90% |
#!/usr/bin/env python3
"""双机基准测试结果存储 —— 全对测试"""
import json, time, subprocess
from pathlib import Path
from itertools import combinations
NODE_LIST = [f"gpu-node-{i:02d}" for i in range(1, 33)] # 32 节点
def run_pair_benchmark(node_a, node_b):
"""对一对节点执行双机基准测试"""
result = {
"pair": [node_a, node_b],
"timestamp": time.strftime("%Y%m%d_%H%M%S"),
"tests": {}
}
# RDMA 带宽
cmd = f"ssh {node_a} 'ib_write_bw -d mlx5_0 -p 18515 --report_gbits -s 4194304 -b'"
# ... (实际执行省略,结构同单机)
result["tests"]["rdma_bw"] = {"value_gbps": 199.87, "expected": 190, "status": "pass"}
# RDMA 延迟
result["tests"]["rdma_lat"] = {"value_us": 1.91, "expected": 2.5, "status": "pass"}
# 跨节点 AllReduce
result["tests"]["cross_ar"] = {"value_gbps": 187, "expected": 170, "status": "pass"}
all_pass = all(t["status"] == "pass" for t in result["tests"].values())
result["overall_status"] = "PASS" if all_pass else "FAIL"
return result
def benchmark_all_pairs():
"""全对双机测试"""
results = []
for node_a, node_b in combinations(NODE_LIST, 2):
r = run_pair_benchmark(node_a, node_b)
results.append(r)
if r["overall_status"] != "PASS":
print(f"⚠ {node_a} ↔ {node_b}: {r['overall_status']}")
store_dir = Path("/data/benchmark/cluster")
store_dir.mkdir(parents=True, exist_ok=True)
store_file = store_dir / f"pair_benchmark_{time.strftime('%Y%m%d_%H%M%S')}.json"
store_file.write_text(json.dumps(results, indent=2))
total = len(results)
passed = sum(1 for r in results if r["overall_status"] == "PASS")
print(f"双机基准完成: {passed}/{total} 通过")
return results
双机测试通过后,扩展到多机。多机基准的核心挑战是组合爆炸——32 个节点有 C(32,2)=496 对,全量测试耗时巨大。因此需要全连接矩阵策略和 N 选 K 抽样策略。
全连接矩阵是对所有节点对逐一执行双机 RDMA 带宽测试,生成一个 N×N 的带宽矩阵。矩阵中对角线为节点内 NVLink 带宽,非对角线为跨节点 RDMA 带宽。理想情况下所有非对角线值应一致。
#!/bin/bash
# 全连接矩阵 RDMA 带宽测试
# 生成 N×N 带宽矩阵,输出为 CSV
NODE_FILE="/data/benchmark/nodes.txt" # 节点列表,每行一个
OUTPUT_DIR="/data/benchmark/matrix/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$OUTPUT_DIR"
NODES=($(cat "$NODE_FILE"))
N=${#NODES[@]}
MATRIX_FILE="$OUTPUT_DIR/bandwidth_matrix.csv"
# 写表头
echo -n "node" > "$MATRIX_FILE"
for j in "${!NODES[@]}"; do
echo -n ",${NODES[$j]}" >> "$MATRIX_FILE"
done
echo "" >> "$MATRIX_FILE"
# 逐对测试(可并行化)
for i in "${!NODES[@]}"; do
echo -n "${NODES[$i]}" >> "$MATRIX_FILE"
for j in "${!NODES[@]}"; do
if [ "$i" -eq "$j" ]; then
echo -n ",0" >> "$MATRIX_FILE" # 对角线
elif [ "$i" -lt "$j" ]; then
# 测 i→j 方向
BW=$(ssh "${NODES[$i]}" \
"ib_write_bw -d mlx5_0 -p $((18500+i*100+j)) \
--report_gbits -s 4194304 -t 5 \
${NODES[$j]}-ib0 2>&1 | grep 'BW average' | awk '{print \$NF}'")
echo -n ",$BW" >> "$MATRIX_FILE"
else
echo -n ",-" >> "$MATRIX_FILE" # 对称,跳过
fi
done
echo "" >> "$MATRIX_FILE"
echo "完成节点 ${NODES[$i]} ($((i+1))/$N)"
done
echo "全连接矩阵已生成: $MATRIX_FILE"
当节点数超过 32 时,全对测试耗时过长(C(64,2)=2016 对,每对 30 秒就需要 17 小时)。N 选 K 抽样策略从 N 个节点中选 K 个做全量测试,用统计方法推断全集群状态。
#!/usr/bin/env python3
"""N 选 K 抽样测试策略"""
import random, json, subprocess, time
from itertools import combinations
from pathlib import Path
def n_choose_k_sampling(all_nodes, k=16, strategy="random"):
"""
从 all_nodes 中选 k 个节点做全量测试
strategy:
- random: 随机选 K 个
- rack: 每个机架选代表
- stride: 等间隔选
"""
n = len(all_nodes)
if strategy == "random":
selected = random.sample(all_nodes, k)
elif strategy == "stride":
step = n // k
selected = all_nodes[::step][:k]
elif strategy == "rack":
# 假设节点名包含机架号: gpu-r{rack}-n{node}
racks = {}
for node in all_nodes:
rack = node.split("-")[1] # r01, r02, ...
racks.setdefault(rack, []).append(node)
selected = []
for rack, nodes in racks.items():
selected.append(random.choice(nodes)) # 每架选一个
selected = selected[:k]
return selected
def run_k_node_benchmark(nodes):
"""对 K 个节点执行全量集合通信测试"""
n = len(nodes)
results = {"nodes": nodes, "n_gpus": n * 8, "tests": []}
# AllReduce
host_spec = ",".join(f"{n}:1" for n in nodes)
cmd = (
f"mpirun -np {n} -H {host_spec} "
f"-x NCCL_IB_DISABLE=0 -x NCCL_IB_HCA=mlx5_0 "
f"-x NCCL_NET_GDR_LEVEL=PHB "
f"./build/all_reduce_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 10"
)
output = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=600)
results["tests"].append({
"op": "allreduce",
"n_nodes": n,
"output": output.stdout[-2000:],
"status": "pass" # 解析后判断
})
# AllGather, ReduceScatter, Broadcast 同理
for op in ["all_gather", "reduce_scatter", "broadcast"]:
cmd = (
f"mpirun -np {n} -H {host_spec} "
f"-x NCCL_IB_DISABLE=0 -x NCCL_IB_HCA=mlx5_0 "
f"./build/{op}_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 10"
)
output = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=600)
results["tests"].append({
"op": op,
"n_nodes": n,
"output": output.stdout[-2000:],
})
return results
# 主流程
all_nodes = [f"gpu-r{r:02d}-n{n:02d}" for r in range(1, 17) for n in range(1, 17)]
# 256 卡 = 32 节点 = 16 机架 × 2 节点/架
# 抽样: 选 16 节点做全量测试
selected = n_choose_k_sampling(all_nodes, k=16, strategy="rack")
print(f"抽样节点: {selected}")
results = run_k_node_benchmark(selected)
store = Path(f"/data/benchmark/sampling/{time.strftime('%Y%m%d_%H%M%S')}.json")
store.parent.mkdir(parents=True, exist_ok=True)
store.write_text(json.dumps(results, indent=2))
print(f"结果已存储: {store}")
对选定的 K 个节点,执行全部四种集合通信操作的测试,覆盖从小消息(8B)到大消息(1GB)的完整范围。
#!/bin/bash
# 集合通信全量测试 —— 4 种操作 × 多种消息大小
# 在 K 个节点上并行执行
NODES="gpu-r01-n01,gpu-r02-n01,gpu-r03-n01,gpu-r04-n01,\
gpu-r05-n01,gpu-r06-n01,gpu-r07-n01,gpu-r08-n01,\
gpu-r09-n01,gpu-r10-n01,gpu-r11-n01,gpu-r12-n01,\
gpu-r13-n01,gpu-r14-n01,gpu-r15-n01,gpu-r16-n01"
K=16
HOST_SPEC=""
IFS=',' read -ra NODE_ARR <<< "$NODES"
for node in "${NODE_ARR[@]}"; do
HOST_SPEC="${HOST_SPEC}${node}:1,"
done
HOST_SPEC=${HOST_SPEC%,} # 去尾逗号
OUTPUT_DIR="/data/benchmark/collective/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$OUTPUT_DIR"
# 四种集合通信操作
for OP in all_reduce_perf all_gather_perf reduce_scatter_perf broadcast_perf; do
echo "=== 测试 $OP ($K 节点) ==="
mpirun -np $K -H "$HOST_SPEC" \
-x NCCL_IB_DISABLE=0 \
-x NCCL_IB_HCA=mlx5_0 \
-x NCCL_NET_GDR_LEVEL=PHB \
-x NCCL_SOCKET_IFNAME=eth0 \
-x NCCL_DEBUG=WARN \
./build/$OP -b 8 -e 1G -f 2 -g 8 -w 5 -n 10 \
2>&1 | tee "$OUTPUT_DIR/${OP}.log"
echo ""
done
echo "集合通信全量测试完成,结果在 $OUTPUT_DIR"
| 测试项 | 节点数 | GPU 数 | 200G 预期 busbw | 400G 预期 busbw | 达成率 |
|---|---|---|---|---|---|
| AllReduce (1GB) | 4 | 32 | ≥ 120 GB/s | ≥ 200 GB/s | ≥ 85% |
| AllReduce (1GB) | 8 | 64 | ≥ 90 GB/s | ≥ 160 GB/s | ≥ 85% |
| AllReduce (1GB) | 16 | 128 | ≥ 55 GB/s | ≥ 110 GB/s | ≥ 85% |
| AllReduce (1GB) | 32 | 256 | ≥ 30 GB/s | ≥ 65 GB/s | ≥ 80% |
| AllGather (1GB) | 16 | 128 | ≥ 60 GB/s | ≥ 120 GB/s | ≥ 85% |
| ReduceScatter (1GB) | 16 | 128 | ≥ 60 GB/s | ≥ 120 GB/s | ≥ 85% |
| Broadcast (1GB) | 16 | 128 | ≥ 50 GB/s | ≥ 100 GB/s | ≥ 85% |
这是正常现象。AllReduce 的 busbw 随节点数增加而降低,因为环形通信的延迟与节点数成正比。不要期望 32 节点的 AllReduce 带宽和 2 节点一样。预期值表中的数字是根据网络拓扑和 NVLink+RDMA 叠加效应计算的理论值,实测应在 80% 以上。
全集群验收是基准测试的最终闭环。它不是"跑一个大 AllReduce 就完",而是一个结构化的 6 步流程,每一步都有明确的输入、输出和通过标准。
确认所有节点操作系统、驱动、CUDA、NCCL 版本一致;确认网络拓扑与设计文档一致;确认 GPU 拓扑(nvidia-smi topo -m)每节点相同;确认 RDMA 设备状态全部 PORT_ACTIVE。任何不一致在此步骤就要解决,不带着环境问题进入测试。
对每个节点的每张 GPU 执行 HBM 带宽和算力测试。256 卡集群 = 32 节点 × 8 卡,可并行执行,每节点约 5 分钟。全部通过后进入下一层。如有 GPU 不达标,标记并走 RMA 流程更换。
对每个节点执行 NVLink P2P 带宽和单机 AllReduce/AllGather 测试。32 节点可并行执行,每节点约 10 分钟。全部通过后进入多机测试。
先执行全连接矩阵 RDMA 带宽测试(32 节点 = 496 对,约 4 小时),生成带宽矩阵排查异常对。再执行 N 选 K(K=16)集合通信全量测试,验证多机集合通信性能。异常对需要定位修复后重测。
在全部 32 节点 256 GPU 上执行 AllReduce、AllGather、ReduceScatter 全量测试。这是最终的性能验收——全集群 AllReduce busbw 是否达到预期。同时执行端到端训练模拟(如用 Megatron-LM 跑 10 步 GPT 模型),验证真实训练场景下的 MFU(Model FLOPs Utilization)。
汇总所有层级的测试结果,生成验收报告(包含通过/不通过状态、所有指标值、异常项及修复记录)。全部通过则签署验收确认,将基线数据归档为初始版本。不通过则列出所有未通过项,制定修复计划。
| 检查项 | 层级 | 范围 | 通过标准 | 状态 |
|---|---|---|---|---|
| 驱动/CUDA/NCCL 版本一致 | 环境 | 全节点 | 版本完全一致 | ✅ |
| GPU 拓扑一致 | 环境 | 全节点 | nvidia-smi topo -m 输出一致 | ✅ |
| RDMA 设备状态 | 环境 | 全节点 | 全部 PORT_ACTIVE | ✅ |
| HBM 带宽 | L0 | 全 GPU | ≥ 3.0 TB/s | ✅ |
| GPU 算力 | L0 | 全 GPU | ≥ 1800 TFLOPS (FP16) | ✅ |
| NVLink P2P 带宽 | L1 | 全节点 | ≥ 45 GB/s 单向 | ✅ |
| 单机 AllReduce | L1 | 全节点 | ≥ 270 GB/s busbw | ✅ |
| RDMA 带宽矩阵 | L2 | 全节点对 | ≥ 190 Gb/s, 方差 < 5% | ✅ |
| 多机 AllReduce (16节点) | L2 | N选K | ≥ 55 GB/s busbw | ✅ |
| 全集群 AllReduce (32节点) | L3 | 全集群 | ≥ 30 GB/s busbw | ✅ |
| 端到端训练 MFU | L3 | 全集群 | ≥ 45% (GPT 175B) | ✅ |
① 环境检查全部一致;② L0 全 GPU 达标率 100%;③ L1 全节点达标率 100%;④ L2 全连接矩阵无异常对(所有对带宽 ≥ 预期值,方差 < 5%);⑤ L3 全集群 AllReduce busbw ≥ 预期值;⑥ 端到端训练 MFU ≥ 基线要求;⑦ 连续 3 次全量测试结果一致(稳定性验证)。
单点不通过(个别 GPU/节点):标记故障节点,走 RMA 或维修流程,修复后对该节点及其关联对重测。系统性不通过(多节点同类异常):停止验收,排查共因(驱动版本、交换机配置、线缆批次),修复后从 Step 1 重新开始。性能边缘(达标但接近下限):记录为"观察项",在运维监控期加密监测频率,观察是否进一步退化。
256 卡集群的全量基准测试如果手动执行,需要数天且容易出错。自动化是让基准测试可重复、可回归、可纳入 CI 的关键。
#!/usr/bin/env python3
"""
集群基准测试自动化框架
支持分层执行、并行调度、结果收集、报告生成
"""
import json, time, subprocess, logging, argparse
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import dataclass, field
from typing import List, Dict, Optional
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
log = logging.getLogger("benchmark")
@dataclass
class BenchmarkTask:
name: str
layer: str # L0, L1, L2, L3
command: str
expected: dict # 预期值
timeout: int = 600
depends_on: List[str] = field(default_factory=list)
@dataclass
class BenchmarkResult:
task_name: str
layer: str
status: str # pass, fail, skip
metrics: dict
raw_output: str
duration: float
timestamp: str
class ClusterBenchmark:
def __init__(self, node_file, output_dir="/data/benchmark"):
self.nodes = Path(node_file).read_text().strip().split("\n")
self.output_dir = Path(output_dir) / time.strftime("%Y%m%d_%H%M%S")
self.output_dir.mkdir(parents=True, exist_ok=True)
self.results: List[BenchmarkResult] = []
def define_tasks(self) -> List[BenchmarkTask]:
"""定义所有基准测试任务"""
tasks = []
# L0: 单卡 HBM 带宽(每节点一个任务,可并行)
for node in self.nodes:
tasks.append(BenchmarkTask(
name=f"hbm_bw_{node}",
layer="L0",
command=f"ssh {node} 'dcgmi dmon -e 1004 -d 10 -j'",
expected={"min_bw_gbps": 3000},
timeout=120,
))
# L1: 单机 AllReduce(每节点一个任务,可并行)
for node in self.nodes:
tasks.append(BenchmarkTask(
name=f"single_ar_{node}",
layer="L1",
command=f"ssh {node} 'cd /opt/nccl-tests && "
f"./build/all_reduce_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20'",
expected={"min_busbw_gbps": 270},
timeout=300,
depends_on=[f"hbm_bw_{node}"],
))
# L2: 全连接矩阵(单任务,内部并行)
tasks.append(BenchmarkTask(
name="rdma_matrix",
layer="L2",
command=f"/opt/benchmark/scripts/rdma_matrix.sh "
f"--node-file /data/benchmark/nodes.txt "
f"--output {self.output_dir}/rdma_matrix.csv",
expected={"min_bw_gbps": 190, "max_variance_pct": 5},
timeout=14400, # 4 小时
depends_on=[f"single_ar_{n}" for n in self.nodes],
))
# L3: 全集群 AllReduce
tasks.append(BenchmarkTask(
name="cluster_allreduce",
layer="L3",
command=f"/opt/benchmark/scripts/cluster_ar.sh "
f"--nodes {','.join(self.nodes)} "
f"--output {self.output_dir}/cluster_ar.log",
expected={"min_busbw_gbps": 30},
timeout=1800,
depends_on=["rdma_matrix"],
))
return tasks
def run_task(self, task: BenchmarkTask) -> BenchmarkResult:
"""执行单个基准测试任务"""
start = time.time()
log.info(f"开始执行: {task.name} (Layer {task.layer})")
try:
r = subprocess.run(
task.command, shell=True,
capture_output=True, text=True, timeout=task.timeout
)
duration = time.time() - start
metrics = self.parse_output(r.stdout, task)
status = self.judge(metrics, task.expected)
result = BenchmarkResult(
task_name=task.name, layer=task.layer,
status=status, metrics=metrics,
raw_output=r.stdout[-5000:], duration=duration,
timestamp=time.strftime("%Y%m%d_%H%M%S"),
)
log.info(f"完成: {task.name} → {status} ({duration:.1f}s)")
except subprocess.TimeoutExpired:
result = BenchmarkResult(
task_name=task.name, layer=task.layer,
status="fail", metrics={}, raw_output="TIMEOUT",
duration=task.timeout, timestamp=time.strftime("%Y%m%d_%H%M%S"),
)
log.error(f"超时: {task.name}")
self.results.append(result)
return result
def parse_output(self, output, task):
"""解析测试输出,提取指标"""
metrics = {}
if "all_reduce_perf" in task.command or "all_gather" in task.command:
lines = [l for l in output.split("\n") if l and not l.startswith("#")]
if lines:
last = lines[-1].split()
if len(last) >= 7:
metrics["busbw_gbps"] = float(last[6])
metrics["msg_size"] = int(last[0])
return metrics
def judge(self, metrics, expected):
"""判断是否通过"""
if not metrics or not expected:
return "skip"
for key, threshold in expected.items():
actual_key = key.replace("min_", "").replace("max_", "")
if actual_key in metrics:
if key.startswith("min_") and metrics[actual_key] < threshold:
return "fail"
return "pass"
def execute(self, parallel_per_layer=True):
"""分层执行所有任务"""
tasks = self.define_tasks()
results_by_name = {}
for layer in ["L0", "L1", "L2", "L3"]:
layer_tasks = [t for t in tasks if t.layer == layer]
log.info(f"=== Layer {layer}: {len(layer_tasks)} 个任务 ===")
# 检查依赖
runnable = []
for t in layer_tasks:
deps_ok = all(
results_by_name.get(d, None) and
results_by_name[d].status == "pass"
for d in t.depends_on
)
if deps_ok:
runnable.append(t)
else:
log.warning(f"跳过 {t.name}(依赖未通过)")
results_by_name[t.name] = BenchmarkResult(
task_name=t.name, layer=layer, status="skip",
metrics={}, raw_output="DEP_NOT_MET",
duration=0, timestamp=time.strftime("%Y%m%d_%H%M%S"),
)
# 执行(L0/L1 可并行,L2/L3 串行)
if parallel_per_layer and layer in ["L0", "L1"]:
with ThreadPoolExecutor(max_workers=8) as pool:
futures = {pool.submit(self.run_task, t): t for t in runnable}
for f in as_completed(futures):
r = f.result()
results_by_name[r.task_name] = r
else:
for t in runnable:
r = self.run_task(t)
results_by_name[r.task_name] = r
# 检查本层是否全部通过
layer_results = [results_by_name[t.name] for t in layer_tasks]
failed = [r for r in layer_results if r.status == "fail"]
if failed:
log.error(f"Layer {layer} 有 {len(failed)} 个任务失败,停止")
break
self.generate_report()
return self.results
def generate_report(self):
"""生成验收报告"""
report = {
"cluster": f"{len(self.nodes)} nodes",
"timestamp": time.strftime("%Y%m%d_%H%M%S"),
"total_tasks": len(self.results),
"passed": sum(1 for r in self.results if r.status == "pass"),
"failed": sum(1 for r in self.results if r.status == "fail"),
"skipped": sum(1 for r in self.results if r.status == "skip"),
"results": [
{
"task": r.task_name, "layer": r.layer,
"status": r.status, "metrics": r.metrics,
"duration_s": round(r.duration, 1),
} for r in self.results
],
}
report_file = self.output_dir / "report.json"
report_file.write_text(json.dumps(report, indent=2))
log.info(f"报告已生成: {report_file}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--node-file", default="/data/benchmark/nodes.txt")
parser.add_argument("--output-dir", default="/data/benchmark")
args = parser.parse_args()
bench = ClusterBenchmark(args.node_file, args.output_dir)
bench.execute()
自动化框架的调度策略遵循分层依赖原则:L0/L1 可以全节点并行(互不依赖),L2 全连接矩阵内部可以按节点对并行,L3 全集群测试必须串行。结果收集采用 JSON 统一格式,每层测试完成后立即写入磁盘,避免中途失败丢失数据。
# .gitlab-ci.yml —— 基准测试 CI 集成
# 每次驱动/NCCL 升级后触发全量回归
stages:
- pre_check
- benchmark_l0l1
- benchmark_l2
- benchmark_l3
- report
variables:
BENCH_DIR: "/data/benchmark/ci/$CI_PIPELINE_ID"
pre_check:
stage: pre_check
script:
- python3 /opt/benchmark/scripts/pre_check.py --node-file /data/nodes.txt
only:
- schedules # 定时触发
- tags # 版本发布触发
benchmark_l0l1:
stage: benchmark_l0l1
script:
- python3 /opt/benchmark/run.py --layers L0,L1 --parallel
artifacts:
paths:
- $BENCH_DIR/L0/
- $BENCH_DIR/L1/
needs: [pre_check]
benchmark_l2:
stage: benchmark_l2
script:
- python3 /opt/benchmark/run.py --layers L2 --matrix --sampling-k 16
artifacts:
paths:
- $BENCH_DIR/L2/
needs: [benchmark_l0l1]
timeout: 5 hours
benchmark_l3:
stage: benchmark_l3
script:
- python3 /opt/benchmark/run.py --layers L3 --full-cluster
artifacts:
paths:
- $BENCH_DIR/L3/
needs: [benchmark_l2]
timeout: 2 hours
report:
stage: report
script:
- python3 /opt/benchmark/report.py --dir $BENCH_DIR --compare-baseline
- python3 /opt/benchmark/alert.py --dir $BENCH_DIR --webhook $ALERT_WEBHOOK
needs: [benchmark_l3]
when: always # 即使前面失败也生成报告
基准测试的价值在于"可对比"。如果测完就扔,下次出问题时没有参照系,就无法判断"是变差了还是本来就这样"。基准数据管理是让测试结果变成可长期维护、可版本对比、可自动检测退化的数据资产。
所有基准数据以 JSON 格式存储,按层级和时间组织目录结构。每次全量基准测试生成一个版本,版本间可 diff 对比。
# 基准数据目录结构
/data/benchmark/
├── baseline/ # 官方基线(验收时生成,不修改)
│ ├── v1.0_20260101/ # 初始验收基线
│ │ ├── manifest.json # 版本清单
│ │ ├── L0/
│ │ │ ├── gpu-node-01.json
│ │ │ ├── gpu-node-02.json
│ │ │ └── ...
│ │ ├── L1/
│ │ │ ├── gpu-node-01.json
│ │ │ └── ...
│ │ ├── L2/
│ │ │ ├── rdma_matrix.csv
│ │ │ ├── pair_results.json
│ │ │ └── sampling_k16.json
│ │ └── L3/
│ │ ├── cluster_allreduce.json
│ │ ├── cluster_allgather.json
│ │ └── e2e_training.json
│ └── v1.1_20260315/ # 驱动升级后回归基线
│ └── ...
├── daily/ # 日常抽检数据
│ ├── 20260401/
│ ├── 20260402/
│ └── ...
└── ci/ # CI 触发的回归数据
├── pipeline_123/
└── ...
// manifest.json —— 基线版本清单
{
"version": "v1.0",
"date": "2026-01-01",
"cluster": "prod-gpu-256",
"nodes": 32,
"gpus": 256,
"gpu_type": "H100-SXM5",
"network": "200G-RoCE",
"driver_version": "550.54.15",
"cuda_version": "12.4",
"nccl_version": "2.20",
"layers": {
"L0": {"status": "PASS", "tests": 256, "passed": 256},
"L1": {"status": "PASS", "tests": 32, "passed": 32},
"L2": {"status": "PASS", "tests": 496, "passed": 496},
"L3": {"status": "PASS", "tests": 4, "passed": 4}
},
"overall": "PASS",
"signed_by": "ops-team",
"notes": "初始验收基线,全量通过"
}
#!/usr/bin/env python3
"""基准数据对比与退化检测"""
import json
from pathlib import Path
from dataclasses import dataclass
@dataclass
class Degradation:
metric: str
baseline_value: float
current_value: float
degradation_pct: float
severity: str # critical, warning, info
def load_baseline(version="v1.0"):
"""加载基线数据"""
base_dir = Path(f"/data/benchmark/baseline/{version}_*")
dirs = sorted(base_dir.parent.glob(f"{version}_*"))
if not dirs:
raise FileNotFoundError(f"基线版本 {version} 不存在")
return dirs[-1]
def compare_results(baseline_dir, current_dir, threshold_warn=5, threshold_critical=15):
"""对比基线与当前结果,检测退化"""
degradations = []
# 对比 L1 单机 AllReduce
for node_file in (current_dir / "L1").glob("*.json"):
node = node_file.stem
baseline_file = baseline_dir / "L1" / f"{node}.json"
if not baseline_file.exists():
continue
baseline = json.loads(baseline_file.read_text())
current = json.loads(node_file.read_text())
# 对比 AllReduce busbw
bl_ar = baseline.get("tests", {}).get("allreduce", {}).get("parsed", {})
cur_ar = current.get("tests", {}).get("allreduce", {}).get("parsed", {})
if bl_ar and cur_ar:
bl_bw = bl_ar.get("busbw_gbps", 0)
cur_bw = cur_ar.get("busbw_gbps", 0)
if bl_bw > 0:
deg_pct = (bl_bw - cur_bw) / bl_bw * 100
if deg_pct > threshold_warn:
severity = "critical" if deg_pct > threshold_critical else "warning"
degradations.append(Degradation(
metric=f"{node}.allreduce.busbw",
baseline_value=bl_bw,
current_value=cur_bw,
degradation_pct=round(deg_pct, 2),
severity=severity,
))
return degradations
def generate_degradation_report(degradations):
"""生成退化报告"""
if not degradations:
print("✅ 未检测到性能退化")
return
print(f"⚠ 检测到 {len(degradations)} 项退化:\n")
print(f"{'指标':<40} {'基线':>10} {'当前':>10} {'退化%':>8} {'级别':>10}")
print("-" * 80)
for d in sorted(degradations, key=lambda x: -x.degradation_pct):
print(f"{d.metric:<40} {d.baseline_value:>10.1f} "
f"{d.current_value:>10.1f} {d.degradation_pct:>8.2f} {d.severity:>10}")
# 告警
critical = [d for d in degradations if d.severity == "critical"]
if critical:
send_alert(critical)
def send_alert(critical_degradations):
"""发送严重退化告警"""
# 对接告警系统(飞书/钉钉/Prometheus Alertmanager)
msg = f"🚨 检测到 {len(critical_degradations)} 项严重性能退化 (>15%)"
for d in critical_degradations:
msg += f"\n {d.metric}: {d.baseline_value:.1f} → {d.current_value:.1f} ({d.degradation_pct:.1f}%)"
print(f"\n告警已发送: {msg}")
if __name__ == "__main__":
baseline = load_baseline("v1.0")
current = Path("/data/benchmark/daily/20260401")
degs = compare_results(baseline, current)
generate_degradation_report(degs)
将历次基准数据按时间排列,可以观察性能趋势——是稳定、缓慢退化、还是断崖式下降。趋势分析帮助在问题变成故障前提前预警。
检测到退化只是第一步,更重要的是定位原因、修复并验证。性能退化的原因从硬件到软件、从单点到系统性,需要一套结构化的排查流程。
| 类别 | 常见原因 | 影响范围 | 检测方式 |
|---|---|---|---|
| 硬件退化 | GPU 老化、HBM 故障前兆、NVLink 链路降级 | 单 GPU / 单节点 | L0/L1 对比基线 |
| 线缆/连接 | 光模块老化、线缆松动、交换机端口误配 | 节点对 / 机架间 | L2 带宽矩阵异常 |
| 软件变更 | 驱动升级、NCCL 版本变更、内核参数被覆盖 | 全集群 | 变更后全量回归 |
| 热退化 | 散热不足导致 GPU 降频、热节流 | 单节点 / 机架 | DCGM 温度+频率监控 |
| 配置漂移 | PFC/ECN 配置被改、NUMA 绑定失效 | 节点 / 全集群 | 配置审计 + 基准对比 |
| 拓扑变更 | 交换机故障导致路由绕行、节点下线 | 多节点 / 机架间 | L2 矩阵 + 拓扑对比 |
#!/bin/bash
# 性能退化定位脚本 —— 从全集群到单节点的逐层缩小范围
echo "=== 退化定位开始 ==="
# Step 1: 确认退化范围
# 对比当前 L3 全集群 AllReduce 与基线
CURRENT_BW=$(python3 /opt/benchmark/parse.py \
--file /data/benchmark/daily/today/L3/cluster_allreduce.json \
--metric busbw_gbps)
BASELINE_BW=$(python3 /opt/benchmark/parse.py \
--file /data/benchmark/baseline/v1.0/L3/cluster_allreduce.json \
--metric busbw_gbps)
DEG_PCT=$(python3 -c "print(round(($BASELINE_BW-$CURRENT_BW)/$BASELINE_BW*100, 2))")
echo "全集群 AllReduce: 基线=$BASELINE_BW, 当前=$CURRENT_BW, 退化=$DEG_PCT%"
# Step 2: 检查 L1 单机是否有退化(缩小到节点级)
echo "--- 检查各节点 L1 AllReduce ---"
for node in $(cat /data/nodes.txt); do
CUR=$(python3 /opt/benchmark/parse.py \
--file /data/benchmark/daily/today/L1/${node}.json \
--metric allreduce.busbw 2>/dev/null)
BL=$(python3 /opt/benchmark/parse.py \
--file /data/benchmark/baseline/v1.0/L1/${node}.json \
--metric allreduce.busbw 2>/dev/null)
if [ -n "$CUR" ] && [ -n "$BL" ]; then
PCT=$(python3 -c "print(round(($BL-$CUR)/$BL*100, 2))" 2>/dev/null)
if (( $(echo "$PCT > 5" | bc -l) )); then
echo " ⚠ $node: 基线=$BL, 当前=$CUR, 退化=${PCT}%"
fi
fi
done
# Step 3: 检查 L2 带宽矩阵异常对
echo "--- 检查 RDMA 带宽矩阵异常对 ---"
python3 /opt/benchmark/matrix_check.py \
--current /data/benchmark/daily/today/L2/rdma_matrix.csv \
--baseline /data/benchmark/baseline/v1.0/L2/rdma_matrix.csv \
--threshold 10 # 退化超 10% 的节点对
# Step 4: 对异常节点检查硬件状态
echo "--- 检查异常节点硬件状态 ---"
for node in $(cat /tmp/degraded_nodes.txt 2>/dev/null); do
echo " $node:"
ssh $node "nvidia-smi --query-gpu=index,temperature.gpu,clocks.current.sm,clocks.max.sm \
--format=csv,noheader"
ssh $node "nvidia-smi nvlink -s" | grep -v "Link 0.*Active"
ssh $node "ibstat" | grep -E "State|Phys"
done
# Step 5: 检查近期变更
echo "--- 近期变更记录 ---"
cat /var/log/cluster-changes.log | tail -20
echo "=== 定位完成,请根据以上信息判断退化原因 ==="
定位 → 修复 → 定向重测 → 全量回归。修复后先对受影响范围执行定向基准测试(如更换了某节点的线缆,只需测该节点的 L1 和其关联的 L2 对),确认修复有效后再触发全量回归确保没有引入新问题。
验收标准是基准测试的"判卷规则"。标准定得太松,集群带着性能隐患上线;定得太紧,正常波动也会被判不通过。好的验收标准基于硬件规格、厂商参考值和实际经验,留出合理余量。
| 指标 | 理论峰值 | 验收达标线 | 告警线 | 说明 |
|---|---|---|---|---|
| HBM 带宽 | 3.35 TB/s | ≥ 3.0 TB/s (90%) | < 2.8 TB/s | H100 SXM5 规格 |
| NVLink 单向 | 50 GB/s | ≥ 45 GB/s (90%) | < 42 GB/s | 每条 NVLink |
| RDMA 200G 双向 | 200 Gb/s | ≥ 190 Gb/s (95%) | < 180 Gb/s | 网卡层面 |
| 单机 AllReduce | ~300 GB/s | ≥ 270 GB/s (90%) | < 250 GB/s | 1GB 消息 busbw |
| 全集群 AllReduce (32N) | ~35 GB/s | ≥ 30 GB/s (86%) | < 27 GB/s | 1GB 消息 busbw |
# 验收标准配置文件
acceptance_criteria:
bandwidth:
hbm:
min_gbps: 3000 # 3.0 TB/s
alert_gbps: 2800
unit: "MB/s"
nvlink_unidir:
min_gbps: 45
alert_gbps: 42
rdma_200g_bidir:
min_gbps: 190 # Gb/s
alert_gbps: 180
single_node_allreduce:
min_busbw_gbps: 270
alert_gbps: 250
msg_size: "1G"
cluster_allreduce_32n:
min_busbw_gbps: 30
alert_gbps: 27
msg_size: "1G"
latency:
rdma_200g:
max_us: 2.5
typical_us: 1.9
alert_us: 5.0
nvlink_p2p:
max_us: 1.5
typical_us: 0.8
consistency:
rdma_matrix_variance_pct: 5 # 全连接矩阵带宽方差不超过 5%
repeat_test_variance_pct: 3 # 连续 3 次测试结果方差不超过 3%
cross_node_consistency: true # 所有节点 L1 结果一致
stability:
repeat_count: 3 # 连续 3 次全量测试
all_must_pass: true # 3 次必须全部通过
max_variance_between_runs: 5 # 运行间方差
documentation:
require_report: true # 必须生成验收报告
require_signoff: true # 必须签字确认
require_baseline_archive: true # 必须归档基线
require_runbook: true # 必须附运维手册
单次测试通过不够——可能恰好那一次网络不拥堵。稳定性要求连续 3 次全量测试全部通过,且 3 次结果间的方差不超过 5%。这能排除偶发因素,确认性能可重复。
2026 年 3 月,某 AI 实验室新建 256 卡 H100 集群(32 节点 × 8 卡,200G RoCE 互联,Fat-Tree 拓扑)交付验收。按本篇流程执行全量基准测试,L0/L1 顺利通过,L2 全连接矩阵发现 5 对节点 RDMA 带宽异常,最终定位为 3 根线缆问题 + 1 个交换机端口配置错误。修复后全量通过,历时 2 天完成验收。
32 节点的驱动版本(550.54.15)、CUDA(12.4)、NCCL(2.20)全部一致。GPU 拓扑确认每节点 NVLink 全互联(18 条/卡)。L0 全 256 卡 HBM 带宽平均 3.24 TB/s,达标率 96.8%。L1 全 32 节点单机 AllReduce 平均 285 GB/s,达标率 95%。此阶段无异常,耗时约 1 小时。
执行 32 节点全连接矩阵 RDMA 带宽测试,共 496 对,耗时约 4 小时。结果发现 5 对节点带宽异常:
异常模式很明显:r03 和 r07 两个机架之间的 4 对节点全部不达标,而 r03/r07 各自内部以及其他机架间通信正常。这说明问题出在 r03↔r07 的机架间链路上,而非节点本身。进一步排查:
# 定位 r03 ↔ r07 机架间链路问题
# 1. 检查 r03-n01 到 r07 的光模块和线缆
ssh gpu-r03-n01 "ethtool -m mlx5_0"
# 输出: Vendor: NVIDIA, Part Number: MCN735A0, Serial: 21C12345
# Length: 100m, Cable Type: MMF
# 2. 检查交换机端口状态和光模块
ssh spine-switch-01 "show interface port 1/5"
# Port 1/5: Link UP, Speed 200G, FEC: RS-FEC
# 但 port 1/5 的光模块 RX power 偏低:
ssh spine-switch-01 "show interface port 1/5 transceiver"
# TX Power: -1.2 dBm (正常)
# RX Power: -6.8 dBm (偏低, 正常应 < -3.5 dBm)
# 3. 检查 r03-n02 的线缆
ssh gpu-r03-n02 "ethtool -m mlx5_0"
# 光模块 Serial: 21C12346, RX Power: -7.1 dBm (偏低)
# 4. 物理检查: r03 机架顶部交换机上行端口
# 发现 3 根线缆连接不紧固(安装时未完全插入)
# 以及 spine-switch-01 port 1/5 的 FEC 模式配置错误
# 应配置为 RS-FEC 但实际为 disabled(导致误码率高,带宽降级)
问题 1-3:r03 机架到 spine 交换机的 3 根 200G 线缆未完全插入,光模块 RX power 偏低(-6.8/-7.1 dBm vs 正常 -3.5 dBm),导致误码率升高、带宽降级到 70%。问题 4:spine-switch-01 port 1/5 的 FEC(前向纠错)模式被误配置为 disabled,应为 RS-FEC,导致高速信号下误码无法纠正。
# 修复操作
# 修复 1-3: 重新插拔 3 根线缆,确保完全插入并锁紧
# 物理操作,需机房现场执行
# 修复后验证光模块 RX power
ssh gpu-r03-n01 "ethtool -m mlx5_0"
# RX Power: -2.1 dBm ✅ (正常范围)
ssh gpu-r03-n02 "ethtool -m mlx5_0"
# RX Power: -2.3 dBm ✅
# 修复 4: 修正交换机端口 FEC 配置
ssh spine-switch-01 "configure terminal"
ssh spine-switch-01 "interface port 1/5"
ssh spine-switch-01 "fec rs" # 设置为 RS-FEC
ssh spine-switch-01 "commit"
ssh spine-switch-01 "show interface port 1/5"
# Port 1/5: Link UP, Speed 200G, FEC: RS-FEC ✅
# 修复后重测 r03 ↔ r07 的 4 对节点
for pair in "r03-n01:r07-n01" "r03-n02:r07-n01" "r03-n01:r07-n02" "r03-n02:r07-n02"; do
node_a="gpu-$(echo $pair | cut -d: -f1)"
node_b="gpu-$(echo $pair | cut -d: -f2)"
echo "重测 $node_a ↔ $node_b"
ssh $node_a "ib_write_bw -d mlx5_0 -p 18515 --report_gbits -s 4194304 -b $node_b-ib0"
done
修复后执行全量 L2 矩阵重测(4 小时)+ L3 全集群 AllReduce(30 分钟)。全连接矩阵 496 对全部 ≥ 190 Gb/s,方差 1.8%。全集群 32 节点 256 GPU AllReduce busbw = 31.2 GB/s,达到预期 30 GB/s 的 104%。连续 3 次测试结果方差 2.1%,稳定性达标。验收通过,基线归档为 v1.0。
验收报告是基准测试的正式交付物,需要结构完整、数据准确、结论明确。以下是标准报告模板。
# GPU 集群基准测试验收报告
## 1. 基本信息
- 集群名称: prod-gpu-256
- 节点数: 32
- GPU 数: 256 (H100-SXM5 × 8/节点)
- 网络拓扑: Fat-Tree, 200G RoCE, 无阻塞
- 验收日期: 2026-03-15
- 验收人员: OPS Team
- 驱动版本: 550.54.15
- CUDA 版本: 12.4
- NCCL 版本: 2.20
## 2. 验收标准
(引用 acceptance_criteria.yaml 中的标准)
## 3. 测试结果汇总
### 3.1 L0 单卡基线
| 指标 | 预期值 | 实测均值 | 最小值 | 达标率 | 状态 |
|------|--------|----------|--------|--------|------|
| HBM 带宽 | ≥3.0 TB/s | 3.24 TB/s | 3.18 TB/s | 100% | ✅ |
| FP16 算力 | ≥1800 TF | 1856 TF | 1821 TF | 100% | ✅ |
### 3.2 L1 单机基线
| 指标 | 预期值 | 实测均值 | 最小值 | 达标率 | 状态 |
|------|--------|----------|--------|--------|------|
| NVLink P2P | ≥45 GB/s | 47.2 GB/s | 46.1 GB/s | 100% | ✅ |
| 单机 AllReduce | ≥270 GB/s | 285 GB/s | 273 GB/s | 100% | ✅ |
### 3.3 L2 多机基线
| 指标 | 预期值 | 实测均值 | 异常对 | 状态 |
|------|--------|----------|--------|------|
| RDMA 带宽矩阵 | ≥190 Gb/s | 199.2 Gb/s | 0 | ✅ |
| 多机 AR (16N) | ≥55 GB/s | 58.3 GB/s | - | ✅ |
### 3.4 L3 全集群
| 指标 | 预期值 | 实测值 | 达成率 | 状态 |
|------|--------|--------|--------|------|
| 全集群 AR (32N) | ≥30 GB/s | 31.2 GB/s | 104% | ✅ |
| 全集群 AG (32N) | ≥32 GB/s | 33.5 GB/s | 105% | ✅ |
| 端到端 MFU | ≥45% | 47.2% | 105% | ✅ |
## 4. 异常项及修复记录
| 序号 | 异常描述 | 根因 | 修复措施 | 修复后状态 |
|------|----------|------|----------|------------|
| 1 | r03↔r07 4对节点RDMA带宽~140Gb/s | 3根线缆未完全插入 | 重新插拔锁紧 | ✅ 199.8 Gb/s |
| 2 | spine-01 port 1/5 FEC误配 | FEC模式设为disabled | 改为RS-FEC | ✅ 200.1 Gb/s |
| 3 | r12↔r15 1对节点带宽边缘 | 线缆松动 | 重新插拔 | ✅ 199.3 Gb/s |
## 5. 稳定性验证
- 连续测试次数: 3
- 3次结果方差: 2.1%
- 全部通过: 是
## 6. 结论
本次验收全部通过,集群性能满足预期要求。
基线版本 v1.0 已归档。
## 7. 建议
- 日常运维中每周执行 L0+L1 抽检
- 驱动/NCCL 升级后触发全量回归
- 关注 r03/r07 机架间链路,加密监测频率
- 建议下次扩容时对新节点单独执行 L0+L1 后再纳入集群
#!/usr/bin/env python3
"""验收报告自动生成"""
import json, time, statistics
from pathlib import Path
def generate_report(bench_dir, baseline_version="v1.0"):
bench_dir = Path(bench_dir)
# 加载所有测试结果
report = {
"title": "GPU 集群基准测试验收报告",
"date": time.strftime("%Y-%m-%d"),
"cluster": "prod-gpu-256",
"sections": {}
}
# L0 汇总
l0_files = list((bench_dir / "L0").glob("*.json"))
hbm_values = []
for f in l0_files:
data = json.loads(f.read_text())
if "hbm_bandwidth" in data.get("tests", {}):
hbm_values.append(data["tests"]["hbm_bandwidth"]["value"])
report["sections"]["L0"] = {
"hbm_bw": {
"mean": round(statistics.mean(hbm_values), 1) if hbm_values else 0,
"min": round(min(hbm_values), 1) if hbm_values else 0,
"expected": 3000,
"pass_rate": round(sum(1 for v in hbm_values if v >= 3000) / len(hbm_values) * 100, 1),
}
}
# L3 汇总
l3_file = bench_dir / "L3" / "cluster_allreduce.json"
if l3_file.exists():
l3_data = json.loads(l3_file.read_text())
report["sections"]["L3"] = {
"cluster_allreduce": {
"value": l3_data.get("busbw_gbps", 0),
"expected": 30,
"achievement_pct": round(
l3_data.get("busbw_gbps", 0) / 30 * 100, 1
),
}
}
# 总体结论
all_pass = True # 简化判断
report["conclusion"] = "PASS" if all_pass else "FAIL"
report["baseline_version"] = baseline_version
# 输出
report_file = bench_dir / "acceptance_report.json"
report_file.write_text(json.dumps(report, indent=2, ensure_ascii=False))
print(f"验收报告已生成: {report_file}")
return report
if __name__ == "__main__":
generate_report(f"/data/benchmark/baseline/v1.0_{time.strftime('%Y%m%d')}")
| 测试项 | 层级 | 命令 | 预期值 |
|---|---|---|---|
| HBM 带宽 | L0 | dcgmi dmon -e 1004 -d 10 | ≥ 3000 MB/s |
| GPU 算力 | L0 | ./gpu_burn 60 | SM ≥ 95% |
| PCIe 带宽 | L0 | ./p2pBandwidthLatencyTest | ≥ 115 GB/s (Gen5) |
| NVLink P2P | L1 | nvidia-smi nvlink -g 0 -l | 18 链路 Active |
| 单机 AllReduce | L1 | ./all_reduce_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20 | busbw ≥ 270 GB/s |
| 单机 AllGather | L1 | ./all_gather_perf -b 8 -e 1G -f 2 -g 8 -w 5 -n 20 | busbw ≥ 350 GB/s |
| RDMA 带宽 | L2 | ib_write_bw -d mlx5_0 --report_gbits -s 4M -b | ≥ 190 Gb/s |
| RDMA 延迟 | L2 | ib_write_lat -d mlx5_0 -s 2 | ≤ 2.5 μs |
| 跨节点 AllReduce | L2 | mpirun -np N ... ./all_reduce_perf -g 8 | 见预期值表 |
| 全集群 AllReduce | L3 | mpirun -np 32 ... ./all_reduce_perf -g 8 -e 1G | busbw ≥ 30 GB/s |
| GPU 拓扑 | 环境 | nvidia-smi topo -m | NV12 全互联 |
| RDMA 状态 | 环境 | ibstat / ibv_devinfo | PORT_ACTIVE |
| NCCL 调试 | 环境 | export NCCL_DEBUG=INFO | — |
| 现象 | 可能原因 | 排查命令 | 修复方向 |
|---|---|---|---|
| 单 GPU HBM 带宽低 | GPU 老化/HBM 故障 | dcgmi dmon -e 1004 | RMA 更换 |
| NVLink 单链路 Down | 线缆/接触/SXM 插座 | nvidia-smi nvlink -s | 重新插拔/报修 |
| RDMA 带宽全矩阵低 | 驱动/NCCL/内核参数 | 对比版本、检查 sysctl | 回滚变更 |
| 特定节点对带宽低 | 线缆/光模块/交换机端口 | ethtool -m, ibstat | 换线缆/修端口配置 |
| 机架间全部低 | spine 交换机/上行链路 | 检查交换机端口和路由 | 修交换机配置/换模块 |
| AllReduce 随节点数急剧下降 | 网络拓扑非无阻塞 | 检查 Fat-Tree 拓扑 | 调整路由/扩容 |
| 热退化(温度高时带宽降) | 散热不足/热节流 | nvidia-smi -q -d TEMPERATURE | 改善散热/清灰 |
| 间歇性退化 | PFC 风暴/ECN 配置 | 抓包看 PFC 帧 | 调 ECN/PFC 参数 |
| 变量 | 作用 | 推荐值 |
|---|---|---|
NCCL_IB_DISABLE | 启用/禁用 IB 通信 | 0 (启用) |
NCCL_IB_HCA | 指定 RDMA 网卡 | mlx5_0 |
NCCL_NET_GDR_LEVEL | GPU Direct RDMA 级别 | PHB |
NCCL_SOCKET_IFNAME | 控制面网卡 | eth0 |
NCCL_DEBUG | 调试日志级别 | INFO/WARN |
NCCL_IB_TIMEOUT | IB 超时重传 | 22 (默认) |
NCCL_IB_RETRY_CNT | IB 重传次数 | 7 (默认) |
NCCL_BUFFSIZE | NCCL 缓冲区大小 | 4194304 (默认) |