g
gcw_coj3XaOd/Datadog-Toto-2.0-22m
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Toto-2.0-22m 昇腾NPU部署文档

1. 模型简介

模型名称: Datadog/Toto-2.0-22m 模型链接: HuggingFace 模型描述: Toto 2.0 是 Datadog 开发的时序预测基础模型系列,使用 u-μP 缩放的 Transformer 架构,支持多变量时间序列的零样本预测。22m 版本具有约 2191 万参数,在保持高效推理的同时达到优秀的预测精度。 模型架构: Decoder-only Patched Transformer(交替时间轴/变量轴注意力) 参数规模: 22M (21,915,584) 任务类型: 时间序列预测 (Time Series Forecasting)

性能指标

数据集CRPSMASE
BOOM (Observability)0.3630.601
GIFT-Eval0.4960.719
TIME0.5560.668

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch2.1.0+PyTorch 框架
torch_npu2.1.0+昇腾 NPU 后端
toto-2>= 2.0.0Toto 2.0 模型库
numpy>= 1.26.0数值计算
einops>= 0.7.0张量操作
safetensors>= 0.4.0模型权重加载
huggingface_hub>= 0.20.0模型加载
gluonts>= 0.16.0时序预测工具包(可选)
昇腾驱动CANN 8.0+推荐 8.5.1

安装命令:

pip install torch torch_npu toto-2 numpy einops safetensors huggingface_hub

注意: toto-models 包要求 Python >= 3.12。如使用 Python 3.11,请直接安装 toto-2 包。


3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info
python3 -c "import torch_npu; import torch; print(torch.npu.is_available(), torch.npu.get_device_name(0))"

3.2 运行推理

# 基本推理(horizon=96)
python inference.py --horizon 96

# 自定义参数
python inference.py --context-len 512 --horizon 192 --n-variates 1

# 带基准测试
python inference.py --horizon 96 --benchmark --benchmark-runs 10

3.3 推理参数说明

参数类型默认值说明
--model-pathstr/data/Datadog-Toto-2.0-22m模型路径
--context-lenint512输入时间序列长度
--horizonint96预测时间步数
--n-variatesint1变量数量
--benchmarkflagFalse运行基准测试
--benchmark-runsint10基准测试运行次数
--devicestrnpu推理设备 (npu/cpu)

4. 测试样例及输出结果

样例 1:单步预测(horizon=96)

输入:

# 随机生成测试数据(实际使用时替换为真实时间序列)
# 形状: (batch=1, n_variates=1, time_steps=512)
target = torch.randn(1, 1, 512, device="npu:0")
target_mask = torch.ones_like(target, dtype=torch.bool)
series_ids = torch.zeros(1, 1, dtype=torch.long, device="npu:0")

输出:

[INFO] 模型参数数量: 21,915,584
[INFO] 模型配置: d_model=512, layers=6, heads=8, patch_size=32
[INFO] 推理耗时: 0.2851秒
[INFO] 输出形状: torch.Size([9, 1, 1, 96]) (quantiles, batch, variates, horizon)
[INFO] 分位数水平: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]

样例 2:NPU 基准测试(5 次推理)

命令:

python inference.py --horizon 96 --benchmark --benchmark-runs 5

输出:

[INFO] 基准测试: 5 次推理
  Run 1/5: 0.0147s
  Run 2/5: 0.0128s
  Run 3/5: 0.0136s
  Run 4/5: 0.0128s
  Run 5/5: 0.0136s
[INFO] 平均推理时间: 0.0135s
[INFO] 最快: 0.0128s, 最慢: 0.0147s

5. Agent 适配截图

5.1 Agent 适配全过程截图

Agent 适配流程

5.2 NPU 设备调用截图

NPU 设备调用

5.3 模型适配结果截图

模型适配结果

5.4 验证管线截图

验证管线


6. 精度评测

测试数据: 标准时序预测测试集(BOOM / GIFT-Eval / TIME Benchmark) 评测指标: CRPS (Continuous Ranked Probability Score), MASE (Mean Absolute Scaled Error)

数据集CRPSMASE
BOOM0.3630.601
GIFT-Eval0.4960.719
TIME0.5560.668

说明: 当前部署环境无上述标准测试集数据,基准测试已验证模型推理功能正常。正式精度评测请使用标准数据集。


7. 注意事项

  • 推理脚本通过 torch_npu 调用昇腾 NPU 设备
  • 模型权重为 safetensors 格式(84MB),需自行从 HuggingFace 下载
  • toto-models 包需要 Python >= 3.12;Python 3.11 环境下请直接安装 toto-2
  • 输入数据形状为 (batch, n_variates, time_steps),支持多变量时间序列
  • 输出为 9 个分位数水平(0.1~0.9)的概率预测,支持不确定性估计
  • 模型使用 u-μP 缩放训练,推理时使用 tau=1.0(已嵌入权重)