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

ibm-granite/granite-timeseries-patchtst - NPU

#NPU

Granite TimeSeries PatchTST-FM(PatchTST-FM)大上下文多变量时间序列概率预测基础模型,已适配华为昇腾 Ascend 910(npu:0)真实推理。模型权重来自官方仓库 ibm-granite/granite-timeseries-patchtst(revision 151f9c6d576281b95c2ff784d0863bd3f12c80f1),架构为 IBM PatchTSTFMForPrediction(99 分位 quantile head,点预测为分位数积分均值)。

  • 任务类型:多变量时间序列概率预测(点预测 + 99 个分位数)
  • 输入窗口:context_length = 8192(本演示使用 512 步上下文,短序列自动按均值左填充并掩码)
  • 预测步长:prediction_length = 64
  • 通道数:7(ETTh1:HUFL, HULL, MUFL, MULL, LUFL, LULL, OT)
  • 参数量:约 2.58 亿(float32,权重约 1.03 GB)
  • 归一化:模型内置 RevIN,内部按窗口标准化并反变换回原始量纲

数据契约

  • 数据来源:ETTh1(https://github.com/zhouhaoyi/ETDataset),小时级,17420 行,SHA-256 f18de3ad269cef59bb07b5438d79bb3042d3be49bdeecf01c1cd6d29695ee066
  • 列顺序固定为 HUFL, HULL, MUFL, MULL, LUFL, LULL, OT(float32 原始值,不重采样)
  • 划分(与官方 demo 一致):train = [0, 8640),test = [11008, 14400)
  • 推理窗口:context 512 → horizon 64,窗口完全位于 test split 内,不越界
  • 缩放:模型 RevIN 内部标准化并反变换,输出为原始量纲;分位数与点预测均已反变换

环境

  • 操作系统:Linux aarch64
  • NPU:Ascend 910(Atlas 800 A2,64 GB HBM,Ascend910_9362)
  • CANN:8.5.1
  • torch 2.9.0+cpu / torch_npu 2.9.0.post1+gitee7ba04 / transformers 4.57.6 / granite-tsfm 0.3.8

安装

pip install -r requirements.txt
# 需要已安装对应版本的 torch_npu + CANN 工具链

NPU 推理

python inference.py                # 默认 npu:0,加载本地 model/ 权重
python inference.py --bench        # 稳定延迟基准(warmup 3,runs 10)
python inference.py --consistency  # CPU vs NPU 一致性检查
python inference.py --device cpu   # CPU 运行

首次运行会自动下载权重到 model/、下载 ETTh1.csv 到 data/(已有则复用本地文件)。模型加载使用本机 granite-tsfm 的 PatchTSTFMForPrediction,无 trust_remote_code 执行。

真实结果(npu:0)

代表窗口(test split 最后 512→64 步,原始量纲,7 通道):

指标值
点预测 MAE2.7056
点预测 RMSE6.4983
点预测 SMAPE0.4565
q50 中位数 MAE3.0147

OT 通道前 6 步(point forecast / q50 / ground truth):

steppredq50gt
03.81143.84654.2910
13.77003.77254.8540
23.85583.85445.0650
34.07474.10804.9950
44.22834.25404.6430
54.39814.43044.5020

输出形状:点预测 (1, 64, 7),分位数 (1, 99, 64, 7),99 个分位水平随概率单调不减。

CPU-NPU 一致性

同一权重、输入、seed、eval mode、float32:

  • CPU 与 NPU 输出形状一致 (64, 7),均有限值
  • max_abs_error = 4.96e-5,mean_abs_error = 2.59e-6
  • atol=1e-4, rtol=1e-3 判定 PASS

性能(npu:0,float32,batch=1)

  • 首轮编译(首次运行,含图编译):194.0 ms
  • 稳定延迟(预热 3 次、测试 10 次):avg 13.13 ms / min 13.06 ms / max 13.18 ms
  • p50 13.14 ms / p90 13.17 ms / p95 13.18 ms
  • 吞吐:约 76.2 windows/s
  • 峰值显存:1125.1 MB(远小于单卡 64 GB)

证据图

以下图片由 xterm.js 根据本次真实日志渲染生成(--style raw),非手工绘制或截图:

  • assets/agent_workflow.png:侦察、数据检查、下载、CPU 基线、NPU 推理、一致性、基准、提交校验全流程
  • assets/npu_device_call.png:npu-smi、NPU 可用性、设备名、模型参数 device/dtype、输入输出 Tensor device
  • assets/model_result.png:python inference.py 默认推理的真实完整输出(数据/窗口摘要、真实预测、分位数、指标、耗时、状态)

限制

  • 该模型为概率预测基础模型,官方权重训练数据涵盖合成与公开时序数据;跨域零样本效果需按场景另行评估
  • 本演示为单窗口(context 512 → horizon 64)数值一致性验证,不构成完整 benchmark 排名
  • 推理脚本在 CPU 与 NPU 上均使用 float32,未使用量化