在单卡昇腾 NPU(Ascend910,npu:0)上真实运行 Datadog/Toto-2.0-4m 零样本多变量时间序列概率预测模型,输出 9 个分位数(0.1–0.9),并完成 CPU–NPU 一致性验证与性能测试。本仓为 GitCode AI 模型仓(model 类型,公开),仅包含可复现推理入口与真实日志证据图,不包含权重与数据集。
| 项 | 值 |
|---|---|
| 模型 | Datadog/Toto-2.0-4m |
| Revision | 8306a9801cf98c0f5ffe4b2dcc8f496e616d84d9 |
| 任务 | 零样本多变量时间序列概率预测(quantile head) |
| 架构 | Decoder-only patched transformer,时间/变量交替注意力,u-μP 缩放 |
| 加载后端 | toto2.Toto2Model(PyTorchModelHubMixin)+ torch_npu |
| 参数 | 4M(约 16.5 MB fp32 权重) |
| 输出 | (9, batch, n_variates, horizon) 分位数,levels=[0.1, 0.2, ..., 0.9] |
使用模型官方基准 Datadog/BOOM 中 ds-0-T 序列(真实观测时序,来源可追溯):
| 字段 | 值 |
|---|---|
| 来源 | Datadog/BOOM,ds-0-T/data-00000-of-00001.arrow |
| start | 2024-12-22T19:13:00 |
| item_id | 0 |
| freq | T(分钟) |
| 长度 | 16384 点 |
| 轴顺序 | (batch, n_variates, time) |
| context_length | 512 |
| horizon | 96 |
| 分位数 | [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] |
输入为 {"target": Float[B,V,T], "target_mask": Bool[B,V,T], "series_ids": Long[B,V]}。缩放由模型内部的因果 arcsinh 标准缩放器完成并逆变换回原始尺度,输出为真实空间分位数,已排序。
| 组件 | 版本 |
|---|---|
| 昇腾 NPU | Ascend910(npu-smi 25.5.5,HBM 64 GB × 2) |
| CANN | 8.5.1(ASCEND_TOOLKIT_HOME=/usr/local/Ascend/cann-8.5.1) |
| Python | 3.11.14 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| toto-models / toto-2 | 1.0.0 / 2.0.0 |
pip install torch torch_npu # 按 CANN 版本安装 NPU 栈(本仓验证版本见上表)
pip install -r requirements.txt
toto-models声明Requires-Python: >=3.12;在 Python 3.11 下请使用pip install --ignore-requires-python -r requirements.txt(本仓已在 3.11 验证)。
默认命令(首次运行会自动下载权重与 BOOM ds-0-T 数据到本地缓存):
python inference.py常用参数:
python inference.py --context-length 512 --horizon 96 --batch 4 --device npu:0 --output forecast.npzinference.py 自包含:加载本地权重(TOTO_MODEL_DIR/--model-dir,缺省自动下载),迁移全部参与计算的 Tensor 到 npu:0,执行 model.forecast(...),打印设备/输入/输出摘要、同步耗时、峰值显存与最终状态;异常返回非零。
以 BOOM ds-0-T 最后 512 点为 context、horizon=96、batch=4 的真实推理(npu:0):
[output] quantiles shape=(9, 4, 1, 96) finite=True monotonic=True
[output] median (q=0.5) first 8 steps: -0.4746 -0.4713 -0.4693 -0.4487 -0.4630 -0.4708 -0.4655 -0.4732
[timing] synchronised elapsed=0.2585 s (含首轮编译) peak_npu_mem=60.8 MiB
[status] PASS — real NPU inference completed同一权重、同一数据切片、同一 seed、eval 模式、fp32:
| 指标 | 值 |
|---|---|
| max_abs_error | 2.74e-06 |
| mean_abs_error | 3.39e-07 |
| 分位数单调性(CPU / NPU) | True / True |
| 阈值 | atol=1e-4, rtol=1e-3 |
python scripts/compare_outputs.py --task quantile 校验通过。
batch=4、context=512、horizon=96、fp32、npu:0;预热 3 次、正式 10 次:
| 指标 | 值 |
|---|---|
| avg | 24.14 ms |
| min / max | 23.60 / 25.60 ms |
| p50 / p90 / p95 | 24.03 / 24.60 / 25.10 ms |
| 吞吐量 | 165.7 series/s |
| 峰值 NPU 显存 | 60.8 MiB |
时间已包含 torch.npu.synchronize(),首轮编译时间与稳定推理分开报告。
三张 PNG 由 xterm.js 依据本次真实日志生成(非桌面截图):
assets/agent_workflow.png — 侦察、数据检查、下载、加载、NPU 推理、一致性、benchmark、提交校验assets/npu_device_call.png — npu-smi、NPU 可用性、设备名、参数 device/dtype、输入输出 Tensor deviceassets/model_result.png — 默认 python inference.py 的真实完整输出toto-models 官方要求 Python ≥ 3.12,本仓在 3.11 通过 --ignore-requires-python 验证。has_missing_values=True;本仓默认使用无缺失观测。