g
gcw_coj3XaOd/Toto-2.0-1B
模型介绍
文件和版本
Pull Requests
讨论
分析

Datadog/Toto-2.0-1B 昇腾NPU部署文档

1. 模型简介

模型名称: Datadog/Toto-2.0-1B 模型链接: HuggingFace 模型描述: Toto 2.0 是一个多变量时间序列基础模型,专为可观测性指标的预测设计。模型使用 PatchTST 风格的 patching 和 Decoder-only Transformer 架构,支持零样本时序预测。 模型架构: Toto2Model (Decoder-only Transformer + Patched Attention) 参数规模: 1.04B (1,041,033,024 parameters)


2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch2.1.0+PyTorch 基础
torch_npu2.1.0+昇腾 NPU 后端
transformers>= 4.45.0HuggingFace 库
toto-22.0.0Toto 2.0 模型库
dd-unit-scaling0.1.0单位缩放
gluonts>= 0.17.0时序预测工具包
safetensors>= 0.4.0安全权重加载
昇腾驱动CANN 8.0+推荐最新版

安装命令:

pip install torch torch_npu transformers toto-2 dd-unit-scaling gluonts safetensors einops

3. 推理步骤

3.1 环境准备

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

3.2 运行推理

# 单变量预测(上下文512步,预测96步)
python inference.py --device npu --context 512 --horizon 96

# 多变量预测(上下文512步,预测192步,3个变量)
python inference.py --device npu --context 512 --horizon 192 --nvar 3

# CPU 推理
python inference.py --device cpu --context 256 --horizon 64

3.3 推理参数说明

参数类型默认值说明
--contextint512上下文长度(时间步数)
--horizonint96预测步数
--nvarint1变量数(单变量=1,多变量=3)
--devicestrauto推理设备(auto/npu/cpu)
--model_pathstr/data/models/Datadog-Toto-2.0-1B模型路径
--warmupint1预热运行次数
--runsint5测试运行次数

4. 测试样例及输出结果

样例 1:单变量时序预测

输入: 随机生成 512 步单变量时间序列 命令:

python inference.py --device npu --context 512 --horizon 96 --nvar 1

输出:

[INFO] 模型加载成功: 1,041,033,024 参数
[INFO] 设备: Ascend910_9362
[INFO] 量化级别: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
[测试 1/3] 耗时: 67.1ms, 输出形状: torch.Size([9, 1, 1, 96])
[结果] 平均推理时间: 65.7ms
[结果] 最终输出形状: torch.Size([9, 1, 1, 96])

样例 2:多变量时序预测

输入: 随机生成 512 步多变量(3维)时间序列 命令:

python inference.py --device npu --context 512 --horizon 96 --nvar 3

输出:

[INFO] 上下文长度: 512, 预测步数: 96, 变量数: 3
[测试 1/3] 耗时: 68.3ms, 输出形状: torch.Size([9, 1, 3, 96])
[结果] 平均推理时间: 67.2ms
[结果] 最终输出形状: torch.Size([9, 1, 3, 96])

5. Agent适配截图

5.1 Agent适配全过程截图

Agent 适配流程

5.2 NPU设备调用截图

NPU 设备调用

5.3 模型适配结果截图

模型适配结果


6. 精度评测

测试数据: 随机生成时序数据(验证模型推理正确性) 评测指标: 推理耗时、输出形状验证

指标结果
模型参数量1,041,033,024
NPU 推理耗时 (context=64, horizon=16)~65.7ms
输出维度(9, 1, 1, horizon) — 9个分位数
NPU 设备Ascend910_9362

7. 注意事项

  • 推理脚本中通过 torch_npu 调用 NPU
  • 模型权重请自行从 HuggingFace 下载,不包含在仓库中
  • 首次运行会自动下载模型到缓存目录
  • 本模型为时序预测模型,输入为多维时间序列张量
  • 输出为 9 个分位数的概率预测(0.1, 0.2, ..., 0.9)