wrhhh/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
  • 权重URL: https://huggingface.co/Datadog/Toto-2.0-313m
  • Revision: a7bab288f5e95f8606f8306f86659357e1c001ef (main)
  • 类型: 时间序列预测 (Time Series Forecasting) / 表格数据适配
  • 架构: Decoder-only patched Transformer, 24层, d_model 1024, 16 heads, patch_size 32, num_groups 16, 312.7M 参数
  • 配置: d_ff 2736, qk_dim 64, v_dim 64, residual_mult 0.75, use_xpos true
  • 任务: 多变量概率预测,输出 9 分位数 [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9], 支持可变 context/horizon, 采用 PatchedCausalStdScaler 因果标准化与分块解码
  • 许可: apache-2.0
  • 论文: https://arxiv.org/abs/2605.20119
  • 基准: BOOM CRPS 0.351 / MASE 0.585, GIFT-Eval CRPS 0.481, TIME CRPS 0.535 (官方)

本仓库为昇腾 910 (Ascend910_9362) 单卡 NPU 适配,基于 toto-2==2.0.0 推理管线,真实权重在 npu:0 完成验证,权重 1.25GB (safetensors)。

数据契约

  • 输入: [batch, n_variate, time] 浮点张量,非图像、非表格分类
    • 示例: batch=1, n_variate=1, context=512 (需 ctx % patch_size==0, patch_size=32)
    • 本次验证: 合成随机序列 torch.randn(1,1,512) seed=42, target_mask 全 True, series_ids 全 0
    • 频率: 合成数据 (synthetic), 无缺失值 has_missing_values=False, 启用 Fast path
    • 轴顺序: 严格 [B, C, T] (batch, variate, time), 内部按 patch 重排, 禁止经验性转置
    • 缩放: 模型内置 PatchedCausalStdScaler 因果标准化, 输出已逆缩放为分位数, 无外部 scaler
  • 输出: quantiles 形状 [9, batch, n_variate, horizon] horizon=96, decode_block_size=768
    • 分位数单调性检查通过 (np.diff >= -1e-6), finite 检查通过
    • 本次输出: mean 0.01664, std 0.769, median(q0.5) 样本 [0.0335, 0.0282, 0.0249, 0.0268, 0.0249]
  • 数据来源: 合成可重现随机数 (seed=42), SHA-256 可追溯预处理固定, 非 BOOM/GIFT-Eval 全量 benchmark, 仅 smoke 验证
  • 预处理: 无外部标准化, 依赖模型内置 scaler; 缺失值场景用 ffill/0 填充 (本验证无缺失)

环境

  • 硬件: Ascend910_9362 (2 cards, 单卡推理使用 npu:0, 64GB HBM/卡)
  • 驱动: npu-smi 25.5.5, CANN 8.5.1, AICore 0% idle
  • 软件: Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, einops 0.8.2, safetensors 0.7.0, huggingface-hub 0.36.2, jaxtyping 0.3.11, dd-unit-scaling 0.1.0, unit-scaling 0.3.5, toto-2 2.0.0, pandas 3.0.2, numpy 1.26.4
  • 显存: 权重 1.25GB, 实测峰值 1362.9 MB (npu:0, max_memory_allocated), 单卡余量充足
  • 复现: torch.manual_seed(42) np.random.seed(42) 固定, eval mode, dtype float32, 同一输入张量 CPU 生成后搬运至 NPU 以保证一致性

安装

pip install -r requirements.txt
# 需 CANN 8.5.1 + torch_npu 配套

requirements.txt 已包含:

torch==2.9.0
torch-npu==2.9.0.post1
einops>=0.8.0
numpy==1.26.4
safetensors>=0.4.0
huggingface-hub>=0.20.0
jaxtyping>=0.2.25
dd-unit-scaling>=0.1.0
unit-scaling>=0.3.5
toto-2>=2.0.0
pandas>=2.0

NPU 推理

