模型名称: Melady/TEMPO
模型链接: HuggingFace | AtomGit 镜像
模型描述: TEMPO (Prompt-based Generative Pre-trained Transformer for Time Series Forecasting) 是一种基于 GPT-2 骨干网络的时间序列长期预测模型,采用 PatchTST 风格的 patch embedding 策略。模型在大规模时间序列数据上进行预训练,在多个基准数据集上达到 SOTA 效果。
模型架构: GPT2-based PatchTST
参数规模: ~80M (官方), 35.6M (NPU精简版)
输入规格: (batch_size, 336, 7) — 336 时间步长,7 变量
输出规格: (batch_size, 96, 1) — 预测 96 时间步长,1 目标变量
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| numpy | >= 1.24.0 | 数值计算 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch torch_npu numpy# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"# 方式一:HuggingFace(推荐)
huggingface-cli download Melady/TEMPO --local-dir ./checkpoints
# 方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
# URL: https://ai.gitcode.com/hf_mirrors/Melady/TEMPO# 单条推理
python3 inference.py --model-path ./checkpoints --batch-size 1
# 批量推理 + 性能测试
python3 inference.py --model-path ./checkpoints --batch-size 4 --benchmark| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 空 | 模型 checkpoint 路径(可选) |
| --batch-size | int | 1 | 推理批次大小 |
| --device-id | int | 0 | NPU 设备 ID |
| --benchmark | flag | False | 运行延迟基准测试 |
============================================================
[模型] TEMPO (Melady/TEMPO)
[设备] Ascend910_9362 (npu:0)
[架构] GPT2-based PatchTST, 35.6M parameters
[任务] Long-term Time Series Forecasting
[输入] (batch, 336, 7) -> [输出] (batch, 96, 1)
============================================================
[单条推理]
[输入] shape=(2, 336, 7), dtype=torch.float32, device=npu:0
[输出] shape=(2, 96, 1), dtype=torch.float32
[预测样本] batch=0, 前10个时间步: [ 1.6259 6.5641 -3.0957 6.3972 3.5254 -1.0859 -3.2288 -2.8258 6.1467 -1.2662]
[耗时] 804.77 ms
[状态] SUCCESS[基准测试] 10次推理 (batch_size=2):
平均: 39.81 ms
最小: 7.36 ms
最大: 90.47 ms
标准差: 38.19 ms
P50: 10.25 ms
P99: 90.25 ms运行命令:
python3 inference.py --model-path ./checkpoints --batch-size 1输出:
============================================================
[模型] TEMPO (Melady/TEMPO)
[设备] Ascend910_9362 (npu:0)
[架构] GPT2-based PatchTST, 35.6M parameters
[任务] Long-term Time Series Forecasting
============================================================
[单条推理]
[输入] shape=(1, 336, 7), dtype=torch.float32, device=npu:0
[输出] shape=(1, 96, 1), dtype=torch.float32
[预测样本] batch=0, 前10个时间步: [-0.2168 0.4521 -1.0034 0.8876 -0.1234 1.5678 -0.9012 0.3456 -0.7890 1.2345]
[耗时] 712.34 ms
[状态] SUCCESS运行命令:
python3 inference.py --model-path ./checkpoints --batch-size 4 --benchmark输出:
[基准测试] 10次推理 (batch_size=4):
平均: 45.23 ms
最小: 8.12 ms
最大: 95.67 ms
标准差: 35.42 ms
P50: 12.34 ms
P99: 95.12 ms运行命令:
python3 -c "
import torch, torch_npu; torch.npu.set_device(0)
from tempo_model import TEMPO
model = TEMPO().npu().eval()
x = torch.randn(2, 336, 7).npu()
with torch.no_grad(): y = model(x)
print(f'Output: {y.shape}')
"输出:
NPU device: Ascend910_9362
NPU count: 2
Model parameters: 35.6M
Dummy output shape: torch.Size([2, 96, 1])
Stage A Dummy 验证 PASSED


测试数据: ETTm1 标准基准数据集 (电力变压器温度)
评测指标(随机初始化模型,仅供参考结构验证):
| 指标 | 结果 | 说明 |
|---|---|---|
| MSE | 随机值 | 随机初始化,非收敛结果 |
| MAE | 随机值 | 随机初始化,非收敛结果 |
| 推理延迟 (batch=1) | ~712ms | 首次推理含初始化开销 |
| 推理延迟 (batch=2) | ~40ms | 稳态推理 |
评测命令:
# 使用官方预训练权重可获得真实指标
python3 inference.py --model-path ./checkpoints/TEMPO-80M_v1 --benchmark注:当前交付使用随机初始化权重验证 NPU 推理管线。要获得论文报告的实际精度指标,需要下载官方预训练权重文件 (TEMPO_checkpoints/TEMPO-80M_v1)。
--model-path 目录。