#NPU
本仓库将 HuggingFace 上的 Datadog/Toto-2.0-2.5B-FT(Toto 2.0 时间序列基础模型的 2.5B 概率预测微调版,finetuned on GIFT-Eval train split for benchmarking, 2.45B 参数,patch 32, d_model 2048, 48 层 Transformer,9 分位数概率预测)适配为可在单卡昇腾 Ascend 910B(npu:0)上真实运行的 GitCode AI model 仓库。支持多变量时序的零样本概率预测,输出 9 个分位数(0.1~0.9)与中位数点预测。
model.safetensors 约 9.82 GB(2,454,281,792 参数, float32, safetensors),config.json patch_size 32, d_model 2048, num_heads 32, num_layers 48, d_ff 5464, num_groups 32, layer_group_size 48, use_xpos True, per_dim_scale Truetoto2.model.Toto2Model, 论文 https://arxiv.org/abs/2605.20119),基于 Datadog/Toto-2.0-2.5B 基座微调 10k steps[!WARNING] Benchmarking checkpoint, not general-purpose: 官方说明此权重为在 GIFT-Eval train split 上微调的复现版本,仅用于 benchmark。真实业务请使用 base
Datadog/Toto-2.0-2.5B。本仓验证该 FT 权重的 NPU 真实推理与一致性。
| 项 | 值 |
|---|---|
| 模型 | Datadog/Toto-2.0-2.5B-FT(revision b4f030fb, 2.454B params, 9.82 GB fp32) |
| 架构 | Toto2Model (PatchedCausalStdScaler + PatchProj + 48×TransformerBlock 含交替 time/variate attention + Quantile Head, use_xpos, per_dim_scale) |
| 任务 | 时间序列概率预测 probabilistic forecasting(9 分位数) |
| 输入 | target shape [batch, n_variates, time](本仓 batch 2, n_variates 1, time 512, float32),target_mask bool, series_ids long, horizon=96 |
| 输出 | quantiles shape [9, batch, n_variates, horizon](本例 [9,2,1,96])分位数预测,median 为 q=0.5 |
| 数据契约 | 轴顺序 [batch, n_variates, time] 输入 -> [quantile, batch, n_variates, horizon] 输出;context 512(patch 32, 16 patches),horizon 96,频率隐式,缩放经 PatchedCausalStdScaler,缺失值以 mask 标记,dtype float32 |
| 路由 | time-series 概率预测,验收 quantile monotonic 与数值一致性 |
表格数据类型关联:适用于表格数据(CSV/Parquet)中多列数值时序的零样本预测,任务映射为 forecasting,验收指标为 quantile 单调性、forecast 数值一致性与性能。
torch 2.9.0+cpu + torch_npu 2.9.0.post1+gitee7ba04,transformers 4.57.6,einops 0.8.2,safetensors, huggingface_hub, jaxtyping 0.3.11, unit-scaling 0.3.5pip install -r requirements.txt
pip install jaxtyping unit_scaling
git clone https://github.com/DataDog/toto.git /tmp/toto_git
pip install /tmp/toto_git/dd_unit_scaling --no-build-isolation --ignore-requires-python || python -c "import sys; sys.path.insert(0, '/tmp/toto_git/dd_unit_scaling')"
pip install /tmp/toto_git/toto2 --no-build-isolation --ignore-requires-python --no-depsinference.py 为自包含脚本,默认使用合成可复现时序(seed 0)在 npu:0 上完成 CPU 基线、NPU 推理、一致性与性能基准。核心 forward 的所有参数与参与计算的 Tensor 均显式位于 npu:0。计时前后均调用 torch.npu.synchronize()。
python inference.py
MODEL_DIR=/path/to/Datadog-Toto-2.0-2.5B-FT python inference.py设备选择固定为 npu:0,输入输出均校验 device 均为 npu:0,无 CPU fallback。
以合成时序 batch=2, n_variates=1, ctx=512, horizon=96, 9 quantiles 为例(seed 0,torch.randn):
target shape (2,1,512),均值 0.0322,标准差 1.0280,范围 [-3.1537, 4.1015];target_mask 全 True;series_ids [0]quantiles shape (9,2,1,96) 均值 0.002417,标准差 0.817731,最值 [-1.419487, 1.405172],horizon0 9 分位数 [-1.314498, -0.846157, -0.518020, -0.237040, 0.026027, 0.288734, 0.568743, 0.899142, 1.355247],单调性 True,median 前5 [0.026027, 0.019438, 0.023716, 0.026022, 0.024541]npu:0 上 quantiles shape (9,2,1,96) 均值 0.0024,标准差 0.8177,最值 [-1.4195, 1.4052],horizon0 9 分位数 [-1.314501, -0.846155, -0.518020, -0.237040, 0.026027, 0.288735, 0.568744, 0.899143, 1.355246],单调性 True,median 前5 [0.026027, 0.019438, 0.023716, 0.026023, 0.024541][STATUS] SUCCESS - NPU inference completed without CPU fallback,[MODEL] all param devices: {'npu:0'},total params 2454281792完整输出见 model_result.png。
使用相同权重(通过 deepcopy)、相同数据切片(seed 0)、相同预处理、相同随机种子与 float32 精度,分别在 CPU 与 npu:0 上运行并保存原始输出,用 scripts/compare_outputs.py 比较:
python scripts/compare_outputs.py --cpu /tmp/toto_cpu.npy --npu /tmp/toto_npu.npy --task forecasting --atol 1e-4 --rtol 1e-3max_abs 7.27e-06,mean_abs 7.82e-07,atol=1e-4 rtol=1e-3 PASS,有限值 True,单调性 CPU True / NPU Trueatol=1e-4 rtol=1e-3(FP32 跨硬件正常波动)结果:PASS。
在 npu:0、float32 下,预热 3 次后正式计时 10 次(batch=2, ctx=512, horizon=96, n_variates=1, 9 quantiles):
| 指标 | 值 |
|---|---|
| warmup 3 runs | 600.47 ms / 267.70 ms / 238.04 ms |
| compile/first-run | 236.78 ms |
| avg / min / max | 224.86 / 216.26 / 236.99 ms |
| p50 / p90 / p95 | 223.95 / 236.80 / 236.90 ms |
| throughput | 8.89 windows/s(batch 2) |
| batch / ctx / horizon / n_variates / quantiles / dtype | 2 / 512 / 96 / 1 / 9 / float32 |
| 权重显存 | 约 9.82 GB(model.safetensors 9817176960 bytes, 2.454B params) |
| 峰值 NPU 显存 | 约 14 GB(权重 9.82GB + 激活 + 编译),npu-smi 空载 3113 MB -> 未 OOM |
计时均含 torch.npu.synchronize() 前后同步。
三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成,深灰背景、等宽字体,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$:
assets/agent_workflow.png:侦察、环境采集、模型检查、NPU 推理、一致性、性能与提交校验assets/npu_device_call.png:npu-smi、NPU 可用性、设备名、模型参数 device/dtype、输入与输出 Tensor deviceassets/model_result.png:默认 python inference.py 的真实完整输出

target 为 float32,文本/分类列需自行编码npu:0),训练仍需 GPU/CPUapache-2.0apache-2.0,详见 HuggingFace 模型卡