jsjs1258/ibm-granite-granite-timeseries-patchtst-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-granite/granite-timeseries-patchtst (Ascend NPU)

#NPU 昇腾 NPU 时间序列预测适配。把 IBM Granite PatchTST 时间序列基础模型真实运行在单卡昇腾 910(npu:0)上,完成 ETTh1 多变量点预测(context=512 → horizon=96)。

  • 模型:ibm-granite/granite-timeseries-patchtst
  • 架构:PatchTSTForPrediction(channel-independent Transformer,PatchTST ICLR 2023)
  • 任务:多变量时间序列点预测(forecasting)
  • 参数量:0.614M(float32)
  • 权重来源:HuggingFace ibm-granite/granite-timeseries-patchtst,权重 2.47 MB(model.safetensors)

数据契约

使用官方模型卡对应的 ETTh1(电力变压器油温,逐小时,7 通道)公开数据集:

  • 通道顺序(固定,不得改变):HUFL, HULL, MUFL, MULL, LUFL, LULL, OT
  • 轴顺序:(batch, context, channel),batch_first=True
  • 数据量:17,420 行,时间粒度 hourly
  • 划分:取后 20% 作为测试段,取末尾 512 步作为上下文窗口
  • context = 512 小时 → 预测 horizon = 96 小时
  • 数据来源:ETT-small/ETTh1.csv(https://github.com/zhouhaoyi/ETDataset)
  • 缩放入口:模型内部 RevIN,输出 loc / scale

环境

  • 昇腾:Ascend910(Ascend910_9362),CANN 8.5.1
  • Python 3.11.14
  • PyTorch 2.9.0 + torch_npu 2.9.0.post1
  • transformers 4.57.1,numpy,pandas

安装

pip install -r requirements.txt

NPU 推理

默认在 npu:0 加载真实权重完成推理(首次运行会自动经 HF 镜像下载权重与 ETTh1 数据到本地):

python inference.py

也可指定本地已下载的权重目录与数据文件:

python inference.py --model-dir /path/to/model --data /path/to/ETTh1.csv

说明:

  • 所有模型参数与输入/输出 tensor 显式置于 npu:0。
  • 计时前后调用 torch.npu.synchronize()。
  • 首轮包含图编译,稳定阶段预热 3 次、正式测试 10 次。
  • 退出码非零即失败;请求 CPU 设备会直接失败(本适配目标为 NPU)。

真实结果(npu:0)

  • 输入:(1, 512, 7) float32,device npu:0
  • 输出:(1, 96, 7) forecast,device npu:0
  • 首轮(含编译):203.2 ms;稳定平均 2.5 ms(min 2.4 / max 2.5 / p50 2.5 / p90 2.5 / p95 2.5)
  • 吞吐:约 405 windows/s
  • 峰值显存:5.4 MiB
  • 96h 预测均值:4.0611

前 8 步预测(7 通道):

step 1: [11.035  3.300  7.250  1.704  3.388  1.275  9.548]
step 2: [11.832  3.703  8.020  2.031  3.477  1.280  9.351]
step 3: [12.833  4.241  9.037  2.461  3.555  1.287  9.183]
...

一致性(CPU-NPU)

相同权重、相同数据切片、相同 seed、eval 模式、float32:

  • 比较原始 forecast(96×7)
  • atol=1e-4, rtol=1e-3
  • max_abs_error = 7.63e-4,mean_abs_error = 1.24e-4 → 通过

性能

指标值
首轮(compile+infer)203.2 ms
avg / min / max2.5 / 2.4 / 2.5 ms
p50 / p90 / p952.5 / 2.5 / 2.5 ms
吞吐~405 windows/s
峰值 NPU 显存5.4 MiB
输入 shape / dtype(1, 512, 7) / float32

证据图

以下三张图片由 xterm.js 依据本次真实运行日志生成(非原始桌面截图):

  • assets/agent_workflow.png — 侦察、数据检查、加载、NPU 推理、一致性、性能与提交校验流程
  • assets/npu_device_call.png — npu-smi、NPU 可用性、设备名、模型参数/输入/输出 tensor device
  • assets/model_result.png — 默认 python inference.py 的真实完整输出

限制

  • 本模型为 ETTh1 7 通道预训练模型,输入通道数需为 7,通道顺序与模型卡一致。
  • 这是固定窗口(512→96)的真实 NPU 推理验证,并非完整 benchmark 排名。
  • 一致性为 smoke consistency(单窗口),阈值针对 FP32 设定。