Device: npu:0
Eager average time: 0.000303 s
First compiled call time: 3.649342 s
Compiled average time: 0.000919 s
Correctness: PASS (max_abs_diff=8.941e-08)
Performance: PASS
预期结果
官方文档或众测任务说明应统一明确:
eager 和 compiled 是否都需要预热;
首次 compiled call 是否必须单独记录;
稳态平均耗时的推荐迭代次数;
NPU 计时前后应使用的同步接口;
首次编译耗时是否排除在稳态性能对比之外;
动态 shape 或重编译是否需要单独记录;
性能结果应同时附带正确性校验和环境版本。
建议
建议提供统一的性能测试模板,并至少输出:
Eager average time
First compiled call time
Compiled average time
Recompile count
Synchronization method
Correctness
在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。
环境信息
环境信息
torch.npu.is_available()返回Truetorch_multimodal_clip测试模型使用场景及问题
问题描述
本次 TorchAir-GE 验证脚本分别输出了 eager 平均耗时、首次 compiled call 耗时和 compiled 平均耗时:
脚本在计时前后对 NPU 执行同步,并把首次编译调用单独统计。由此可以区分:
但如果不同测试脚本没有统一预热、迭代次数和同步方式,结果就无法判断是在比较编译成本、稳态执行性能,还是异步调用返回时间。当前希望补充的是测试口径,而不是报告 TorchAir-GE 的确定性性能 Bug。
独立复现步骤
cd "/workspace/pytorch-ecosystem/01_tasks/2026/torch_npu_public_beta/Aimermo/任务2-torch.compile体验与实践" source /workspace/torch312/bin/activate source /usr/local/Ascend/cann-9.1.0/set_env.sh unset TORCH_DEVICE_BACKEND_AUTOLOAD python "TorchAir-GE/1_改写脚本.py" 2>&1 | tee /tmp/torchair-ge-benchmark.txt最小复现代码
以下代码是本次测试脚本中实际使用的计时核心,包含 NPU 同步、首次调用单独计时和稳态平均计时:
import time import torch import torch_npu import torchair def sync(device): if device.type == "npu": torch.npu.synchronize() def average_time(fn, device, repeats=5): sync(device) start = time.perf_counter() for _ in range(repeats): fn() sync(device) return (time.perf_counter() - start) / repeats class TinyModel(torch.nn.Module): def __init__(self): super().__init__() self.linear = torch.nn.Linear(128, 64) def forward(self, x): return self.linear(x).gelu() device = torch.device("npu:0") model = TinyModel().to(device).eval() x = torch.randn(2, 128, device=device) backend = torchair.get_npu_backend() with torch.no_grad(): eager_time = average_time(lambda: model(x), device) compiled = torch.compile(model, backend=backend) sync(device) start = time.perf_counter() compiled(x) sync(device) first_compile_time = time.perf_counter() - start compiled_time = average_time(lambda: compiled(x), device) print(f"Eager average time: {eager_time:.6f} s") print(f"First compiled call time: {first_compile_time:.6f} s") print(f"Compiled average time: {compiled_time:.6f} s")实际输出
本次 TorchAir-GE 端到端测试的实际输出为:
预期结果
官方文档或众测任务说明应统一明确:
建议
建议提供统一的性能测试模板,并至少输出:
如果不同后端不能使用完全相同的计时方法,也建议分别说明限制和可比范围。
欢迎加入社区,感谢您对社区的贡献 🎉!