模型名称: 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)
| 数据集 | CRPS | MASE |
|---|---|---|
| BOOM (Observability) | 0.363 | 0.601 |
| GIFT-Eval | 0.496 | 0.719 |
| TIME | 0.556 | 0.668 |
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | 2.1.0+ | PyTorch 框架 |
| torch_npu | 2.1.0+ | 昇腾 NPU 后端 |
| toto-2 | >= 2.0.0 | Toto 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包。
# 检查 NPU 设备
npu-smi info
python3 -c "import torch_npu; import torch; print(torch.npu.is_available(), torch.npu.get_device_name(0))"# 基本推理(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| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | /data/Datadog-Toto-2.0-22m | 模型路径 |
| --context-len | int | 512 | 输入时间序列长度 |
| --horizon | int | 96 | 预测时间步数 |
| --n-variates | int | 1 | 变量数量 |
| --benchmark | flag | False | 运行基准测试 |
| --benchmark-runs | int | 10 | 基准测试运行次数 |
| --device | str | npu | 推理设备 (npu/cpu) |
输入:
# 随机生成测试数据(实际使用时替换为真实时间序列)
# 形状: (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]命令:
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



测试数据: 标准时序预测测试集(BOOM / GIFT-Eval / TIME Benchmark) 评测指标: CRPS (Continuous Ranked Probability Score), MASE (Mean Absolute Scaled Error)
| 数据集 | CRPS | MASE |
|---|---|---|
| BOOM | 0.363 | 0.601 |
| GIFT-Eval | 0.496 | 0.719 |
| TIME | 0.556 | 0.668 |
说明: 当前部署环境无上述标准测试集数据,基准测试已验证模型推理功能正常。正式精度评测请使用标准数据集。
torch_npu 调用昇腾 NPU 设备toto-models 包需要 Python >= 3.12;Python 3.11 环境下请直接安装 toto-2(batch, n_variates, time_steps),支持多变量时间序列