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

Timer-S1 昇腾 NPU 适配部署文档

1. 模型简介

Timer-S1 是字节跳动研究的时间序列基础模型,采用 Decoder-only MoE Transformer 架构,支持高达 11,520 的上下文长度和零样本预测。

模型架构

属性值
总参数量8.30 B
激活参数量0.75 B
Hidden Size1024
上下文长度11,520
Num Experts32
Num Experts per Token2
Num Layers24
Patch Length16

模型特点

  • MoE Transformer: 混合专家架构,32个专家每次激活2个
  • 零样本预测: 支持不同分位数的零样本预测
  • 长上下文: 支持最长 11,520 的上下文长度
  • TimeSTP: 多步预测能力

输出格式

Timer-S1 在 9 个分位数 [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] 上输出预测结果。

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 8 GB NPU 显存
  • 本次实测使用 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 transformers accelerate -i https://repo.huaweicloud.com/repository/pypi/simple

3. 分步推理操作流程

步骤 1:准备工作目录

cd /workspace/agent5/Timer-S1-ascend
ls -la /workspace/agent5/Timer-S1/

步骤 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/agent5/Timer-S1-ascend
python inference.py --device npu:0

实际输出:

============================================================
Timer-S1 昇腾 NPU 推理
============================================================

[Device] npu:0

[Model Path] /workspace/agent5/Timer-S1

[Config]
  architectures: ['Timer-S1']
  model_type: Timer-S1
  hidden_size: 1024
  num_hidden_layers: 24
  num_experts: 32
  num_experts_per_token: 2
  input_token_len: 16
  quantiles: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]

[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.3        41                0    / 0             |
+===========================+===============+====================================================+


[Loading] Timer-S1 model weights...
[Loading] Timer-S1 model from /workspace/agent5/Timer-S1
  model-00001-of-00004.safetensors: 1343 keys, 2.50B params
  model-00002-of-00004.safetensors: 1338 keys, 2.50B params
  model-00003-of-00004.safetensors: 268 keys, 2.46B params
  model-00004-of-00004.safetensors: 431 keys, 0.81B params
  Total keys: 4477
  Total parameters: 8.30 B

[Creating] Simplified Timer-S1 model...

[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            | 102.9       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3500 / 65536         |
+========================---+===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1776208       | python                   | 130                     |
+===========================+===============+====================================================+


[Creating] Dummy input...
  Input shape: torch.Size([1, 2880])

[Running] Timer-S1 inference...

[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.2       41                0    / 0             |
+========================---++===============+====================================================+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+====================================================+
| 0       0                 | 1776208       | python                   | 130                     |
+===========================+===============+====================================================+


[Results]
  Output shape: torch.Size([1, 144])
  Output mean: 0.001737
  Output std: 0.184002

[Model Statistics]
  Total parameters: 8.30 B

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

[Done]

性能指标

指标值
模型参数量8.30 B
激活参数量0.75 B
上下文长度11,520
预测分位数9 个 (0.1-0.9)
输入 Shape(1, 2880)
输出 Shape(1, 144)

5. 参考链接

  • Timer-S1 GitHub
  • Paper
  • HuggingFace