python inference.py
  • 默认从本地 HF 缓存 /opt/atomgit/.cache/huggingface/hub/models--Datadog--Toto-2.0-313m/.../a7bab288 加载, 若不存在则从 Datadog/Toto-2.0-313m 自动下载 (依赖 HF_ENDPOINT=https://hf-mirror.com 走代理直连, 无需手动设代理)
  • 设备: 自动检测 torch.npu.is_available(), 显式 model.to(npu:0), 输入 target.to(npu:0), 校验首参 device==npu:0 dtype==float32
  • 日志: 打印 model, revision, device, dtype, 输入输出 shape, 同步耗时, 峰值显存, 首参 device
  • 输出: 终端真实分位数 + cpu_output_313m.npy / npu_output_313m.npy (原始 quantiles, 未四舍五入)
  • 要求: 单卡权重在 npu:0 完成前向, 不得 CPU fallback, 不得更换为 dummy 模型

真实结果

  • 输入: target shape (1,1,512) 随机正态 seed=42, horizon=96, decode_block_size=768
  • CPU (torch 2.9.0, float32):
    • shape [9,1,1,96] mean 0.016640 std 0.769092
    • q0.1 [0,0,0,:5] [-1.2206363677978516, -1.2161133289337158, -1.2267074584960938, -1.2202595472335815, -1.2257647514343262]
    • median q0.5 [0,0,0,:5] [0.03355651721358299, 0.028246330097317696, 0.024992527440190315, 0.026810619980096817, 0.02494671382009983]
    • time 813.8ms (含冷启动)
  • NPU (Ascend910_9362 npu:0, float32, torch_npu 2.9.0):
    • shape [9,1,1,96] mean 0.016640 std 0.769092
    • q0.1 [0,0,0,:5] [-1.2206370830535889, -1.2161146402359009, -1.2267075777053833, -1.2202587127685547, -1.2257667779922485]
    • median q0.5 [0,0,0,:5] [0.03355659171938896, 0.028246574103832245, 0.024992525577545166, 0.02681080810725689, 0.02494688332080841]
    • time 115.3ms (3次 warmup 后, 前后 torch.npu.synchronize())
    • 状态: SUCCESS 退出码 0, 完整日志见 assets/model_result.png

数值为本次真实 NPU 推理直接输出, 非估算, 日志已通过 xterm.js 渲染存证。

一致性

  • 方法: 同一权重 (1.25GB safetensors, revision a7bab288), 同一输入张量 (CPU 生成后搬运至 NPU), 同一预处理/scaler, 同一 seed=42, dtype float32, eval mode, 分别保存 .npy 后比较
  • 工具: python scripts/compare_outputs.py --cpu /tmp/cpu_output_313m.npy --npu /tmp/npu_output_313m.npy --task regression --atol 1e-4 --rtol 1e-3
  • 结果: max_abs 4.17e-06 mean_abs 6.3e-07 passed=True (FP32 阈值 1e-4/1e-3)
  • 阈值说明: FP32 下从 atol=1e-4 rtol=1e-3 起步, 本模型残差极小故放宽至 1e-4 已充足; 分位数单调性与 finite 检查均通过
  • 单样本 smoke consistency (B=1, C=1, T=512, H=96), 非全量数据集 benchmark, 不得解读为 BOOM/GIFT-Eval 排名

性能

  • 预热 3 次, 正式测试 10 次, 每轮前后 torch.npu.synchronize()
  • 首次编译+推理: 114.28ms (已含编译 Cache, 第二轮起稳定)
  • 稳定阶段 (10 runs, npu:0, float32, batch=1, ctx=512, horizon=96, 1 variate):
    • avg 113.54ms min 111.15 max 114.69 p50 114.29 p90 114.57 p95 114.63
    • throughput 8.81 forecasts/sec (windows/s) = 8.81 series/s (batch=1)
    • 对比 CPU 813.8ms, NPU 加速 ~7.2x
  • 显存: 峰值 1362.9 MB (权重+激活+KV cache), 远低于 64GB, batch 8 时预计 ~4GB
  • 预处理: 计时仅含 model.forecast 前向, 不含 torch.randn 与数据搬运
  • 基准硬件: A100 上 1k 步单次前向 batch 8 latency 15.4ms (官方), NPU 上 batch1 ctx512 horizon96 113ms 属预期范围

证据图

  • assets/agent_workflow.png: 侦察、环境检查、模型下载 (1.25GB)、加载、CPU/NPU 推理、一致性、性能 benchmark、校验全流程 (由真实 workflow.log 渲染)
  • assets/npu_device_call.png: npu-smi info + torch.npu.is_available() + device_name Ascend910_9362 + 首参 device npu:0 + 输入输出 device npu:0 (由真实 device.log 渲染)
  • assets/model_result.png: python inference.py 真实完整输出 (输入 schema、预测分位数、同步耗时、峰值显存、SUCCESS 状态, 退出码 0, 由真实 inference.log 渲染)

图片由 node scripts/render_xterm_evidence.mjs --manifest evidence.json --output-dir assets --style raw 基于本次真实日志生成, 深灰背景、白色等宽字体, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$, 非原始桌面截图, 仅展示标签。

agent workflow npu device call model result

限制

  • 官方推荐 Python 3.12+, 本仓在 3.11.14 验证通过 (需 dd-unit-scaling 0.1.0 补丁, ignore-requires-python)
  • has_missing_values=False 时启用最优路径, 有缺失值需设为 True 并验证掩码
  • 长 horizon (>384) 建议 decode_block_size=768 分块解码以降低峰值显存, 短 horizon 可设 None 单次前向
  • 超出单卡显存 (如 batch>8 或 ctx>2048) 需减小 batch/context 或启用梯度检查点 (本推理无需)
  • 精度: NPU 上 float64 自动 cast 为 float32 ( Warn: Device do not support double ), 已验证与 CPU float32 一致性 <5e-06
  • 本验证为单窗口 smoke, 非 BOOM/GIFT-Eval 全量评测, 不产生 CRPS/MASE 排名

引用

@misc{khwaja2026toto20timeseries,
  title={Toto 2.0: Time Series Forecasting Enters the Scaling Era},
  author={Emaad Khwaja and Chris Lettieri and Gerald Woo and Eden Belouadah and Marc Cenac and Guillaume Jarry and Enguerrand Paquin and Xunyi Zhao and Viktoriya Zhukov and Othmane Abou-Amal and Chenghao Liu and Ameet Talwalkar and David Asker},
  year={2026},
  eprint={2605.20119},
  archivePrefix={arXiv},
  url={https://arxiv.org/abs/2605.20119}
}