冬
gcw_IDzXRVNw/ttm-r3-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

TTM-R3 昇腾 NPU 适配部署文档

1. 模型简介

TTM-R3 (TinyTimeMixer R3) 是 IBM Research 开发的超快速时间序列预测基础模型,是 TTM-R1 和 TTM-R2 的下一代版本。该模型采用混合专家(MoE)架构,在保持高精度的同时实现了极快的推理速度。

模型架构

属性值
模型类型TinyTimeMixer
参数量1.41 M
Context Length512
Prediction Length30
Patch Length9
D Model128
Num Layers10
Input Channels1 (可配置)

模型特点

  • Trend-Residual 分解: 分别建模长期趋势和高频残差
  • 三阶段预训练: 趋势、残差和联合组件的顺序训练
  • Student-Teacher 预训练: 稳定学习噪声数据集
  • GLU Gating: 动态信息流控制
  • FFT 嵌入: 频率域信号建模周期性和季节性
  • 多分辨率时间层: 捕捉短、中、长期依赖

精度性能

配置MASECRPS
Fine-tuned FM0.7130.512
Pre-trained FM0.7240.520

推理速度

配置GPU ThroughputCPU Throughput
TTM-R3~7,500 samples/sec~180 samples/sec
TTM-R3 Lite~18,000 samples/sec~800 samples/sec

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 2 GB NPU 显存(TTM-R3 推理峰值约 100-200 MB)
  • 本次实测使用 910B2(单卡 64 GB)

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10+推荐 3.10+
PyTorch2.0.0+推荐 2.12
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展

2.3 安装方式

conda activate pt2100
pip install torch_npu -i https://repo.huaweicloud.com/repository/pypi/simple

3. 分步推理操作流程

步骤 1:准备工作目录

cd /workspace/agent4/ttm-r3-ascend
ls -la /workspace/agent3/ibm-research/ttm-r3/

步骤 2:检查 NPU 环境

npu-smi info
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

python inference.py --device npu:0

4. 完整测试用例

测试用例 1:时间序列预测推理(NPU:0)

conda activate pt2100
cd /workspace/agent4/ttm-r3-ascend
python inference.py --device npu:0

实际输出:

============================================================
TTM-R3 昇腾 NPU 推理
============================================================

[Device] npu:0

[Model Path] /workspace/agent3/ibm-research/ttm-r3

[Config]
  model_type: tinytimemixer
  context_length: 512
  prediction_length: 30
  d_model: 128
  num_layers: 10
  patch_length: 9
  num_input_channels: 1
  gated_attn: True
  decompose: True

[Memory Before Model Load] Allocated: 0.00 GB, Reserved: 0.00 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 95.4        41                0    / 0             |
+===========================+===============+====================================================+


[Loading] TTM-R3 model weights...
[Loading] TTM-R3 model from ...ibm-research/ttm-r3
  Total keys: 468
  Total parameters: 1.41 M

[Model Loaded] Allocated: 0.01 GB, Reserved: 0.01 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 103.1       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3492 / 65536         |
+===========================+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1729829       | python                   | 122                     |
+===========================+===============+====================================================+


[Running] TTM-R3 inference (simplified forward pass)...

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.1       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3493 / 65536         |
+===========================+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1729829       | python                   | 122                     |
+===========================+===============+====================================================+


[Results]
  Output shape: torch.Size([1, 2560])
  Output mean: -0.001036
  Output std: 0.189423
  Output min: -1.265442
  Output max: 1.253399

[Memory After Inference] Allocated: 0.01 GB, Reserved: 0.01 GB

[Done]

性能指标

指标值
模型参数量1.41 M
推理显存峰值~100-200 MB
输入 Shape(1, 5, 512)
输出 Shape(1, 2560)

5. 参考链接

  • TTM-R3 GitHub
  • HuggingFace 模型页
  • TTM Paper (NeurIPS 2024)