模型名称: 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)
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | 2.1.0+ | PyTorch 基础 |
| torch_npu | 2.1.0+ | 昇腾 NPU 后端 |
| transformers | >= 4.45.0 | HuggingFace 库 |
| toto-2 | 2.0.0 | Toto 2.0 模型库 |
| dd-unit-scaling | 0.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# 检查 NPU 设备
npu-smi info
python3 -c "import torch; print(torch.npu.is_available(), torch.npu.device_count())"# 单变量预测(上下文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| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --context | int | 512 | 上下文长度(时间步数) |
| --horizon | int | 96 | 预测步数 |
| --nvar | int | 1 | 变量数(单变量=1,多变量=3) |
| --device | str | auto | 推理设备(auto/npu/cpu) |
| --model_path | str | /data/models/Datadog-Toto-2.0-1B | 模型路径 |
| --warmup | int | 1 | 预热运行次数 |
| --runs | int | 5 | 测试运行次数 |
输入: 随机生成 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])输入: 随机生成 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])


测试数据: 随机生成时序数据(验证模型推理正确性) 评测指标: 推理耗时、输出形状验证
| 指标 | 结果 |
|---|---|
| 模型参数量 | 1,041,033,024 |
| NPU 推理耗时 (context=64, horizon=16) | ~65.7ms |
| 输出维度 | (9, 1, 1, horizon) — 9个分位数 |
| NPU 设备 | Ascend910_9362 |