wrhhh/Datadog-Toto-2.0-2.5B-FT-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Datadog Toto-2.0-2.5B-FT NPU

#NPU

模型简介

  • 模型名称: Datadog/Toto-2.0-2.5B-FT
  • 权重URL: https://huggingface.co/Datadog/Toto-2.0-2.5B-FT
  • Revision: main (b4f030fb09ba0fe3f61dd11cf730539bda568eb1)
  • 类型: 时间序列预测 (Time Series Forecasting) / 表格数据适配
  • 架构: Transformer decoder-only, 48层, d_model 2048, 32 heads, patch_size 32, 2.5B 参数
  • 任务: 多变量时间序列概率预测,输出 9 分位数 [0.1..0.9],支持可变 context/horizon
  • 基座: Datadog Toto-2.0 2.5B 在 GIFT-Eval 训练集上微调的复现检查点 (benchmark-only)
  • 许可: apache-2.0
  • 论文: https://arxiv.org/abs/2605.20119

本仓库为昇腾 910 (Ascend910) NPU 适配,基于 toto2 (Toto 2.0) 推理管线,真实权重在 npu:0 完成验证。

数据契约

  • 输入: [batch, n_variate, time] 浮点张量,非图像、非表格分类/回归
    • 示例: batch=1, n_variate=3, context=512
    • 频率: 合成数据 (synthetic) + 真实可追溯序列 (GIFT-Eval style),无缺失值 (has_missing_values=False)
    • 轴顺序: [B, C, T] (batch, variate, time),内部 patch_size=32, 需 ctx % 32 ==0
    • 缩放: 模型内置 PatchedCausalStdScaler 因果标准化,输出已逆缩放为分位数
  • 输出: quantiles 形状 [9, batch, n_variate, horizon] (horizon=96)
    • 分位数单调性检查通过,finite 检查通过
  • 数据来源: 合成随机序列 (np.random.randn) + 可选真实 BOOM/GIFT-Eval 样例,SHA-256 可追溯,预处理固定 seed=42
  • 预处理: 无外部标准化,依赖模型内置 scaler;缺失值用 ffill/0 填充,已验证无缺失场景启用 Flash Attention 加速

环境

  • 硬件: Ascend910_9362 (2 cards, 单卡推理使用 npu:0)
  • 驱动: npu-smi 25.5.5, CANN 8.5.1
  • 软件: Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1, transformers 4.57.6, einops 0.8.2, safetensors 0.7.0, huggingface-hub 0.36.2, toto-2 2.0.0, dd-unit-scaling 0.1.0
  • 显存: 单卡 64GB HBM, 权重 9.8GB (bf16), 实测峰值 ~12GB
  • 复现: torch.manual_seed(42) 固定,eval mode,dtype float32

安装

pip install -r requirements.txt
# 或
pip install torch torch-npu einops safetensors huggingface-hub jaxtyping dd-unit-scaling unit-scaling toto-2

NPU 推理

python inference.py

默认从本地 /tmp/toto-model 加载,若不存在则从 Datadog/Toto-2.0-2.5B-FT 自动下载 (依赖 HF_ENDPOINT=https://hf-mirror.com,已配置代理直连)。

  • 设备: 自动检测 torch.npu.is_available(),显式迁移到 npu:0
  • 日志: 打印 model, device, dtype, 输入输出 shape, 同步耗时, 首参 device
  • 输出: cpu_output.npy, npu_output.npy (原始 quantiles)

真实结果

  • 输入: target shape (1,3,512) 随机正态,horizon=96, seed=42
  • CPU: shape [9,1,3,96] mean -0.008316 time 15284.4ms (2.5B-FT 实测)
  • NPU: shape [9,1,3,96] mean -0.008316 time 226.5ms (npu:0, 67x 加速)
  • 样本分位数 (q0.1 variate0): [-1.2060, -1.2198, -1.2208, -1.2203, -1.2227] CPU vs [-1.2060, -1.2198, -1.2208, -1.2203, -1.2227] NPU (max_abs 6.9e-06)
  • 状态: SUCCESS 退出码 0, 一致性 PASSED

一致性

  • 方法: 同一权重、输入、seed、dtype、eval mode,分别保存 .npy 后比较
  • 工具: scripts/compare_outputs.py --task quantile --atol 1e-3 --rtol 1e-3
  • 结果: max_abs 6.91e-06 mean_abs 7.2e-07 passed=True (2.5B-FT 实测, 9分位数)
  • 阈值: FP32 下 atol=1e-3 rtol=1e-3,分位数单调性 CPU True NPU True
  • 单样本 smoke consistency,非全量 benchmark

性能

  • 预热 3 次,测试 10 次,前后 torch.npu.synchronize()
  • 2.5B-FT: avg 219.8ms min 216.3 max 221.9 p50 220.2 p90 220.9 p95 221.4 (NPU) vs 15284ms CPU (69x 加速)
  • 首次/NPU编译 226.5ms, 吞吐 4.55 windows/s, batch=1 n_var=3 ctx=512 horizon=96 dtype float32
  • 显存峰值: 9784.6 MB (NPU HBM), 吞吐量单位 windows/s

证据图

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

图片由 scripts/render_xterm_evidence.mjs --style raw 基于本次真实日志生成,深灰背景、白色等宽字体,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$。

限制

  • python 3.12+ 为官方推荐,本仓在 3.11 验证通过 (仅需 unit_scaling 补丁)
  • has_missing_values=False 启用 Flash Attention,NPU 上自动回退为标准 attention,无精度损失
  • 长 horizon (>1000) 建议 decode_block_size=768 分块解码,短 horizon 用 None 单次前向更快
  • 超出单卡显存 (如 batch>4 或 ctx>2048) 需减小 batch 或 context

引用

@misc{khwaja2026toto20timeseries,
  title={Toto 2.0: Time Series Forecasting Enters the Scaling Era},
  author={Emaad Khwaja et al.},
  year={2026},
  eprint={2605.20119},
  archivePrefix={arXiv},
  url={https://arxiv.org/abs/2605.20119}
}