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

TEMPO-ascend

TEMPO 时间序列预测基础模型适配昇腾NPU版本。

模型简介

  • 基础模型: Melady/TEMPO
  • 任务: 时间序列预测 (Time Series Forecasting)
  • 架构: GPT2-based Transformer
  • 类型: 时间序列基础模型 (Time Series Foundation Model)
  • 开发公司: Melady

模型特点

  • 基于 GPT2 的时间序列预测基础模型
  • 支持零样本时间序列预测
  • 无需额外训练或超参数调整
  • 适用于多种时间序列数据集 (ETTh, ETTm, electricity, traffic, weather)

模型配置

参数值
Base ModelGPT2
Parameters80M
GPT Layers6
D Model768
N Heads4
Sequence Length336
Prediction Length96
Label Length96
Enc Input Features7
Output Features1

模型文件

文件大小
TEMPO-80M_v1.pth279.23 MB
TEMPO-80M_v2.pth279.23 MB
总计558.46 MB

性能表现

指标数值
推理时间~1.37s (演示)
NPU显存占用~0.16GB (演示)
模型大小~560 MB

环境依赖

torch>=2.0.0
torch_npu>=2.0.0
numpy>=1.21.0
transformers>=4.30.0

分步推理流程

1. 安装依赖

cd /workspace/agent1/TEMPO-ascend
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple

2. 运行推理

cd /workspace/agent1/TEMPO-ascend
python inference.py --device npu:0 --show_npu_memory

3. 参数说明

  • --model_path: 模型路径,默认 /workspace/agent2/Melady/TEMPO
  • --device: 运行设备,默认 npu:0
  • --show_npu_memory: 显示NPU显存使用情况

测试用例与输出

测试代码

import torch

device = "npu:0"
batch_size = 1
seq_len = 336
pred_len = 96
enc_in = 7

time_series_input = torch.randn(batch_size, seq_len, enc_in, dtype=torch.float32).to(device)

predictions = model(time_series_input)

完整输出

[设备] npu:0
NPU设备数量: 1
  设备 0: Ascend910B2

[模型] TEMPO
[任务] 时间序列预测 (Time Series Forecasting)
[架构] GPT2-based Transformer
[类型] 时间序列基础模型 (Time Series Foundation Model)

[模型配置]
  Base Model: GPT2
  Parameters: 80M
  GPT Layers: 6
  D Model: 768
  N Heads: 4
  Sequence Length: 336
  Prediction Length: 96
  Label Length: 96
  Enc Input Features: 7
  Output Features: 1

[模型文件]
  TEMPO-80M_v1.pth: 279.23 MB
  TEMPO-80M_v2.pth: 279.23 MB
  总计: 558.46 MB

[构建测试输入]
  Batch Size: 1
  Sequence Length: 336
  Prediction Length: 96
  Enc Input Features: 7
  D Model: 768
  N Heads: 4
  GPT Layers: 6

[输入张量形状]
  Time Series Input: (1, 336, 7)
  Prediction Output: (1, 96)

运行TEMPO推理演示...

======================================================================
加载模型到NPU...
======================================================================

======================================================================
前向传播...
======================================================================

======================================================================
NPU 显存状态
======================================================================
[NPU显存] 已分配=0.1585GB | 缓存=0.1797GB | 峰值=0.1614GB

======================================================================
NPU 信息 (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.0       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3670 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1168758       | python                   | 300                     |
+===========================+===============+====================================================+


======================================================================
输出摘要
======================================================================
  模型: TEMPO
  任务: 时间序列预测
  输入形状: torch.Size([1, 336, 7])
  输出形状: torch.Size([1, 96])
  预测值范围: [-0.3800, 1.0941]
  总耗时: 1.3748s
  输出 finite: True

  前5个预测值:
    t+1: -0.3143
    t+2: 0.1994
    t+3: 0.1360
    t+4: -0.1187
    t+5: 0.6824

完整使用

完整模型使用:

import numpy as np
import torch
from transformers import GPT2Model

model = TEMPO.load_pretrained_model(
    device=torch.device('npu:0'),
    repo_id="Melady/TEMPO",
    filename="TEMPO-80M_v1.pth",
    cache_dir="./checkpoints"
)

input_data = np.random.rand(336)
with torch.no_grad():
    predicted_values = model.predict(input_data, pred_length=96)
print("Predicted values:", predicted_values)

架构详情

推理流程

时间序列历史数据 (336步, 7特征)
                    |
            Embedding层
                    |
            GPT2 Transformer Encoder (6层)
                    |
            输出投影层
                    |
            预测序列 (96步)

核心组件

  1. Input: 时间序列历史数据
  2. Embedding: 特征嵌入
  3. GPT2 Transformer: 6层Transformer编码器
  4. Output Projection: 预测输出

应用场景

  • 时间序列预测
  • 能源消耗预测
  • 交通流量预测
  • 气象预测
  • 金融时间序列分析

注意事项

  1. 当前演示使用随机张量展示NPU推理流程
  2. 模型约 560MB
  3. Transformer Encoder 部分可能回退到 CPU
  4. 支持 fp32 精度

参考链接

  • TEMPO 官方模型
  • TEMPO GitHub
  • TEMPO Paper