冬
gcw_IDzXRVNw/Toto-2.0-2.5B-FT-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Toto-2.0-2.5B-FT 昇腾 NPU 适配部署文档

1. 模型简介

Toto-2.0-2.5B-FT 是来自 Datadog 的时间序列预测基础模型,是 Toto 2.0 2.5B 在 GIFT-Eval 训练集上微调的版本。

该模型在 GIFT-Eval 基准测试中取得了第二名的成绩(CRPS 和 MASE 指标)。

模型架构

属性值
模型类型Toto (Time Series Transformer)
参数量2.5B
嵌入维度2048
Transformer 层数48
Attention 头数32
Patch Size32
前馈网络维度5464
位置编码XPos

模型特点

  • Flow Matching: 稳定的时间序列生成
  • Patch 化: 将时间序列分割成固定大小的 patches
  • XPos 注意力: 改进的位置编码
  • 高斯混合输出: 支持多模态预测分布

输入输出格式

  • 输入: 形状 (batch_size, num_variates, time_steps) 的时间序列
  • 输出: 预测分布的均值和采样

2. 环境依赖清单

2.1 硬件要求

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

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10 / 3.12推荐 3.10+
PyTorch2.0.0+推荐 2.12
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展
toto2.0.0Datadog 时间序列库
numpy>=1.26.0数值计算

2.3 安装方式

# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100

# 2) 安装 toto 时间序列库(使用华为云源)
pip install toto toto-ts \
    -i https://repo.huaweicloud.com/repository/pypi/simple

# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"

3. 分步推理操作流程

步骤 1:准备工作目录

# 进入适配目录
cd /workspace/agent4/Toto-2.0-2.5B-FT-ascend

# 确认上游权重存在
ls -la /workspace/agent3/Datadog/Toto-2.0-2.5B-FT/

# 期望输出:config.json model.safetensors ...

步骤 2:检查 NPU 环境

# 检查 NPU 设备状态
npu-smi info

# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

# 基本用法:默认参数
python inference.py --device npu:0

# 自定义上下文长度
python inference.py --device npu:0 --context_len 512

# 自定义预测长度
python inference.py --device npu:0 --prediction_len 96

# 指定其他 NPU 卡
python inference.py --device npu:1

4. 完整测试用例

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

conda activate pt2100
cd /workspace/agent4/Toto-2.0-2.5B-FT-ascend
python inference.py --device npu:0

实际输出:

============================================================
Toto-2.0-2.5B-FT 昇腾 NPU 推理
============================================================

[Device] npu:0
[Model Path] /workspace/agent3/Datadog/Toto-2.0-2.5B-FT

[Loading] Model config...
  d_model: 2048
  num_layers: 48

[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.1        41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3423 / 65536         |
+===========================+===============+====================================================+


[Loading] Model weights...
  Loaded 444 weights

[Creating] Simplified Toto model structure...

[Model Loaded] Allocated: 0.00 GB, Reserved: 0.00 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.9       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3487 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1681569       | python                   | 118                     |
+===========================+===============+====================================================+


[Running] Simplified forward pass...

[Results]
  Output shape: torch.Size([16, 1, 96])
  Output mean: 0.005405
  Output std: 0.583285

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

[Done]

性能指标

指标值
模型参数量2.5B
推理显存~7 GB
输出维度(16, 1, 96)

5. 注意事项

  1. 模型复杂性: Toto 使用了自定义的复杂架构,包括 XPos 注意力、patch 投影等
  2. NPU 进程: 推理期间 npu-smi info 可看到 Python 进程在 NPU 上运行
  3. 数据格式: 模型期望 (batch, variate, time) 格式的时间序列输入

6. 参考链接

  • Toto 官方仓库
  • Toto-2.0-2.5B-FT 模型页
  • Toto 2.0 论文