#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.
0411ceb27bdf7fc3e4892e99edc8ad08192dc3c5)CausalPatchStdMeanScalermodel.safetensors 605 MB (FP32), config.json patch 64/stride 64/embed 768/12 layers/12 heads/mlp 3072MaskedTimeseries(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 = validid_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_length (需 pad 到 stride 64), prediction_length 48/96 常用;默认验证 context 512 -> horizon 48pad_array 到 stride 倍数,id_mask 同步 pad;无需归一化(模型内含 scaler)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 不可用模型权重首次运行时自动解析,优先级:
./model_snapshot (推荐离线放置)$HF_HOME/hub/models--Datadog--Toto-Open-Base-1.0-cache离线下载:
HF_ENDPOINT=https://hf-mirror.com huggingface_hub snapshot_download --repo-id Datadog/Toto-Open-Base-1.0 --local-dir ./model_snapshotpython 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 默认:
Toto.from_pretrained(model_dir).to(device) 并通过 TotoForecaster 生成 mean 预测 (无采样,确定性)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 MBmean [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-3max_abs_error 1.56e-06, mean_abs_error 4.50e-07, passed true (FP32 阈值 atol 1e-4, rtol 1e-3)torch.npu.synchronize() 前后计时)forecaster.forecast| 图片 | 说明 |
|---|---|
assets/agent_workflow.png | 侦察、下载、加载、NPU 推理完整工作流 |
assets/npu_device_call.png | npu-smi、NPU 可用性、设备名、模型参数 device/dtype |
assets/model_result.png | 默认 python inference.py 的真实完整输出 |

num_samples>0) 受 aten::_standard_gamma CPU fallback 影响,跨设备采样不一致,推荐生产使用均值或在 CPU 上采样use_memory_efficient_attention=True 在无 xFormers 时自动回退到朴素 attentionsamples_per_batch 或 context 分块