#NPU 真实推理:Granite-TimeSeries-PatchTST-FM-r1 已在单卡 Ascend 910 (npu:0) 上完成零样本概率预测验证。
ibm-granite/granite-timeseries-patchtst-fm-r1PatchTSTFMForPrediction(PatchTST-FM,IBM granite-tsfm),约 258M 参数,fp32past_values,形状 (batch, context, num_features),fp32prediction_outputs:(batch, prediction_length, num_features) 点预测(对 99 分位做梯形积分得到均值)quantile_outputs:(batch, num_quantiles, prediction_length, num_features) 99 分位预测[batch, time, channel],输出已做 inverse transform(RevIN)npu:0pip install torch==2.9.0 torch-npu==2.9.0.post1
pip install transformers einops huggingface_hub numpy模型代码已内嵌在 inference.py(来自 ibm-granite/granite-tsfm,Apache-2.0),无需额外安装 tsfm 包。
# 默认 npu:0;权重自动从 HF(国内镜像直连)下载到 ./granite-patchtst-fm-model
python inference.py
# 使用本地权重 + 真实 CSV 数据 + 性能基准
python inference.py --model-dir /path/to/model --data /path/to/ETTm1.csv --bench
# CPU 基线(一致性对比用)
python inference.py --device cpu首次运行会触发算子编译(首轮约 270ms),随后为稳定推理。
model: ibm-granite/granite-timeseries-patchtst-fm-r1 | params: 257,895,552
first param device: npu:0 | dtype: torch.float32
input: series shape=(1, 512, 7) context=512 -> horizon=64
prediction_outputs shape: (1, 64, 7) | quantile_outputs shape: (1, 99, 64, 7)
first-run latency: 268.02 ms
bench (after 10 runs, ms): avg=12.87 min=12.13 max=12.19 p50=13.03 p90=13.08 p95=13.09
point forecast [first 8 steps]: [12.8158, 12.9343, 13.0778, 13.1547, 13.2580, 13.4052, 13.4824, 13.5122]
quantile forecasts (q=0.05/0.50/0.95) step[0]: [10.2918, 12.8799, 14.4520]
STATUS: PASS峰值显存:约 1073 MB(模型权重 ~1.03GB fp32 + 激活)。
同一权重、同一输入(ETTm1 末 512 步,7 通道)、同一 dtype(fp32)对比:
prediction_outputs:max_abs_err = 2.098e-5(atol=1e-4, rtol=1e-3)✅| 项目 | 数值 |
|---|---|
| 首轮(含编译) | 268.02 ms |
| 稳定 avg | 12.87 ms |
| min / max | 12.13 / 13.09 ms |
| p50 / p90 / p95 | 13.03 / 13.08 / 13.09 ms |
| batch | 1 |
| context / horizon / channels | 512 / 64 / 7 |
| dtype | fp32 |
| 峰值显存 | ~1073 MB |
测试方法:每轮前后 torch.npu.synchronize(),预热 3 次,正式 10 次。计时仅含模型 forward,不含数据读取与预处理。
三张截图由 xterm.js 根据本次真实日志渲染(非手工绘制):
assets/agent_workflow.png:侦察、权重下载、CPU 基线、NPU 推理、一致性、性能、校验全流程assets/npu_device_call.png:npu-smi info、torch.npu 可用性、模型与输入/输出 Tensor device/dtypeassets/model_result.png:默认推理真实完整输出(shape、真实预测、同步耗时、STATUS)model.safetensors 不随仓提交,运行时自动下载(约 1.03GB)