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

Granite-TimeSeries-TTM-R2 (NPU)

#NPU 真实推理:ibm-granite/granite-timeseries-ttm-r2 已在单卡 Ascend 910 (npu:0) 上完成零样本时间序列点预测验证。

  • 模型:ibm-granite/granite-timeseries-ttm-r2(TinyTimeMixer,TTM-R2,IBM granite-tsfm)
  • 架构:TinyTimeMixerForPrediction,约 0.8M 参数,fp32
  • 任务:零样本点预测(forecasting)
  • 配置:context_length=512, prediction_length=96, d_model=192, num_layers=2, patch_length=64, 单通道

数据契约

  • 输入:past_values,形状 (batch, context, num_features),fp32,轴顺序 [batch, time, channel]
  • 本次验证输入:ETTh1 数据集(公开 benchmark,https://github.com/zhouhaoyi/ETDataset)的 OT 通道(油温,小时级)最后 512 步 → 预测未来 96 步
    • 文件 SHA-256:f18de3ad269cef59bb07b5438d79bb3042d3be49bdeecf01c1cd6d29695ee066
    • 窗口:rows [8000:8512](context)→ [8512:8608](actual future)
    • 缩放:模型内部 std scaler(RevIN),输入未做外部归一化
  • 输出:prediction_outputs,形状 (batch, prediction_length, num_features),已 inverse transform
  • 完整 CSV 可通过环境变量 TTM_DATA_CSV 传入,脚本自动取最后 context+prediction 步

环境

  • Ascend CANN 8.5.1,torch 2.9.0,torch_npu 2.9.0.post1,transformers 4.57.6,Python 3.11
  • NPU:2 × Ascend910(HBM 64GB/卡),验证使用 npu:0

依赖

pip install -r requirements.txt

NPU 推理

python inference.py                 # 自动下载权重到 ./model 并跑 npu:0 推理
TTM_MODEL_DIR=/path python inference.py   # 使用本地权重
python inference.py --bench         # 稳定延迟 benchmark

模型为自包含实现:inference.py 内嵌 TinyTimeMixer 配置与建模代码(镜像自 IBM granite-tsfm / tinytimemixer,Apache-2.0),不依赖 trust_remote_code 执行。权重加载遵守 HF_ENDPOINT 镜像配置,正式推理从本地加载。

真实结果(npu:0)

  • 预测(前 8 步):[21.579, 21.247, 21.089, 20.803, 20.508, 20.384, 20.164, 19.826]
  • 预测(后 8 步):[17.568, 17.772, 17.990, 18.261, 18.480, 18.841, 19.140, 19.237]
  • 与真实未来值对比:MAE = 1.076,RMSE = 1.374

CPU-NPU 一致性

同一权重、同一数据窗口、同一 seed、fp32:

输出shapemax_abs_errormean_abs_erroratolrtol结果
prediction_outputs(1, 96, 1)0.0008640.0004061e-41e-3PASS

NPU 推理全程在 npu:0 完成,无 CPU fallback。

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

  • 预热 1 次、正式 10 次,平均 4.58 ms/window,min 4.49 ms,max 4.64 ms,p50 4.59 ms
  • 吞吐:218.3 windows/s
  • 峰值 NPU 显存:约 3.2 MB

证据图

  • agent_workflow — 侦察、数据检查、CPU 基线、NPU 推理、一致性、benchmark、校验完整流程
  • npu_device_call — npu-smi、NPU 可用性、模型与输入输出 Tensor 设备
  • model_result — 默认 python inference.py 的真实完整输出

以上图片由 xterm.js 根据本次真实日志生成,非手工截图。

限制

  • 本模型为 TTM-R2 主分支点预测变体(512-96);预测仅含点估计,不含分位数输出。
  • 验证为 ETTh1 单通道零样本窗口;多通道/其他频率需按数据契约扩展输入。
  • 未做完整 benchmark 排名,数值一致性基于固定窗口。