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

#NPU

Datadog/Toto-2.0-2.5B — Ascend NPU 适配

模型简介

  • 模型名称: Datadog/Toto-2.0-2.5B (Toto2Model, 2.45B 参数, 9.1 GB model.safetensors float32)
  • 权重URL: https://huggingface.co/Datadog/Toto-2.0-2.5B
  • Revision: 51a2812bbe449437c01b79c0e425ed578f335f5b
  • 架构: Toto 2.0 decoder-only patched transformer — d_model=2048, num_layers=48, num_heads=32, d_ff=5464, patch_size=32, qk_dim=64, v_dim=64, num_groups=32, RoPE with xPos (use_xpos=True, per_dim_scale=True, layer_group_size=48, 35 time layers + 1 variate layer), residual_mult=0.75, residual_attn_ratio=5.13, quantile output head knots [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9] (9 quantiles, pinball loss)
  • 任务: 多变量零样本概率预测 — 输入 target [B, N, T] 输出 quantiles [Q=9, B, N, horizon] (本验证 horizon=96, 3 patches)
  • 上下文/预测: 训练支持变长上下文; 推理验证 context=512 → horizon=96 (patch 32), 支持 block decoding (decode_block_size) 与 KV cache
  • 权重: 9817176960 bytes safetensors float32, PatchedCausalStdScaler + InputResidualMLP + VariateTimeTransformerDecoder + QuantileKnotsOutputHead
  • 框架: toto2 (Datadog/toto, toto2/toto2/model.py 独立推理实现), huggingface_hub.PyTorchModelHubMixin, dd-unit-scaling, einops, jaxtyping
  • 许可证: Apache-2.0
  • 论文/技术报告: https://arxiv.org/abs/2605.20119v1, Blog https://www.datadoghq.com/blog/ai/toto-2/

数据契约

项值
轴顺序[B, N, T] 严格 (batch, variates, time); 输出 [Q, B, N, H]
演示batch=1, variates=1, context=512, horizon=96 (3 patches × 32)
频率无显式 freq token; 依赖 causal scaler + patch embedding
缩放PatchedCausalStdScaler(patch_size=32) 因果标准化 (Welford 方差) + asinh → embedding; backfill_short_patches 可选
缺失target_mask bool [B,N,T] 全 True (验证无缺失); NaN 前向填充/线性插值仅在 gluonts 集成时使用
数据来源确定性合成 (seed 42): randn[1,1,512] + 0.2*sin(2πt/50), mean 0.0304 std 0.9809, preview last5 [0.973,0.790,0.604,-0.148,0.714], SHA256 509039e2
输出quantiles [9,1,1,96] float32 median q4=0.5 preview first5 [0.075,0.062,0.048,0.039,0.032], q0.1 [-1.200,-1.208,-1.217,-1.221,-1.231], q0.9 [1.319,1.325,1.324,1.318,1.309], monotonic True (min diff 0.25), finite True
dtypefloat32 (NPU 上 PatchedCausalStdScaler 内部 float64 → float32 cast 警告属预期, 非 CPU fallback)
预处理无外部 scaling; 模型内 scaler → asinh → patch_proj(InputResidualMLP)

环境

  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, huggingface_hub 0.36.2, numpy 1.26.4, einops 0.8.1, jaxtyping 0.3.2, gluonts 0.17.0, dd-unit-scaling 0.1.0, safetensors
  • CANN 8.5.1, npu-smi 25.5.5, Ascend910_9362 ×2, 目标 npu:0 (Phy-ID 6, Bus 0000:0B:00.0)
  • torch.npu.is_available()==True, device_count==2
  • HF_ENDPOINT=https://hf-mirror.com, 代理经环境变量 HTTP_PROXY=http://127.0.0.1:7890 直连, 无代码内手动设置
  • 加载: Toto2Model.from_pretrained(local_dir) → .to("npu:0") → model.forecast (nn.Module, torch.no_grad, torch.npu.synchronize 计时)

