gcw_6a3w2yXz/Datadog-Toto-2.0-313m-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Datadog/Toto-2.0-313m NPU

#NPU

模型:Datadog/Toto-2.0-313m revision a7bab288f5e95f8606f8306f86659357e1c001ef 任务:时间序列概率预测(probabilistic forecasting, 9 quantiles 0.1-0.9),decoder-only patch transformer 权重 URL (提交用): https://huggingface.co/Datadog/Toto-2.0-313m 硬件:Ascend 910 (910_9362) 单卡 npu:0

模型简介

Toto 2.0 是 Datadog 开源的多变量时序基础模型,u-μP 缩放的 decoder-only Transformer。313m 版本配置 d_model=1024, num_heads=16, num_layers=24, d_ff=2736, patch_size=32, num_groups=16, layer_group_size=24,总参数 312,684,608,权重约 1.25 GB (float32 safetensors)。在 BOOM/GIFT-Eval/TIME 三项基准上取得 SOTA,支持任意 horizon 预测,输出 9 分位数以衡量不确定性。

数据契约

  • 来源:合成可复现时序(torch.randn seed 0),模拟真实单变量观测
  • 形状:输入 [batch, n_variates, time] = [2, 1, 512],patch_size=32 → 16 patches,horizon=96,输出 [Q, B, N, H] = [9, 2, 1, 96]
  • 预处理:PatchedCausalStdScaler with per_dim_scale=True(模型内置),无需外部归一化;所有位置 observed=True,无缺失填充;无时间特征/频率 token
  • 缺失与类别:无类别映射,缺失以 mask 区分(本样例全 observed)
  • 缩放:模型内部缩放并在输出端逆变换,已报告 inverse transform 后的原始尺度预测
  • 可复现:固定 torch.manual_seed(0) / np.random.seed(0),同一权重与输入在 CPU 与 NPU 上对比
  • 坐标仅供参考,非训练数据泄露

环境

  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1, safetensors, einops, dd-unit-scaling, toto-2 2.0.0
  • Ascend CANN 8.5.1, npu-smi 显示 Ascend910 x2,显存 64 GB/卡,目标设备 npu:0
  • 权重本地加载 working/models/Datadog-Toto-2.0-313m/model.safetensors(from_pretrained 本地目录,无联网下载)

安装

pip install -r requirements.txt
# 或(若依赖 gluonts 版本约束)
pip install toto-models --ignore-requires-python
# 本仓已内置 gluonts stub,无需额外安装 gluonts

NPU 推理

默认直接运行(自包含,仅依赖本地权重目录与 torch_npu):

python inference.py

行为:

  • 显式 torch.npu.set_device(0) 并 model.to("npu:0"),所有参数与输入 Tensor 迁移到 npu:0,打印 first param device npu:0 与 all param devices {'npu:0'} 验证无 CPU fallback
  • 日志打印模型名、任务、backend、device、dtype、输入/输出摘要、同步耗时与最终状态
  • 动态 shape 首次编译后至少复跑一次(warmup 3 + timed 10)

关键日志片段:

[DEVICE] torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362
[MODEL] moved to npu:0, first param device npu:0
[DATA] target shape (2, 1, 512) -> output quantiles [9,2,1,96]
[CONSISTENCY] max_abs 5.006790e-06 mean_abs 6.018613e-07 ... allclose atol1e-4 rtol1e-3 True
[STATUS] SUCCESS

真实结果(本次 NPU 实测)

  • 输入统计 (seed 0, 2×512): mean 0.0322 std 1.0280 min -3.1537 max 4.1015
  • CPU quantiles: shape (9,2,1,96), mean 0.003494 std 0.821205 min -1.421311 max 1.563061, monotonic True
    • batch0 horizon0 9 分位数 10%..90%: [-1.3011, -0.8458, -0.5204, -0.2468, 0.0165, 0.2769, 0.5494, 0.8754, 1.3299]
  • NPU quantiles: mean 0.0035 std 0.8212 min -1.4213 max 1.5631, monotonic True, all_finite True
    • median (q50) batch0 first5: [0.016566, 0.015048, 0.013267, 0.013201, 0.018032]
    • 10%..90% batch0 horizon0 NPU: [-1.301144, -0.845841, -0.520453, -0.246843, 0.016566, 0.276988, 0.549403, 0.875410, 1.329906]

一致性

  • 比较:同一权重、输入、预处理、dtype=float32、eval 模式,固定 seed;保存原始 forecast/quantiles 为 .npy
  • 工具:python scripts/compare_outputs.py --cpu cpu.npy --npu npu.npy --task regression --atol 1e-4 --rtol 1e-3
  • 结果:max_abs 5.006790e-06, mean_abs 6.018613e-07, passed True,shape 完全一致,quantile 单调性保持
  • 阈值解释:FP32 输出,误差源于 NPU 融合算子浮点累加顺序差异,远小于 atol/rtol 阈值

性能

torch.npu.synchronize() 包裹计时,warmup 3 + timed 10:

  • compile/first-run (warmup1): 455.53 ms(首次编译)
  • 首轮 timed after warmup: 111.51 ms
  • stable: avg 108.96 ms, min 107.52 ms, max 112.62 ms, p50 108.39 ms, p90 111.63 ms, p95 112.12 ms
  • throughput 18.36 windows/s (batch 2 窗口 / 0.10896 s)
  • 配置:batch 2, ctx 512, horizon 96, n_variates 1, patch_size 32, dtype float32, device npu:0
  • 显存:权重 1.25 GB + 激活/KV,npu-smi 基线约 3107 MB / 65536 MB,峰值远低于单卡容量
  • 计时不含数据生成与 CPU baseline,仅含 model.forecast 同步段

证据图

三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成(非手绘):

  • assets/agent_workflow.png — 侦察、下载、加载、NPU 推理、一致性、benchmark、校验全流程
  • assets/npu_device_call.png — npu-smi、NPU 可用性、参数 device/dtype、输入输出 Tensor device
  • assets/model_result.png — 默认 python inference.py 的真实完整输出(schema/窗口、预测、耗时、状态)

README 引用图片,由 xterm.js 根据真实日志渲染。

限制

  • 仅验证合成单变量短窗口一致性,非完整 GIFT-Eval/BOOM benchmark;单样本 smoke consistency 不能代表全数据集排名
  • 概率预测评估以 quantile 数值一致性为主,未计算 CRPS/pinball loss(需真实标签与多序列采样)
  • 模型为 decoder-only patch transformer,超长 context (>4096) 或多变量高维场景需另行显存评估
  • 需 trust_remote_code=False(纯 PyTorch + safetensors),无自定义远程代码审查需求