Test-TTM-v1 是基于 TinyTimeMixer (TTM) 架构的时间序列预测模型。
本模型是 IBM Granite 时间序列模型系列的一部分,专为时间序列预测任务设计。
| 属性 | 值 |
|---|---|
| 模型类型 | TinyTimeMixerForPrediction |
| 参数量 | 0.81M |
| 上下文长度 | 512 |
| 预测长度 | 96 |
| Patch 长度 | 64 |
| Patch 步长 | 64 |
| 隐藏维度 | 192 |
| 编码器层数 | 2 |
| 解码器层数 | 2 |
| 解码器隐藏维度 | 128 |
| 频率调制 | 5 维 |
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.10 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| safetensors | >=0.4.0 | 权重加载 |
| granite-tsfm | 本地源码 | IBM 时间序列模型库 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 安装模型依赖(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple \
safetensors torch_npu numpy
# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent1/test-ttm-v1-ascend
# 确认上游权重存在
ls -la /workspace/agent2/ibm-research/test-ttm-v1/
# 确认 granite-tsfm 源码存在
ls -la /workspace/agent2/ibm-granite/granite-tsfm-main/# 检查 NPU 设备状态
npu-smi info
# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"# 基本用法:默认参数 (NPU:0)
python inference.py --device npu:0
# 指定其他 NPU 卡
python inference.py --device npu:1
# CPU 模式(仅在 NPU 不可用时使用)
python inference.py --device cpuconda activate pt2100
cd /workspace/agent1/test-ttm-v1-ascend
python inference.py --device npu:0实际输出:
[W822 14:05:00.000000000 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
============================================================
Test-TTM-v1 昇腾 NPU 推理
============================================================
[Device] npu:0
[Model Path] /workspace/agent2/ibm-research/test-ttm-v1
[Loading] TTM model from local granite-tsfm...
Config loaded: context_length=512, prediction_length=96
Model loaded successfully
Total params: 0.81M
[Model Loaded] 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 | 102.8 40 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3488 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1335088 | python | 120 |
+===========================+===============+====================================================+
[Creating] Dummy time series input...
Past values shape: torch.Size([1, 1, 512])
Freq token shape: torch.Size([1, 1])
[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 | 104.0 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3489 / 65536 |
+===========================+===============+====================================================+
[Running Time Series Prediction]...
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(MB)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 104.3 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3571 / 65536 |
+===========================+===============+====================================================+
[Results]
Output type: <class 'tsfm_public.models.tinytimemixer.modeling_tinytimemixer.TinyTimeMixerForPredictionOutput'>
Prediction outputs shape: torch.Size([1, 96, 512])
Output sample: [0.3826, 0.3126, 0.2770, 0.2523, 0.2382]
[Memory After Inference] Allocated: 0.01 GB, Reserved: 0.07 GB
[Done]✅ 验证要点:
解决方案:
source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh)npu-smi info 检查设备状态解释:TinyTimeMixer 模型在标准 transformers 包中不可用。IBM 提供了 granite-tsfm 库实现该模型。本脚本使用本地源码 /workspace/agent2/ibm-granite/granite-tsfm-main/。
解释:TTM 是轻量级预训练模型,参数量仅约 0.81M-3M,远小于 TimesFM、Moirai 等数十亿参数的模型。TTM 在零样本和少样本预测任务上实现了 SOTA 性能。
test-ttm-v1-ascend/
├── inference.py # 推理脚本(torch_npu 推理)
├── README.md # 本文档
├── requirements.txt # 依赖列表
└── assets/ # 资源占位目录上游权重目录(只读,未被修改):
/workspace/agent2/ibm-research/test-ttm-v1/
├── config.json # 模型配置
├── model.safetensors # 权重 (~3MB)
└── README.md # 原始文档本地 granite-tsfm 库(只读,未被修改):
/workspace/agent2/ibm-granite/granite-tsfm-main/
├── tsfm_public/
│ └── models/
│ └── tinytimemixer/ # TinyTimeMixer 模型实现
└── ...# Test-TTM-v1 昇腾 NPU 推理环境依赖
# 核心依赖(必须)
torch>=2.0.0
torch_npu
safetensors>=0.4.0
numpy使用方式:
# 激活环境
conda activate pt2100
# 安装依赖(华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -r requirements.txt