waylong/Datadog-Toto-2.0-4m-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Datadog/Toto-2.0-4m NPU

Datadog/Toto-2.0-4m — 4M parameter probabilistic time-series foundation model for multivariate forecasting, adapted to Huawei Ascend 910B npu:0 via torch_npu.

  • Model: Datadog/Toto-2.0-4m (https://huggingface.co/Datadog/Toto-2.0-4m), revision 8306a9801cf98c0f5ffe4b2dcc8f496e616d84d9
  • Weights: model.safetensors 16.58 MB, fp32, Apache-2.0
  • Architecture: Toto2 decoder-only patched transformer, patch_size=32, d_model=256, num_layers=4, num_heads=4, num_groups=4, heads_per_group=1, d_ff=688, quantile head (9 quantiles 0.1-0.9)
  • Task: time-series forecasting (probabilistic quantiles) #NPU
  • Input: [batch, n_variates, time] float32, context 512 (multiple of 32), e.g. (1,1,512); also validated (2,3,512)
  • Output: quantiles [9, batch, n_variates, horizon] horizon default 96

Data Contract

  • Time-series: no CSV required; uses synthetic realistic traces (torch.randn with seed 0) representing multivariate observability metrics. Real deployment should feed target as [batch, channel, time] with target_mask bool and series_ids long. Data validated with same seed for CPU/NPU consistency.
  • Context: 512 (16 patches), horizon 96 (3 patches), decode_block_size 768, frequency agnostic, causally scaled via PatchedCausalStdScaler with per-dim scaling.
  • Axis order: [batch, variate, time] preserved; no transpose tricks.
  • Preprocessing: arcsinh-like robust scaler inside model, quantile monotonicity enforced, no external inverse transform needed for raw quantiles.
  • No training/fine-tuning; zero-shot inference only.

Environment

  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1, safetensors 0.7.0, transformers 4.57.6, einops 0.8.2, gluonts 0.17.0, dd-unit-scaling 0.1.0, jaxtyping 0.3.11
  • NPU: Ascend910_9362, 2 devices, tested on npu:0, npu-smi 25.5.5, CANN 8.5.1, torch.npu.is_available()==True
  • Code: toto2 standalone toto2.Toto2Model.from_pretrained loaded from local ./Datadog-Toto-2.0-4m

Installation

pip install torch torch_npu einops safetensors huggingface-hub jaxtyping dd-unit-scaling gluonts lightning matplotlib
# install toto2 from source (requires python>=3.12 patched to >=3.11):
pip install git+https://github.com/DataDog/toto.git  # or pip install ./toto2 with python>=3.11 fix
huggingface-cli download Datadog/Toto-2.0-4m --local-dir Datadog-Toto-2.0-4m

NPU Inference

python inference.py                          # default 512 context, 96 horizon, batch 1, 1 variate, npu:0
python inference.py --context 512 --horizon 96 --batch 2 --variates 3

inference.py auto-selects npu:0 if available, else CPU, loads local weights, runs synchronized forecast, prints config, device, shapes, quantiles and timing. Exit non-zero on error.

Results (single run, seed 0, fp32)

  • Input: target (1,1,512) random normal, target_mask all True, series_ids 0, horizon 96
  • Output: quantiles (9,1,1,96) device npu:0, mean ≈ -0.24, median first 5 [-0.218, -0.198, -0.182, -0.191, -0.181], q0.1 ≈ -1.54, q0.9 ≈ 1.14, quantile monotonic True
  • Multi-series (2,3,512) -> (9,2,3,96) mean ≈ -0.055, timing 99 ms, throughput ≈ 60 series/s

Exact values are seed-dependent; see model_result.png for live run.

Consistency

  • CPU vs NPU same weights/seed/preprocess/dtype (float32), fixed input torch.manual_seed(0); comparison via scripts/compare_outputs.py --task quantile --atol 1e-3 --rtol 1e-3
  • Result: max_abs 2.98e-06, mean_abs 4.6e-07, finite True, monotonic True (cpu & npu), passed True
  • Threshold relaxed to 1e-3 due to float32 and known NPU double->float cast, but observed error is 1e-6 level, well within FP32 tolerance.
  • No CPU fallback; all tensors and model on npu:0, verified via next(model.parameters()).device == npu:0 and quantiles.device == npu:0.

Performance (Ascend910_9362, fp32, horizon 96, context 512)

  • Warmup 3 + 10 measured, sync via torch.npu.synchronize(), batch 1×1:
    • compile/first-run 233-248 ms, stable avg 24.77 ms, min 24.47 ms, max 25.43 ms, p50 24.52 ms, p90 25.41 ms, p95 25.42 ms, ≈ 40 windows/s, peak HBM ~3.1 GB
  • Batch 2×3: 98-99 ms for 6 series, ≈ 61 series/s
  • Preprocessing not timed separately; end-to-end forecast includes scaler.

Limitations

  • Requires context_length % 32 == 0, horizon arbitrary but tested at 96; very long context (>2048) may exceed single-card HBM for large variate counts.
  • NPU warns Device do not support double, cast to float (scaler float64->float) — numerically verified negligible.
  • Zero-shot only; fine-tuning path not validated on NPU; GluonTS integration not used in NPU path.

Evidence

  • assets/agent_workflow.png — full workflow log (inspect, NPU check, CPU/NPU runs, compare, bench, inference)
  • assets/npu_device_call.png — npu-smi info, torch.npu availability, model param device/dtype, input/output Tensor device
  • assets/model_result.png — default python inference.py complete output with shapes, quantiles, timing and SUCCESS status

Images rendered via Pillow emulating xterm.js dark theme (raw style) from actual logs; prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$.