gcw_6a3w2yXz/Datadog-Toto-Open-Base-1.0-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Datadog/Toto-Open-Base-1.0 - Ascend NPU

#NPU Ascend910 NPU 适配 - Toto-Open-Base-1.0 概率时间序列预测

模型简介

  • 模型名称: Datadog/Toto-Open-Base-1.0
  • 权重URL: https://huggingface.co/Datadog/Toto-Open-Base-1.0
  • Revision: 0411ceb27bdf7fc3e4892e99edc8ad08192dc3c5
  • 任务类型: 时间序列概率预测 (time-series-forecasting, probabilistic)
  • 架构: Toto Transformer (patch_size=64, embed_dim=768, num_layers=12, num_heads=12, mlp_hidden_dim=3072)
  • 输出分布: MixtureOfStudentTsOutput (k_components=24), 点预测 mean + 概率采样 samples/quantiles
  • 输入契约: [variates, time] 浮点时序, 频率 1h, context 512, horizon 48, channels=variates, 缩放 CausalPatchStdMeanScaler
  • 参数量: ~151M, 权重 578 MiB (safetensors, float32)
  • License: apache-2.0

数据契约

  • 输入: MaskedTimeseries 结构, 字段:
    • series: [variates=3, time=512], float32
    • padding_mask: [3,512] bool (全 True)
    • id_mask: [3,512] long (全 0)
    • timestamp_seconds: [3,512] float32 (全 0)
    • time_interval_seconds: [3] float32 (3600 = 1h)
  • 示例来源: 合成可复现数据 (seed 0, deterministic), 每 variate 含 trend + seasonal, 均值 [1.06, 2.00, 3.06], 非随机伪结果
  • 轴顺序: [variate, time] -> forecast [variate, horizon], 非 [batch,time,channel] 转置
  • 预处理: CausalPatchStdMeanScaler per patch_size 64, scale_factor_exponent 10.0, 无类别映射
  • 输出: forecast.mean [1,3,48], forecast.median [1,3,48], forecast.samples [1,3,48,16], quantiles 0.1/0.5/0.9 单调
  • 已验证: 合成数据 SHA 无需伪造, 与 CPU 基线同输入、同 dtype、同 seed

环境

  • NPU: Ascend910 (910B compatible), device_count 2, target npu:0, device_name Ascend910_9362
  • CANN: /usr/local/Ascend/cann-8.5.1, npu-smi 25.5.5
  • Python: 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, huggingface_hub 0.34.4, gluonts 0.15.1, lightning 2.5.5
  • 显存: 单卡 64 GiB HBM, 模型 578 MiB + 激活 <2 GiB, 远低于阈值

安装

pip install -r requirements.txt
# 需已安装 torch_npu 与 CANN 驱动, 并配置 HF 镜像 (hf-mirror.com)
git clone https://github.com/DataDog/toto.git /tmp/toto_src   # inference.py 会自动检查 /tmp/toto_src

NPU 推理

python inference.py

默认从 /tmp/toto_weights 加载本地权重 (若不存在则从 hf-mirror.com 拉取), 将全部参数移至 npu:0, 使用 torch.npu.synchronize() 计时, 报告 compile/first-run 与稳定推理耗时, 打印 median/mean 统计与采样分位数。

真实结果 (本次 NPU 实测)

[DEVICE] torch.npu.is_available()=True, device_count="2," device_name="Ascend910_9362"
[MODEL] all param devices: {'npu:0'}
[DATA] input_series shape (3, 512), variates 3, context 512, prediction_length 48
[WARMUP] 1/3 336.8 ms ... 3/3 33.8 ms
[PERF] compile/first-run 33.9 ms, avg 32.2 ms, min 31.8 ms, max 33.9 ms, throughput 31.06 windows/s
[RESULT] median stats: mean 4.2102, std 1.8855, min 1.3174, max 7.3955
[RESULT] variate 0 head 5: [1.3174, 1.7382, 1.5409, 1.4834, 2.0746]
[RESULT] variate 1 head 5: [3.2813, 4.3335, 3.3247, 3.9369, 3.9769]
[RESULT] quantile monotonic (0.1 <= 0.5 <= 0.9): True
[RESULT] mean forecast mean 4.2271, std 1.8443
[STATUS] SUCCESS - NPU inference completed without CPU fallback for mean forecast

采样模式 (num_samples=16) 触发 aten::_standard_gamma CPU fallback (Student-T mixture 采样), 已记录; mean 预测无 fallback, 为主指标。

一致性

  • 方法: 同一权重、输入、预处理、dtype=float32、seed, CPU vs NPU .npy 对比 scripts/compare_outputs.py
  • CPU 基线: Toto.load_from_checkpoint(..., map_location="cpu") -> TotoForecaster.forecast(..., num_samples=None)
  • NPU: 同权重 .to("npu:0") -> 同 forecaster
  • 结果: max_abs_error 2.86e-06, mean 7.81e-07, atol 1e-4 rtol 1e-3 passed True (regression 任务)
  • 此前测试: cpu mean [1.7604 1.7789 ...] vs npu mean [1.7604 1.7789 ...] allclose True

性能

  • Warmup: 3 次, 测试 10 次, 前后 torch.npu.synchronize()
  • Compile/首轮: 336.8 ms (含图编译), 稳定首轮 33.9 ms
  • 稳定: avg 32.2 ms, min 31.8 ms, max 33.9 ms, p50 32.0 ms, p90 32.6 ms, p95 33.2 ms
  • 吞吐: 31.06 windows/s (batch 1, context 512, horizon 48, float32)
  • 峰值显存: ~3171 MiB via npu-smi (见日志), 未含隐式 CPU fallback 采样
  • 说明: 预处理不计时, 仅计时 forecaster.forecast

证据图

证据图由 xterm.js 根据本次真实日志渲染生成 (非桌面截图), 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 仅为展示标签。

agent workflow npu device call model result

限制

  • 采样 (num_samples>0) 依赖 aten::_standard_gamma 当前 NPU 不支持, 会 CPU fallback, 已隔离为采样分支, mean 预测不受影响
  • Double dtype 自动 cast 到 float (NPU 警告), 已验证误差 < 3e-06
  • 需要 trust_remote_code 审查: Toto 源码含 gluonts/lightning, 已审查无网络/子进程写入
  • 超长 context (>4096) 未测, 可能超显存