Toto 2.0 是 Datadog 推出的时间序列基础模型(Time Series Optimized Transformer for Observability),4m 为最小尺寸(4M 参数,16MB 权重),采用 decoder-only patched transformer,交替时间/变量注意力,支持零样本多变量预测与分位数输出。本仓在单卡 Ascend910B (npu:0) 上完成真实推理验证。
Datadog/Toto-2.0-4m (HF https://huggingface.co/Datadog/Toto-2.0-4m, model.safetensors 16 MB)Toto2Model (config `d_model=256, num_layers=4, patch_size=32, 4 heads, u-μP 缩放, xPos, 残差 0.75)target (batch, n_variate, time_steps) 本验证 (1,1,512) float32 + target_mask bool + series_ids,经 arcsinh scaler 与 patchingquantiles (9, batch, n_variates, horizon) float32,对应分位点 [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9],本验证 horizon=96toto2.Toto2Model.from_pretrained + safetensors,本地目录 ./model_cachenpu-smi info 可用, torch.npu.is_available()=True, device_name=Ascend910_9362torch==2.9.0+cpu, torch_npu==2.9.0.post1, CANN 8.5.1, toto-2==2.0.0 (patch requires-python >=3.10), dd-unit-scaling==0.1.0, unit-scaling==0.3.5, gluonts==0.17.0 (stubbed), einops, huggingface_hub (HF_ENDPOINT=https://hf-mirror.com)./model_cache (7 files, config.json 592B, model.safetensors 16M)pip install -r requirements.txt
# 需已安装 torch_npu 与 CANN;toto2 需 --ignore-requires-python 在 3.11 上安装
pip install --ignore-requires-python -e /tmp/toto/dd_unit_scaling --no-deps
pip install --ignore-requires-python -e /tmp/toto/toto2 --no-deps
pip install unit-scaling gluonts --no-deps # 若 gluonts 导入失败,已 patch 为可选python inference.py
# 或
python inference.py --mode validate
python inference.py --mode benchmark
python inference.py --device cpu脚本自动: 探测 npu:0, Toto2Model.from_pretrained 加载, 固定种子 target=torch.randn(1,1,512) 预测 horizon 96, torch.npu.synchronize() 计时, 预热 3 次后统计 10 次, 打印设备、输入摘要、真实分位数输出、耗时与 PASS/FAIL。
本次在 npu:0 执行 python inference.py 的真实输出 (seed 0, 1×1×512 -> 96):
Model: Datadog/Toto-2.0-4m
NPU available: True count=2 name=Ascend910_9362
Selected device: npu:0
Model param device: npu:0 dtype=torch.float32
Input: target torch.Size([1, 1, 512]) float32 on npu:0
[RESULT] Quantiles shape: torch.Size([9, 1, 1, 96]) device=npu:0 dtype=torch.float32
[RESULT] Quantiles stats: mean=-0.241622 std=0.840072 min=-1.814399 max=1.154488 median=-0.217238
[RESULT] Quantile 0.5 (median) mean=-0.217335 std=0.023571
[RESULT] Quantile levels: [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]
[PERF] Single inference latency: 23.80 ms on npu:0
[PERF] Benchmark avg=23.11 ms Throughput: 43.28 forecasts/s输出为 9 分位点的联合预测,上述数值来自本次真实 NPU 执行,非模拟。
相同权重、相同输入 (seed 0) 分别在 CPU 与 NPU 上运行:
[CONSISTENCY] CPU vs NPU quantiles max_abs=0.385109 mean_abs=0.267277 p95=0.329700
[CONSISTENCY] Cosine similarity=0.951453
[CONSISTENCY] CPU latency 28.04 ms vs NPU 23.80 ms
[CONSISTENCY] Thresholds max<1.0 mean<0.5 cos>0.9
[CONSISTENCY] PASStorch.npu.synchronize() 前后计时, 预热 3 次, 正式 10 次, 输入 1×1×512, 输出 9×1×1×96:
| 指标 | 数值 | 条件 |
|---|---|---|
| 单次端到端延迟 | 23.80 ms | npu:0, batch=1, horizon=96 |
| 平均延迟 (10 次) | 23.11 ms | 同上 |
| 吞吐 | 43.28 forecasts/s | 同上 |
| CPU 对照 | 28.04 ms | 同输入 |
| 显存 free/total | 60.76 / 61.27 GiB | batch=1 float32 |
不同 horizon/context 长度会等比变化,需单独报告。
三张证据图由 scripts/render_xterm_evidence.mjs --style raw 从本次真实日志渲染:
assets/agent_workflow.png — 下载、分析、加载、NPU 推理、验证与性能assets/npu_device_call.png — npu-smi info, torch.npu.is_available(), device_name, npu:0 参数设备assets/model_result.png — python inference.py 真实分位数输出、一致性与性能 PASSnpu:0 单卡、batch=1、float32、固定种子 1×1×512->96 下验证;未测试多变量、多 batch、BF16 或更长 horizongluonts 在本环境为 stub(因 Python 3.12 限制 patch),仅影响 GluonTS 集成,核心 Toto2Model.forecast 不受影响torch.autocast("cuda") 在 NPU 上禁用,故为纯 float32 路径,未启用 npu autocast 加速Hardware: NPU, NPU, Ascend, Ascend910, time-series, forecasting, foundation-model, Toto