#NPU
Datadog/Toto-2.0-1B (Toto2Model, 1.04B 参数, 3.9 GB model.safetensors float32)1604e1a5242884fb9848f88c4ced14f4dc62d9d3d_model=1536, num_layers=36, num_heads=24, d_ff=4096, patch_size=32, qk_dim=64, v_dim=64, num_groups=24, RoPE with xPos (use_xpos=True, per_dim_scale=True, layer_group_size=36, 35 time layers + 1 variate layer), residual_mult=0.75, residual_attn_ratio=5.13, quantile output head knots [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9] (9 quantiles, pinball loss)target [B, N, T] 输出 quantiles [Q=9, B, N, horizon] (本验证 horizon=96, 3 patches)context=512 → horizon=96 (patch 32), 支持 block decoding (decode_block_size) 与 KV cachePatchedCausalStdScaler + InputResidualMLP + VariateTimeTransformerDecoder + QuantileKnotsOutputHeadtoto2 (Datadog/toto, toto2/toto2/model.py 独立推理实现), huggingface_hub.PyTorchModelHubMixin, dd-unit-scaling, einops, jaxtyping| 项 | 值 |
|---|---|
| 轴顺序 | [B, N, T] 严格 (batch, variates, time); 输出 [Q, B, N, H] |
| 演示 | batch=1, variates=1, context=512, horizon=96 (3 patches × 32) |
| 频率 | 无显式 freq token; 依赖 causal scaler + patch embedding |
| 缩放 | PatchedCausalStdScaler(patch_size=32) 因果标准化 (Welford 方差) + asinh → embedding; backfill_short_patches 可选 |
| 缺失 | target_mask bool [B,N,T] 全 True (验证无缺失); NaN 前向填充/线性插值仅在 gluonts 集成时使用 |
| 数据来源 | 确定性合成 (seed 42): randn[1,1,512] + 0.2*sin(2πt/50), mean 0.0304 std 0.9809, preview last5 [0.973,0.790,0.604,-0.148,0.714], SHA256 509039e2 |
| 输出 | quantiles [9,1,1,96] float32 median q4=0.5 preview first5 [0.075,0.062,0.048,0.039,0.032], q0.1 [-1.175,-1.187,-1.209,-1.216,-1.227], q0.9 [1.315,1.309,1.296,1.291,1.279], monotonic True (min diff 0.25), finite True |
| dtype | float32 (NPU 上 PatchedCausalStdScaler 内部 float64 → float32 cast 警告属预期, 非 CPU fallback) |
| 预处理 | 无外部 scaling; 模型内 scaler → asinh → patch_proj(InputResidualMLP) |
Ascend910_9362 ×2, 目标 npu:0 (Phy-ID 6, Bus 0000:0B:00.0)torch.npu.is_available()==True, device_count==2HF_ENDPOINT=https://hf-mirror.com, 代理经环境变量 HTTP_PROXY=http://127.0.0.1:7890 直连, 无代码内手动设置Toto2Model.from_pretrained(local_dir) → .to("npu:0") → model.forecast (nn.Module, torch.no_grad, torch.npu.synchronize 计时)pip install -r requirements.txt
# 需 toto2 源码: inference.py 自动将 /tmp/toto/toto2 与 /tmp/fake_lightning 加入 sys.path
# 若无则 pip install -e /tmp/toto/toto2 (已预置) + fake lightning stubpython inference.py/opt/atomgit/.cache/huggingface/hub/models--Datadog--Toto-2.0-1B/snapshots/1604e1a.../model.safetensors 或 snapshot_download 自动下载 → npu:0 → warmup 3 → 同步计时 → 打印真实预测。关键日志(npu:0, seed 42):
[INFO] model_name: Datadog/Toto-2.0-1B
[INFO] device: npu:0 npu_device_name: Ascend910_9362
[INFO] first param device after to(npu:0): npu:0
[INFO] input NPU device target:npu:0 mask:npu:0 series_ids:npu:0
[INFO] warmup 3 runs ...
[RESULT] output shape (9, 1, 1, 96) device npu:0
[RESULT] median preview first5 [0.075,0.062,0.048,0.039,0.032]
[INFO] quantile monotonic: True
[PERF] avg 168.32 ms ... throughput 5.94 windows/s
[SUCCESS] NPU inference completed on npu:0 with Toto2Model (Datadog/Toto-2.0-1B) context 512 horizon 96npu:0 时非零退出; double dtype cast 警告为已知 NPU 限制非 fallback。median q0.5 first5 [0.0752,0.0620,0.0484,0.0394,0.0324]q0.1 [-1.175,-1.187,-1.209,-1.216,-1.227] q0.9 [1.315,1.309,1.296,1.291,1.279]output mean 0.02128 std 0.771 min -1.303 max 1.337quantile monotonic True min_diff 0.250071 finite Truepython .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_toto1B.npy --npu working/npu_toto1B.npy --task quantile --atol 1e-4 --rtol 1e-3
| 输出 | max_abs | mean_abs | passed |
|---|---|---|---|
quantiles [9,1,1,96] float32 | 5.48e-06 | 5.47e-07 | ✅ |
| monotonic cpu True npu True | — | — | ✅ |
Toto2Model.from_pretrained on cpu, 同 target/mask/series_ids, torch.manual_seed(42)..to("npu:0"), target.to("npu:0"), torch.npu.synchronize() 前后计时; 无 aten::_standard_gamma 等 CPU fallback (仅 double→float cast).torch.npu.synchronize())batch 1 ctx 512 horizon 96 Q9 patch 32PatchedCausalStdScaler + asinh + patch embedding (模型内)

node .opencode/skills/npu-adapt-skills/scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成 (深灰背景 白色等宽, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$), 仅截尾不改内容, token 已脱敏。ctx 512 horizon 96 smoke consistency; 非全量 BOOM/GIFT-Eval 基准 (需数千序列)。N>1 已支持 (alternating time/variate attention), 本仓演示 N=1; 更大 N / batch 需评估显存。decode_block_size / KV cache 路径未在本 smoke 中启用 (多块迭代推理需额外验证)。float32; float16/bf16 未测试。