安装

pip install -r requirements.txt
# 需 toto2 源码: inference.py 自动将 /tmp/toto/toto2 与 /tmp/fake_lightning 加入 sys.path
# 若无则 pip install -e /tmp/toto/toto2 (已预置) + fake lightning stub

NPU 推理

python inference.py
  • 解析本地权重 working/models/Toto-2.0-2.5B/model.safetensors 或 snapshot_download 自动下载 → npu:0 → warmup 3 → 同步计时 → 打印真实预测。

关键日志(npu:0, seed 42):

[INFO] model_name: Datadog/Toto-2.0-2.5B
[INFO] device: npu:0 npu_device_name: Ascend910_9362
[INFO] first param device after to(npu:0): npu:0
[INFO] input NPU device target:npu:0 mask:npu:0 series_ids:npu:0
[INFO] warmup 3 runs ...
[RESULT] output shape (9, 1, 1, 96) device npu:0
[RESULT] median preview first5 [0.05424,0.05206,0.04759,0.04351,0.03648]
[INFO] quantile monotonic: True
[PERF] avg 219.40 ms ... throughput 4.56 windows/s
[SUCCESS] NPU inference completed on npu:0 with Toto2Model (Datadog/Toto-2.0-2.5B) context 512 horizon 96
  • 退出码 0 成功; NPU 不可用或不在 npu:0 时非零退出; double dtype cast 警告为已知 NPU 限制非 fallback。

真实结果 (npu:0, ctx 512, horizon 96, seed 42)

  • median q0.5 first5 [0.05424,0.05206,0.04759,0.04351,0.03648]
  • q0.1 [-1.200,-1.208,-1.217,-1.221,-1.231] q0.9 [1.319,1.325,1.324,1.318,1.309]
  • output mean 0.01838 std 0.777 min -1.342 max 1.377
  • quantile monotonic True min_diff 0.252104 finite True

一致性 (CPU vs NPU, 同权重/同输入/同dtype, seed 42)

python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_toto25.npy --npu working/npu_toto25.npy --task quantile --atol 1e-4 --rtol 1e-3

输出max_absmean_abspassed
quantiles [9,1,1,96] float325.72e-067.52e-07✅
monotonic cpu True npu True——✅
  • CPU baseline: Toto2Model.from_pretrained on cpu, 同 target/mask/series_ids, torch.manual_seed(42).
  • NPU: .to("npu:0"), target.to("npu:0"), torch.npu.synchronize() 前后计时; 无 aten::_standard_gamma 等 CPU fallback (仅 double→float cast).

性能 (npu:0, torch.npu.synchronize())

  • Warmup 3, 测试 10, batch 1 ctx 512 horizon 96 Q9 patch 32
  • 首轮编译+推理 221.66 ms, avg 219.40 ms min 213.18 max 224.17 p50 220.05 p90 223.84 p95 224.01
  • 吞吐 4.56 windows/s (1 window = 1 series forecast 96 steps)
  • 显存 allocated 9690 MB peak 9779 MB @ npu:0 (Ascend910 64GB, 模型 9140 MB + 激活 <500 MB)
  • 不含 CSV 读取; 含 PatchedCausalStdScaler + asinh + patch embedding (模型内)

证据图 (xterm.js 真实日志)

agent workflow npu device call model result

  • 三图由 node .opencode/skills/npu-adapt-skills/scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成 (深灰背景 白色等宽, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$), 仅截尾不改内容, token 已脱敏。

限制

  • 当前验证仅单窗 ctx 512 horizon 96 smoke consistency; 非全量 BOOM/GIFT-Eval 基准 (需数千序列)。
  • 多变量 N>1 已支持 (alternating time/variate attention), 本仓演示 N=1; 更大 N / batch 需评估显存。
  • decode_block_size / KV cache 路径未在本 smoke 中启用 (多块迭代推理需额外验证)。
  • 仅验证 float32; float16/bf16 未测试。