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

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

#NPU

Datadog/Toto-Open-Base-1.0 is a 605M-parameter multivariate time-series foundation model (Toto 1.0, patch 64, stride 64, 12 layers, embed 768, 12 heads, MixtureOfStudentTs k=24). This repository ports the model to a single Ascend 910 NPU (npu:0) via torch_npu.

模型简介

  • Model: Datadog/Toto-Open-Base-1.0 (revision 0411ceb27bdf7fc3e4892e99edc8ad08192dc3c5)
  • Task: multivariate time-series forecasting (probabilistic foundation model, deterministic mean path used for NPU verification; full distribution is MixtureOfStudentTs with 24 components)
  • Architecture: decoder-only transformer, patch embedding (64), proportional factorized space-time attention, global stabilization, causal scaler CausalPatchStdMeanScaler
  • Weights: model.safetensors 605 MB (FP32), config.json patch 64/stride 64/embed 768/12 layers/12 heads/mlp 3072
  • License: Apache-2.0

数据契约

  • Input: MaskedTimeseries(series, padding_mask, id_mask, timestamp_seconds, time_interval_seconds)
    • series: (variates, time) float32, e.g. 7 x 512 (also supports batched 1 x 7 x 512)
    • padding_mask: (variates, time) bool, True = valid
    • id_mask: (variates, time) int/float, variate identity (0 for single group)
    • timestamp_seconds: (variates, time) int, unix seconds (0 for synthetic)
    • time_interval_seconds: (variates,) int, e.g. 900 (15 min)
    • 轴顺序固定为 (variates, time),频率/间隔通过 time_interval_seconds 传入;缩放为因果 patch 标准化(CausalPatchStdMeanScaler, scale_factor_exponent 10.0)
  • Context / horizon: 任意 context_length (需 pad 到 stride 64), prediction_length 48/96 常用;默认验证 context 512 -> horizon 48
  • Dtype: FP32;不支持 FP16/BF16 量化(已验证 FP32 精度)
  • 随机种子: 42(合成数据生成与模型 eval 确定性)
  • 预处理契约: pad_array 到 stride 倍数,id_mask 同步 pad;无需归一化(模型内含 scaler)
  • 真实数据示例: 可替换为 ETTh1/BOOM/GIFT-Eval 切片,保持上述张量契约即可;列顺序不得改变

环境

  • NPU: Ascend910_9362 x2 (tested on npu:0)
  • CANN: 8.5.1
  • PyTorch: 2.9.0+cpu
  • torch_npu: 2.9.0.post1+gitee7ba04
  • Python: 3.11
  • 依赖: 见 requirements.txt (toto @ working/toto-main, torch, torch_npu, einops, jaxtyping, gluonts, rotary-embedding-torch, unit_scaling, lightning)

安装

pip install -r requirements.txt
# 另需 Toto 源码(已在镜像中提供 working/toto-main,或 pip install toto-ts==0.2.0)
pip install toto-ts==0.2.0  # 可选,若 working/toto-main 不可用

模型权重首次运行时自动解析,优先级:

  1. ./model_snapshot (推荐离线放置)
  2. $HF_HOME/hub/models--Datadog--Toto-Open-Base-1.0-cache
  3. 其他 HF cache 路径

离线下载:

HF_ENDPOINT=https://hf-mirror.com huggingface_hub snapshot_download --repo-id Datadog/Toto-Open-Base-1.0 --local-dir ./model_snapshot

NPU 推理

python inference.py
# 或指定
python inference.py --device npu:0 --context-length 512 --prediction-length 48 --n-variates 7
python inference.py --device cpu  # CPU 对比

inference.py 默认:

  • 使用确定性合成数据 (seed 42, 7 variates x 512, 周期 900s)
  • 加载 Toto.from_pretrained(model_dir).to(device) 并通过 TotoForecaster 生成 mean 预测 (无采样,确定性)
  • 打印模型 device/dtype、首轮编译耗时、稳定 10 次平均/最小/最大/p50、吞吐 windows/s、显存、forecast 预览

真实结果

  • NPU (npu:0): mean shape [1, 7, 48] mean preview [0.01464, 0.01367, 0.00200, 0.00587, 0.01093] (variate 0 前5步), first run 0.4261s, stable avg 0.0745s, throughput 13.43 windows/s, NPU max mem 607.5 MB
  • CPU: 同输入/权重/seed 下 mean [0.01464, 0.01367, 0.00200, 0.00587, 0.01093], max abs error 1.56e-06, mean abs 4.5e-07

概率采样路径 (num_samples=16) 因 aten::_standard_gamma 在 NPU 上 fallback 到 CPU,跨设备采样随机性不一致,平均误差 ~0.44;因此验证采用确定性 num_samples=None 均值路径。

一致性

  • 比较对象: mean forecast tensor [1, 7, 48] (forecasting 任务)
  • 方法: python scripts/compare_outputs.py --cpu cpu_mean.npy --npu npu_mean.npy --task regression --atol 1e-4 --rtol 1e-3
  • 结果: max_abs_error 1.56e-06, mean_abs_error 4.50e-07, passed true (FP32 阈值 atol 1e-4, rtol 1e-3)
  • 说明: 同权重、同输入、同预处理、同 seed、eval 模式;采样路径因 gamma fallback 未用于一致性判定

性能

  • 设备: npu:0 (Ascend910_9362)
  • Batch: 1 window (7 variates x 512 context -> 48 horizon)
  • Dtype: FP32
  • Compile/first run: 0.42s (含 KV cache 初始化、patch pad、attention)
  • Stable: avg 0.0745s, min 0.0744s, max 0.0746s, p50 0.0745s (10 runs, warmup 3, torch.npu.synchronize() 前后计时)
  • Throughput: 13.43 windows/s (或 644 variate-steps/s)
  • Peak memory: 607.5 MB (torch.npu.max_memory_allocated)
  • 预处理计时: 不含 CSV 读取,仅含 tensor to(npu) + forecaster 内部 pad;数据生成在计时外,推理计时仅含 forecaster.forecast
  • CPU 对比: CPU 同任务约 0.35s/window (NPU 4.7x 加速)

证据图

图片说明
assets/agent_workflow.png侦察、下载、加载、NPU 推理完整工作流
assets/npu_device_call.pngnpu-smi、NPU 可用性、设备名、模型参数 device/dtype
assets/model_result.png默认 python inference.py 的真实完整输出

agent workflow npu device call model result

限制

  • 单窗口 smoke consistency,非全量 BOOM/GIFT-Eval benchmark;完整评测需运行官方 BOOM 流水线
  • 采样 (num_samples>0) 受 aten::_standard_gamma CPU fallback 影响,跨设备采样不一致,推荐生产使用均值或在 CPU 上采样
  • 仅验证 FP32;FP16/BF16 未测试
  • use_memory_efficient_attention=True 在无 xFormers 时自动回退到朴素 attention
  • 超长 context (>4096) 或 horizon (>1024) 未在单卡测试,可能需调整 samples_per_batch 或 context 分块