#NPU
将 HuggingFace 权重 ibm-research/test-patchtst(PatchTST,PatchTSTForPrediction)真实运行在单卡
昇腾 Ascend910(npu:0),完成 ETTh1 数据集 7 通道、context=512、horizon=96 的
多变量时间序列点预测,并完成 CPU-NPU 一致性验证与性能基准。
ibm-research/test-patchtst(main,safetensors,FP32)PatchTSTForPrediction(d_model=128,layers=3,heads=16,patch=12/stride=12)[batch, horizon, channels] 的逆缩放预测transformers.PatchTSTForPrediction + torch_npu,模型与输入 Tensor 显式位于 npu:0默认输入为真实可追溯的 ETTh1(电变压器温度,小时频率)测试窗口:
f18de3ad269cef59bb07b5438d79bb3042d3be49bdeecf01c1cd6d29695ee066HUFL, HULL, MUFL, MULL, LUFL, LULL, OT(7 通道)past_values--csv <file>,文件需含同样的 7 列且列序一致;--context/--horizon 控制切分| 项 | 值 |
|---|---|
| 设备 | Ascend910(npu-smi 显示 Ascend910,2 卡,使用 npu:0) |
| 驱动 / CANN | CANN 8.5.1,Ascend 驱动 25.5.5 |
| torch / torch_npu | torch 2.9.0+cpu / torch_npu 2.9.0.post1+gitee7ba04 |
| transformers | 4.57.6 |
| numpy / pandas | 1.26.4 / 2.3.3 |
pip install -r requirements.txt
# NPU 侧需先安装与 CANN 匹配的 torch_npu(Ascend PyTorch 适配器,非 PyPI 发行)# 默认:从 HF 拉取权重(HF_ENDPOINT 默认 hf-mirror.com,可覆盖),使用内嵌 ETTh1 窗口,在 npu:0 推理
python inference.py
# 使用本地权重目录
python inference.py --model-path /path/to/model_dir
# 使用自定义 CSV(列序同 ETTh1)
python inference.py --csv /path/to/data.csv --context 512 --horizon 96脚本为自包含实现:模型权重从本地目录 / 缓存 / HF 仓库解析;无 NPU 时明确报错并返回非零, 不做静默 CPU fallback;默认执行 3 次预热 + 10 次计时推理,输出同步耗时与状态。
默认 python inference.py 在 npu:0 的真实输出(ETTh1 最后 96 步,逆缩放原始单位):
[output] prediction_outputs shape=(1, 96, 7)
[output] OT(7th) channel first_12=[6.299, 6.152, 6.0873, 6.1828, 6.2289, 6.2734, 6.4228, 6.3995, 6.6339, 6.8307, 6.8432, 6.9466]
[result] mae_vs_truth=1.398693 rmse_vs_truth=2.162873loc/scale 与预测均以原始单位给出同一权重、同一窗口、同一 seed(0)、eval 模式、FP32。输出保存为 .npy 后使用
compare_outputs.py --task forecasting --atol 1e-3 --rtol 1e-2 校验:
cpu_shape=[1,96,7] npu_shape=[1,96,7] finite=true
max_abs_error=0.001003 mean_abs_error=0.000194 passed=trueFP32 下 CPU/NPU 最大绝对误差约 1e-3、平均约 2e-4,在浮点计算差异范围内。
预热 3 次后正式计时 10 次(每轮前后 torch.npu.synchronize()),batch=1,shape=[1,512,7],FP32:
avg=2.444ms min=2.413ms max=2.521ms p50=2.439ms p90=2.458ms p95=2.49ms以下三张 PNG 由 xterm.js 根据本次真实日志渲染(render_xterm_evidence.mjs --style raw),
仅展示本次会话真实 stdout/stderr,非手工补写或绘图库模拟:
assets/agent_workflow.png:侦察、数据检查、下载、加载、NPU 推理、一致性、性能与提交校验assets/npu_device_call.png:npu-smi、NPU 可用性、设备名、模型参数 device/dtype、输入输出 Tensor deviceassets/model_result.png:默认 python inference.py 的完整真实输出(schema、真实预测、同步耗时、状态)--csv 提供业务数据--model-pathtest-patchtst 为 ibm-research 提供的测试型 checkpoint,官方完整预训练权重见
https://huggingface.co/ibm-granite/granite-timeseries-patchtst