昇腾 NPU 模型适配(repository_type=model) 原始模型:ibm-research/ttm-r3 权重镜像:https://ai.gitcode.com/hf_mirrors/ibm-research/ttm-r3 许可证:CC-BY-NC-SA-4.0 适配结论:PASS(NPU 前向 / 精度 / 性能 / 稳定性全部通过)
TTM-R3 是 IBM TinyTimeMixer(TTM)系列的下一代时序基础模型,采用
残差/趋势双预测器(residual_forecaster / trend_forecaster) 结构,
decompose=true 将序列分解为长期趋势与高频残差分别建模。支持零样本预测、
少样本微调与高吞吐批量推理。
context_length=512,prediction_length=30,num_input_channels=1,
d_model=128,num_layers=10,distribution_output=student_t。model.safetensors(5.7MB,468 个 tensor key,residual/trend 双前缀)。tsfm_public.models.tinytimemixer.TinyTimeMixerForDecomposedPrediction
(transformers 主库未合入 tinytimemixer,0.2.28 也不支持 r3 的
residual/trend 双预测器权重键,必须 0.3.8+)。| 组件 | 版本 |
|---|---|
| 操作系统 | Ubuntu 22.04 (aarch64) |
| Python | 3.11.14 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| CANN | 8.5.1 |
| transformers | 4.57.6 |
| granite-tsfm | 0.3.8(vendor 到 pylibs/,--no-deps) |
| NPU 设备 | Ascend910_9362 × 2(npu:0 推理) |
# torch / torch_npu / CANN / transformers 已随环境提供,无需覆盖
pip install --target pylibs granite-tsfm==0.3.8 --no-deps \
-i https://repo.huaweicloud.com/repository/pypi/simple/# 默认在 npu:0 上完成真实推理(可 --cpu 切到 CPU)
python inference.py输入:past_values [batch, seq_len, num_input_channels](seq_len>=512 右截断到 512)。
输出:确定性点预测 prediction_outputs [batch, 30, 1]。
3 组测试输入,全部输出形状正确、全有限、无 NaN/Inf,
模型首个真实参数位于 npu:0:
| 组 | 输入 | 输出形状 | 全部有限 | 延迟 |
|---|---|---|---|---|
| single_series_ctx512 | 1×512 | [1, 30, 1] | ✅ | 0.27s(含首次编译) |
| batch4_ctx512 | 4×512 | [4, 30, 1] | ✅ | 0.05s |
| single_series_ctx1024 | 1×1024(右截断到 512) | [1, 30, 1] | ✅ | 0.02s |
权重证据:model.safetensors size=5729424 B,sha256=74dcec10fa75f334f6e6ddb8f6df19452de1c70a1ad43b87e5064c4e30f930cc。
CPU 与 NPU 各自独立进程(CPU 隔离 TORCH_DEVICE_BACKEND_AUTOLOAD=0),
对完全相同输入对比确定性点预测:
| 组 | 形状一致 | rel-L2 | cosine | MAE | max_abs |
|---|---|---|---|---|---|
| single_series_ctx512 | ✅ | 2.164e-04 | 1.00000000 | 6.434e-04 | 1.847e-03 |
| batch4_ctx512 | ✅ | 2.422e-04 | 0.99999994 | 6.910e-04 | 1.762e-03 |
| single_series_ctx1024 | ✅ | 3.306e-04 | 0.99999982 | 9.981e-04 | 2.057e-03 |
验收标准:FP32 下 atol=5e-3, rtol=1e-3 全部通过;rel-L2 < 1%:全部通过。 本验证为固定样例一致性对比,非完整数据集精度评测。数值误差来源于 NPU 与 CPU 浮点累加顺序差异,在可接受范围。
batch8 / ctx512 / pred30,warmup 5 次 + 正式 20 次,每次 forward 前后
torch.npu.synchronize():
| 指标 | 数值 |
|---|---|
| 平均延迟 | 18.63 ms |
| p50 延迟 | 18.62 ms |
| p95 延迟 | 18.89 ms |
| 吞吐 | 429.44 series/s |
三张证据图由 xterm.js 根据本次真实日志生成(下载→侦察→NPU 推理→验证→性能→稳定性)。



ascend-model/ 加载,不依赖运行时下载。#NPU #Ascend #Ascend910 #torch_npu #tinytimemixer #time-series-forecasting #ttm-r3