集群交付验收是NPU集群从建设到投产的最后一道关卡。传统人工验收耗时长、覆盖面窄、难以复现。本文系统讲解昇腾NPU集群验收自动化框架的设计与实现,覆盖测试用例体系、并行执行编排、报告自动生成、CI/CD集成,以及与GPU集群验收自动化的关键差异,帮助团队将验收时间从数天缩短至数小时。
集群验收自动化框架的核心目标是:给定一个新交付的昇腾NPU集群,自动执行一组预定义的检查项,生成结构化验收报告,判定集群是否可以投产。框架需要支持并行执行、失败重试、增量验收、报告归档。
验收框架采用分层设计:调度层负责编排测试用例的执行顺序和并行度;执行层负责在目标节点上运行具体检查;采集层负责收集执行结果和日志;报告层负责汇总结果并生成验收报告。四层解耦使得可以独立扩展每一层而不影响其他层。
#!/usr/bin/env python3
"""昇腾NPU集群验收自动化框架"""
import abc
import time
import json
import subprocess
from enum import Enum
from dataclasses import dataclass, field
from typing import List, Dict, Optional
from concurrent.futures import ThreadPoolExecutor, as_completed
class CheckResult(Enum):
PASS = "pass"
FAIL = "fail"
SKIP = "skip"
WARN = "warn"
@dataclass
class TestCase:
"""验收测试用例基类"""
case_id: str
name: str
category: str # hardware/comm/operator/business
timeout: int = 300 # 超时秒数
retry: int = 1 # 重试次数
depends_on: List[str] = field(default_factory=list) # 依赖用例
nodes: List[str] = field(default_factory=list) # 目标节点
params: Dict = field(default_factory=dict) # 参数
@dataclass
class TestResult:
"""测试执行结果"""
case_id: str
result: CheckResult
duration: float
message: str = ""
details: Dict = field(default_factory=dict)
timestamp: str = ""
class BaseExecutor(abc.ABC):
"""执行器抽象基类"""
@abc.abstractmethod
def run(self, case: TestCase) -> TestResult:
pass
@abc.abstractmethod
def collect_evidence(self, case: TestCase) -> Dict:
"""收集证据(日志、截图等)"""
pass
class AcceptanceFramework:
"""验收框架主类"""
def __init__(self, config_file: str):
self.config = self._load_config(config_file)
self.test_cases: List[TestCase] = []
self.results: List[TestResult] = []
self.executors: Dict[str, BaseExecutor] = {}
def load_cases(self, case_dir: str):
"""从YAML/JSON文件加载测试用例"""
pass
def register_executor(self, category: str, executor: BaseExecutor):
"""注册执行器"""
self.executors[category] = executor
def run(self, parallel: int = 8, filter_category: str = None):
"""执行验收"""
cases = self.test_cases
if filter_category:
cases = [c for c in cases if c.category == filter_category]
# 按依赖关系排序
ordered = self._topological_sort(cases)
# 并行执行
with ThreadPoolExecutor(max_workers=parallel) as pool:
futures = {}
for case in ordered:
executor = self.executors.get(case.category)
if executor:
future = pool.submit(self._run_with_retry, executor, case)
futures[future] = case
for future in as_completed(futures):
result = future.result()
self.results.append(result)
print(f"[{result.result.value}] {result.case_id}: {result.message}")
return self._generate_report()
def _run_with_retry(self, executor, case):
"""带重试的执行"""
for attempt in range(case.retry + 1):
result = executor.run(case)
if result.result == CheckResult.PASS:
return result
if attempt < case.retry:
print(f"重试 {case.case_id} ({attempt+1}/{case.retry})")
time.sleep(5)
return result
验收自动化框架就像汽车的出厂质检线——车辆(集群)开上质检线后,不需要人工逐项检查,而是自动经过一组传感器(执行器):轮胎压力检测(硬件检查)、刹车性能测试(通信检查)、发动机工况扫描(算子检查)、路试模拟(业务检查)。每个传感器独立工作但由中央控制系统(调度层)协调,最终生成一份质检报告(报告层),判定这辆车能不能出厂交付。
验收测试用例是框架的核心资产。用例体系需要覆盖从硬件到业务的全部层面,形成分层递进的验证链条。如果底层检查不通过,上层检查无需执行——一张有硬件故障的卡不需要跑算子精度测试。
| 层级 | 用例类别 | 典型用例 | 用例数量 | 执行耗时 | 并行性 |
|---|---|---|---|---|---|
| L1硬件 | NPU识别 | 卡数量/型号/PCIe拓扑 | 5 | ~30s | 完全并行 |
| L1硬件 | 健康状态 | 温度/ECC/功耗/HBM | 8 | ~60s | 完全并行 |
| L2通信 | HCCS链路 | 链路状态/带宽/延迟 | 6 | ~2min | 按域并行 |
| L2通信 | HCCL集合通信 | AllReduce/AllGather/Broadcast | 10 | ~5min | 需协调 |
| L3算子 | 基础算子 | MatMul/Conv/Softmax精度 | 20 | ~10min | 完全并行 |
| L3算子 | 融合算子 | FlashAttention/RMSNorm | 15 | ~8min | 完全并行 |
| L4业务 | 训练基准 | 小模型训练10步收敛 | 5 | ~30min | 按任务并行 |
| L4业务 | 推理基准 | 模型推理延迟/吞吐 | 5 | ~15min | 完全并行 |
一个完整的昇腾NPU集群验收用例集通常包含70-100个用例,串行执行约需2-3小时,合理并行后可缩短至30-45分钟。其中L1硬件层和L2通信层占执行时间的20%,但能发现80%的硬件类问题。L4业务层占执行时间的60%,主要用于验证端到端可用性。
# acceptance_cases.yaml - 验收用例定义
cases:
# === L1 硬件层 ===
- id: HW-001
name: "NPU数量与型号校验"
category: hardware
executor: hardware_executor
timeout: 30
params:
expected_count: 8
expected_model: "Ascend 910C"
critical: true # 失败则终止后续用例
- id: HW-002
name: "HBM温度基线检查"
category: hardware
executor: hardware_executor
timeout: 60
params:
max_temp: 75
check_all_npus: true
depends_on: ["HW-001"]
- id: HW-003
name: "ECC错误计数检查"
category: hardware
executor: hardware_executor
timeout: 60
params:
max_correctable: 1000
max_uncorrectable: 0
depends_on: ["HW-001"]
# === L2 通信层 ===
- id: COMM-001
name: "HCCS全链路状态检查"
category: comm
executor: comm_executor
timeout: 120
params:
check_bidirectional: true
min_bandwidth_gbps: 350
depends_on: ["HW-001", "HW-002", "HW-003"]
- id: COMM-002
name: "HCCL AllReduce延迟测试"
category: comm
executor: comm_executor
timeout: 300
params:
message_size: ["1MB", "64MB", "256MB"]
expected_latency_ms: {1MB: 0.5, 64MB: 5, 256MB: 15}
tolerance: 0.2 # 允许20%偏差
depends_on: ["COMM-001"]
# === L3 算子层 ===
- id: OPS-001
name: "MatMul精度校验"
category: operator
executor: operator_executor
timeout: 120
params:
shapes: [[1024,1024,1024], [4096,4096,4096]]
dtype: ["float16", "bfloat16"]
compare_with: "cpu_reference"
atol: 1e-3
rtol: 1e-3
# === L4 业务层 ===
- id: BIZ-001
name: "GPT2小模型训练收敛"
category: business
executor: business_executor
timeout: 1800
params:
model: "gpt2-small"
steps: 10
expected_loss_decrease: true
min_throughput_samples: 100
depends_on: ["COMM-002", "OPS-001"]
并行执行是缩短验收时间的关键。但并非所有用例都可以随意并行——有些用例之间存在依赖关系(如通信检查依赖硬件检查通过),有些用例会竞争系统资源(如多个HCCL测试同时运行会互相干扰)。
框架通过拓扑排序将用例组织为有向无环图(DAG),同一层级的用例可以并行执行,不同层级串行推进。关键路径上的用例决定最小执行时间。
#!/usr/bin/env python3
"""并行验收调度器"""
from collections import defaultdict, deque
from concurrent.futures import ThreadPoolExecutor, as_completed
import time
class ParallelScheduler:
def __init__(self, cases, max_workers=8):
self.cases = {c.case_id: c for c in cases}
self.max_workers = max_workers
self.results = {}
self.failed_critical = False
def _build_dependency_graph(self):
"""构建依赖图,返回邻接表和入度"""
graph = defaultdict(list)
in_degree = defaultdict(int)
for cid, case in self.cases.items():
in_degree[cid] = len(case.depends_on)
for dep in case.depends_on:
graph[dep].append(cid)
return graph, in_degree
def _get_ready_cases(self, in_degree):
"""获取入度为0且未执行的用例"""
ready = []
for cid, deg in in_degree.items():
if deg == 0 and cid not in self.results:
ready.append(cid)
return ready
def _execute_case(self, cid):
"""执行单个用例"""
case = self.cases[cid]
executor = self.executors[case.category]
start = time.time()
try:
result = executor.run(case)
except Exception as e:
result = TestResult(
case_id=cid, result=CheckResult.FAIL,
duration=time.time() - start, message=str(e)
)
return cid, result
def run(self, executors):
"""执行并行验收"""
self.executors = executors
graph, in_degree = self._build_dependency_graph()
total = len(self.cases)
completed = 0
print(f"总用例数: {total}, 最大并行: {self.max_workers}")
with ThreadPoolExecutor(max_workers=self.max_workers) as pool:
while completed < total and not self.failed_critical:
ready = self._get_ready_cases(in_degree)
if not ready:
time.sleep(0.5)
continue
# 提交就绪用例
futures = {
pool.submit(self._execute_case, cid): cid
for cid in ready
}
for future in as_completed(futures):
cid, result = future.result()
self.results[cid] = result
completed += 1
status = "✓" if result.result == CheckResult.PASS else "✗"
print(f" [{status}] {cid}: {result.message} "
f"({result.duration:.1f}s) [{completed}/{total}]")
# 关键用例失败则停止
if (result.result == CheckResult.FAIL and
self.cases[cid].params.get("critical")):
self.failed_critical = True
print(f" 关键用例 {cid} 失败,终止验收")
break
# 更新依赖入度
for dependent in graph[cid]:
in_degree[dependent] -= 1
return self.results
HCCL集合通信测试不能同时运行多个实例——多个AllReduce测试同时初始化HCCL会因通信端口冲突而失败。框架需要在调度层对通信类用例做互斥控制:同一HCCS域内的通信测试串行执行,不同域之间可以并行。建议在用例定义中添加exclusive_resource: hccs_domain_0标记,调度器据此做互斥调度。
验收报告是交付物之一,需要同时面向技术团队(详细数据)和管理层(结论摘要)。框架支持生成HTML和JSON两种格式:HTML用于人阅读,JSON用于CI/CD流水线消费。
| 报告章节 | 面向受众 | 内容 | 关键字段 |
|---|---|---|---|
| 验收摘要 | 管理层 | 总体结论+关键指标 | 通过率、总耗时、关键发现、验收结论 |
| 环境信息 | 技术+管理 | 集群规格与配置 | 节点数、NPU型号、CANN版本、拓扑 |
| 用例详情 | 技术团队 | 每个用例的执行结果 | 用例ID、结果、耗时、日志路径、错误信息 |
| 性能数据 | 技术团队 | 关键性能指标基线 | HCCS带宽、HCCL延迟、算子吞吐、训练步时间 |
| 异常分析 | 技术团队 | 失败用例的根因分析 | 失败用例、可能原因、建议操作 |
| 历史对比 | 技术+管理 | 与上次验收的差异 | 指标变化、新增失败、回归检测 |
#!/usr/bin/env python3
"""验收报告生成器"""
import json
import datetime
from jinja2 import Template
class ReportGenerator:
def __init__(self, cluster_info, results, baseline=None):
self.cluster = cluster_info
self.results = results
self.baseline = baseline # 历史基线(用于对比)
def generate_html(self, output_path):
"""生成HTML验收报告"""
summary = self._calc_summary()
env_info = self._collect_env_info()
perf_data = self._collect_perf_data()
anomalies = self._analyze_failures()
comparison = self._compare_baseline() if self.baseline else None
html_template = Template("""
<html>
<head><title>昇腾NPU集群验收报告</title></head>
<body>
<h1>集群验收报告</h1>
<h2>验收摘要</h2>
<p>集群: {{ summary.cluster_name }}</p>
<p>结论: {{ summary.conclusion }}</p>
<p>通过率: {{ summary.pass_rate }}% ({{ summary.passed }}/{{ summary.total }})</p>
<p>总耗时: {{ summary.duration }}</p>
<h2>环境信息</h2>
<table>
<tr><td>节点数</td><td>{{ env.nodes }}</td></tr>
<tr><td>NPU型号</td><td>{{ env.npu_model }}</td></tr>
<tr><td>CANN版本</td><td>{{ env.cann_version }}</td></tr>
</table>
<h2>用例详情</h2>
<table>
<tr><th>用例ID</th><th>结果</th><th>耗时</th><th>说明</th></tr>
{% for r in results %}
<tr>
<td>{{ r.case_id }}</td>
<td>{{ r.result }}</td>
<td>{{ "%.1f"|format(r.duration) }}s</td>
<td>{{ r.message }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
""")
html = html_template.render(
summary=summary, env=env_info, results=self.results,
perf=perf_data, anomalies=anomalies, comparison=comparison
)
with open(output_path, "w") as f:
f.write(html)
def generate_json(self, output_path):
"""生成JSON结构化报告"""
report = {
"report_id": f"ACC-{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}",
"timestamp": datetime.datetime.now().isoformat(),
"cluster": self.cluster,
"summary": self._calc_summary(),
"results": [r.__dict__ for r in self.results],
"performance": self._collect_perf_data(),
}
with open(output_path, "w") as f:
json.dump(report, f, indent=2, ensure_ascii=False)
def _calc_summary(self):
total = len(self.results)
passed = sum(1 for r in self.results if r.result == CheckResult.PASS)
return {
"total": total,
"passed": passed,
"pass_rate": round(passed / total * 100, 1),
"conclusion": "通过" if passed == total else "不通过",
"duration": sum(r.duration for r in self.results),
}
def _analyze_failures(self):
"""分析失败用例的根因"""
failures = [r for r in self.results if r.result == CheckResult.FAIL]
analysis = []
for f in failures:
# 根据用例类别和错误信息推断根因
cause = self._infer_cause(f)
analysis.append({
"case_id": f.case_id,
"message": f.message,
"probable_cause": cause["cause"],
"suggested_action": cause["action"],
})
return analysis
每次验收报告应归档至/data/acceptance_reports/{cluster_name}/{date}/,保留至少12个月。历史对比功能允许将当前验收结果与上次验收并排比较,自动标红退化的指标(如HCCS带宽下降、HCCL延迟增加)。这对于发现集群性能退化趋势非常有价值——单次验收可能看不出问题,但连续三次验收HCCS带宽下降2%就值得关注。
验收自动化框架应与CI/CD流水线集成,实现集群交付的自动化门禁。当新集群交付或集群变更(如扩容、升级)后,CI/CD自动触发验收流水线,验收通过才允许投产。
# .gitlab-ci.yml - 昇腾NPU集群验收流水线
stages:
- pre_check
- acceptance
- report
- gate
variables:
CLUSTER_NAME: "CloudMatrix-384-Prod"
ACCEPTANCE_VERSION: "v2.3"
# 预检查:确认集群可达
pre_check:
stage: pre_check
script:
- python3 scripts/check_cluster_reachable.py --cluster $CLUSTER_NAME
- python3 scripts/verify_ssh_access.py --nodes all
rules:
- if: '$CI_PIPELINE_SOURCE == "trigger"'
# L1硬件层验收
acceptance_hardware:
stage: acceptance
script:
- python3 -m ascend_acceptance
--cluster $CLUSTER_NAME
--filter-category hardware
--parallel 16
--output results_hardware.json
artifacts:
paths: [results_hardware.json]
expire_in: 30 days
# L2通信层验收(依赖L1通过)
acceptance_comm:
stage: acceptance
needs: [acceptance_hardware]
script:
- python3 -m ascend_acceptance
--cluster $CLUSTER_NAME
--filter-category comm
--parallel 4
--output results_comm.json
artifacts:
paths: [results_comm.json]
# L3算子层 + L4业务层
acceptance_ops_biz:
stage: acceptance
needs: [acceptance_comm]
script:
- python3 -m ascend_acceptance
--cluster $CLUSTER_NAME
--filter-category operator,business
--parallel 8
--output results_ops_biz.json
artifacts:
paths: [results_ops_biz.json]
# 生成综合报告
generate_report:
stage: report
needs: [acceptance_hardware, acceptance_comm, acceptance_ops_biz]
script:
- python3 -m ascend_acceptance.report
--merge results_hardware.json results_comm.json results_ops_biz.json
--output acceptance_report.html
--json acceptance_report.json
artifacts:
paths: [acceptance_report.html, acceptance_report.json]
# 投产门禁
production_gate:
stage: gate
needs: [generate_report]
script:
- python3 scripts/check_gate.py --report acceptance_report.json
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: on_success
allow_failure: false
CI/CD集成的验收门禁就像机场的安检流程——旅客(集群变更)必须依次通过身份验证(预检查)、行李扫描(硬件验收)、金属探测(通信验收)、开箱检查(算子验收)、随机抽查(业务验收),全部通过才能登机(投产)。任何一环不通过都会被拦下,不会进入下一环节。这种"层层把关、逐级放行"的设计确保了投产质量,避免了"带病上线"。
本节给出几个关键验收检查项的完整实现,展示如何从npu-smi等工具的输出中提取数据并与期望值比对。
#!/usr/bin/env python3
"""硬件检查执行器"""
import subprocess
import re
import json
class HardwareExecutor(BaseExecutor):
"""L1硬件层检查执行器"""
def run(self, case: TestCase) -> TestResult:
dispatch = {
"HW-001": self._check_npu_count,
"HW-002": self._check_temperature,
"HW-003": self._check_ecc,
"HW-004": self._check_pcie_topology,
"HW-005": self._check_power,
}
handler = dispatch.get(case.case_id)
if handler:
return handler(case)
return TestResult(case.case_id, CheckResult.SKIP, 0, "未知用例")
def _check_npu_count(self, case):
"""HW-001: NPU数量与型号校验"""
start = time.time()
result = subprocess.run(
["npu-smi", "info", "-l"],
capture_output=True, text=True, timeout=case.timeout
)
# 解析NPU数量
count_match = re.search(r"Total Count\s*:\s*(\d+)", result.stdout)
actual_count = int(count_match.group(1)) if count_match else 0
expected = case.params["expected_count"]
# 解析型号
model_match = re.search(r"Chip\s+Type\s*:\s*(.+)", result.stdout)
actual_model = model_match.group(1).strip() if model_match else "Unknown"
expected_model = case.params["expected_model"]
if actual_count == expected and expected_model in actual_model:
return TestResult(
case.case_id, CheckResult.PASS, time.time() - start,
f"{actual_count}卡在线, 型号{actual_model}",
{"count": actual_count, "model": actual_model}
)
else:
return TestResult(
case.case_id, CheckResult.FAIL, time.time() - start,
f"期望{expected}卡{expected_model}, 实际{actual_count}卡{actual_model}",
{"expected": expected, "actual": actual_count}
)
def _check_temperature(self, case):
"""HW-002: HBM温度检查"""
start = time.time()
max_temp = 0
temps = {}
for i in range(8): # 8张卡
result = subprocess.run(
["npu-smi", "info", "-t", "temp", "-i", str(i)],
capture_output=True, text=True, timeout=30
)
# 解析HBM温度
for line in result.stdout.splitlines():
if "HBM" in line:
temp_match = re.search(r"(\d+)\s*C", line)
if temp_match:
t = int(temp_match.group(1))
temps[f"NPU{i}"] = t
max_temp = max(max_temp, t)
threshold = case.params["max_temp"]
if max_temp <= threshold:
return TestResult(
case.case_id, CheckResult.PASS, time.time() - start,
f"最高温度{max_temp}°C (阈值{threshold}°C)",
{"max_temp": max_temp, "all_temps": temps}
)
else:
return TestResult(
case.case_id, CheckResult.FAIL, time.time() - start,
f"温度超限: {max_temp}°C > {threshold}°C",
{"max_temp": max_temp, "all_temps": temps}
)
def _check_ecc(self, case):
"""HW-003: ECC错误检查"""
start = time.time()
total_correctable = 0
total_uncorrectable = 0
for i in range(8):
result = subprocess.run(
["npu-smi", "info", "-t", "ecc", "-i", str(i)],
capture_output=True, text=True, timeout=30
)
# 解析ECC计数
for line in result.stdout.splitlines():
if "Correctable" in line:
m = re.search(r"(\d+)", line.split(":")[-1])
if m: total_correctable += int(m.group(1))
if "Uncorrectable" in line:
m = re.search(r"(\d+)", line.split(":")[-1])
if m: total_uncorrectable += int(m.group(1))
max_unc = case.params["max_uncorrectable"]
if total_uncorrectable <= max_unc:
return TestResult(
case.case_id, CheckResult.PASS, time.time() - start,
f"ECC: {total_correctable}可纠正, {total_uncorrectable}不可纠正",
{"correctable": total_correctable,
"uncorrectable": total_uncorrectable}
)
else:
return TestResult(
case.case_id, CheckResult.FAIL, time.time() - start,
f"不可纠正ECC超限: {total_uncorrectable} > {max_unc}",
)
def collect_evidence(self, case):
"""收集诊断证据"""
evidence = {}
evidence["npu-smi_info"] = subprocess.run(
["npu-smi", "info"], capture_output=True, text=True
).stdout
evidence["dmesg"] = subprocess.run(
["dmesg", "--time-format=iso"], capture_output=True, text=True
).stdout[-5000:] # 最后5000字符
return evidence
验收过程中会遇到各种瞬时故障:SSH连接超时、NPU状态查询偶发失败、HCCL初始化超时。框架需要区分瞬时故障和真实失败,对瞬时故障自动重试,对真实失败记录并报告。
| 异常类型 | 判定方式 | 重试策略 | 重试参数 | 最终处理 |
|---|---|---|---|---|
| SSH连接超时 | 超时异常 | 自动重试 | 3次,间隔5s | 标记节点不可达 |
| npu-smi无输出 | 空输出 | 自动重试 | 2次,间隔3s | 标记NPU异常 |
| HCCL初始化超时 | 超时异常 | 自动重试 | 2次,间隔10s | 检查HCCS链路 |
| 算子精度超差 | 数值比对 | 不重试 | - | 记录+标记失败 |
| NPU数量不符 | 数值比对 | 不重试 | - | 关键失败+终止 |
| 温度超限 | 阈值比对 | 延迟重试 | 1次,间隔60s | 确认是否持续 |
重试不是万能药。过度重试会掩盖真实问题——如果一个用例连续失败3次,很可能是真实故障而非瞬时抖动。建议对重试设置"熔断"机制:同一用例在24小时内重试超过5次,自动标记为"疑似不稳定"并触发告警,由人工介入分析。此外,重试只适用于检查类用例(如状态查询),不适用于破坏性操作(如固件刷写)。
将验收自动化的完整流程整合为一张图,展示从触发到报告的端到端流程:
验收用例是框架的核心资产,需要像代码一样进行版本管理。用例集随集群配置演进而变化——新芯片型号需要新用例,旧用例可能因工具升级而失效。良好的用例管理确保验收的可重复性和可追溯性。
验收用例集应存储在Git仓库中,每次集群验收记录使用的用例集版本号。当验收失败时,可以精确定位是哪个版本的用例发现的哪个问题。用例变更需要经过code review,确保新增用例的期望值经过验证、删除用例有充分理由。
| 用例变更类型 | 触发场景 | 变更内容 | 兼容性处理 | 验证要求 |
|---|---|---|---|---|
| 新增用例 | 新芯片/新特性支持 | 添加检查项+期望值 | 旧集群标记skip | 在测试集群验证 |
| 修改期望值 | 固件升级改变基线 | 更新threshold/expected | 保留旧值用于对比 | 双版本并行验证 |
| 删除用例 | 工具废弃/检查项合并 | 标记deprecated | 保留1个版本周期 | 确认无遗漏检查 |
| 调整依赖 | 用例执行顺序优化 | 修改depends_on | 验证DAG无环 | 全量回归测试 |
| 参数调优 | 降低误报/提高灵敏度 | 修改timeout/retry/tolerance | 灰度应用 | 对比历史通过率 |
#!/bin/bash
# case_version_manager.sh - 用例集版本管理
CASE_REPO="/opt/ascend-acceptance-cases"
CASE_VERSION_FILE="/var/ascend_acceptance/case_version.txt"
# 记算用例集哈希
compute_case_hash() {
find "$CASE_REPO/cases" -name "*.yaml" | sort | xargs cat | sha256sum | awk '{print $1}'
}
# 记算用例集版本
get_case_version() {
cd "$CASE_REPO"
git describe --tags --always 2>/dev/null || echo "unknown"
}
# 记算用例数量
count_cases() {
find "$CASE_REPO/cases" -name "*.yaml" -exec grep -l "^ - id:" {} \; | xargs grep -c "^ - id:" | awk -F: '{sum+=$2} END{print sum}'
}
# 记算各层用例数量
count_by_category() {
local category=$1
grep -r "category: $category" "$CASE_REPO/cases/" | wc -l
}
echo "=== 用例集版本信息 ==="
echo "版本: $(get_case_version)"
echo "哈希: $(compute_case_hash)"
echo "总数: $(count_cases) 个用例"
echo " L1硬件: $(count_by_category hardware) 个"
echo " L2通信: $(count_by_category comm) 个"
echo " L3算子: $(count_by_category operator) 个"
echo " L4业务: $(count_by_category business) 个"
# 记算与上次验收的差异
LAST_VERSION=$(cat "$CASE_VERSION_FILE" 2>/dev/null)
CURRENT_VERSION=$(get_case_version)
if [ "$LAST_VERSION" != "$CURRENT_VERSION" ]; then
echo ""
echo "=== 用例集变更 (自上次验收) ==="
echo "旧版本: $LAST_VERSION"
echo "新版本: $CURRENT_VERSION"
cd "$CASE_REPO"
git log --oneline "$LAST_VERSION".."$CURRENT_VERSION" -- cases/
fi
# 保存当前版本
get_case_version > "$CASE_VERSION_FILE"
compute_case_hash >> "$CASE_VERSION_FILE"
不同集群可能使用不同版本的用例集——910B集群使用v2.1(不含UB拓扑检查),910C集群使用v2.3(含UB/灵衢检查)。建议在集群配置文件中记录用例集版本号,验收时自动加载对应版本。这样避免用例集升级影响旧集群的验收流程,也便于在验收报告中追溯使用的用例版本。
用例集本身也需要质量度量,以持续改进。关键度量指标包括:
这些度量数据应定期(如每月)生成用例质量报告,指导用例集的迭代优化。用例集不是一次写好就不变的——随着集群规模扩大、芯片代际更迭、业务需求变化,用例集需要持续演进,而质量度量提供了演进方向的依据。
昇腾NPU集群验收与NVIDIA GPU集群验收在框架设计上可以共用同一套架构,但在具体检查项、工具链、通信库测试等方面存在差异。
| 对比维度 | 昇腾NPU集群 | NVIDIA GPU集群 |
|---|---|---|
| 硬件检查工具 | npu-smi / ascend-dmi | nvidia-smi / dcgmi / nvml |
| 通信链路检查 | HCCS链路状态+带宽 (hccn_tool) | NVLink/NVSwitch拓扑+带宽 (dcgmi) |
| 集合通信测试 | HCCL AllReduce/AllGather (hccl_test) | NCCL AllReduce/AllGather (nccl-tests) |
| 算子精度基准 | torch_npu算子 vs CPU参考实现 | PyTorch CUDA算子 vs CPU参考实现 |
| 训练基准模型 | GPT2/BERT + torch_npu适配 | GPT2/BERT + 原生PyTorch CUDA |
| 拓扑验证 | HCCS域+UB拓扑 (910C+) | NVSwitch拓扑+GPU NIC亲和性 |
| ECC检查 | npu-smi info -t ecc -i 0 | nvidia-smi -q (ECC模式+计数) |
| 框架成熟度 | 需自研框架,社区工具少 | 有DCGM/DCGMI/Kubernetes Device Plugin |
昇腾和GPU的验收自动化对比,就像两个不同品牌的汽车质检线——质检流程框架是一样的(上线→检查→报告→放行),但具体的检测设备不同:昇腾用的是自研的npu-smi检测仪,GPU用的是nvidia-smi检测仪。聪明的做法是设计一个"检测仪适配层",让同一套质检框架能接入不同品牌的检测设备,这样运维团队只需要维护一套框架,而不是为昇腾和GPU各写一套。
对于同时运维昇腾和GPU集群的团队,建议抽象出统一的验收框架接口,为不同芯片类型实现适配器。框架核心(调度、报告、CI/CD集成)共用,执行器按芯片类型切换。这样验收SOP可以统一管理,验收报告格式一致,便于跨平台对比。关键差异点仅在执行器内部:npu-smi vs nvidia-smi、HCCL vs NCCL、torch_npu vs 原生PyTorch。
某昇腾NPU集群交付案例:从人工验收的3天(含反复确认和文档整理)缩短到自动化验收的45分钟(含报告生成)。更重要的是,自动化验收的覆盖面从人工的约30个检查项扩展到74个用例,发现了3个人工验收遗漏的问题(1个HCCS链路CRC错误、2个算子精度偏差)。验收报告自动归档后,历史对比功能在后续巡检中两次提前发现了性能退化趋势。