w
gcw_uQ09W7jl/Datadog-Toto-2.0-22m-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Datadog Toto-2.0-22m on Ascend NPU #NPU

Model Introduction

Model Name: Datadog/Toto-2.0-22m
Revision: main (model.safetensors 84 MB, 22M params, d_model=512, num_layers=6, patch_size=32)
Model Weight URL: https://huggingface.co/Datadog/Toto-2.0-22m
Model Type: Time-Series Foundation Model (probabilistic forecasting)
Task Type: forecasting (quantile forecasting, 9 quantiles 0.1–0.9)
Architecture Family: Decoder-only Patched Transformer with alternating time/variate attention, u-μP scaling
Pipeline Tag: time-series-forecasting
Weights: model.safetensors (84 MB, fp32) + config.json
License: Apache-2.0

Toto 2.0 is Datadog's observability time-series foundation model family (4m–2.5B). 22m is the efficient default: 6 layers, 8 heads, d_model 512, d_ff 1368, patch_size 32, num_output_patches 1, u-μP-scaled, trained with quantile pinball loss. Input is [batch, n_var, time] (e.g. [2,2,512]), output is quantiles [9, batch, n_var, horizon] (horizon 96). Supports variable context/horizon, multivariate via variate attention, causal scaling (PatchedCausalStdScaler + arcsinh) and xPos RoPE.

Data Contract

FieldValue
Input Format[batch, n_variates, time] e.g. [2,2,512]
Axis OrderB N T (batch, variate, time) – Toto2Model expects target: [B,N,T]
Context Length512 (demo) – model supports arbitrary (patch_size 32, must be multiple, training up to 4096)
Prediction Length (horizon)96 (3 patches)
Channels / Variates2 (demo, supports N≥1, multivariate via variate attention layers)
FrequencyAgnostic (no freq token, continuous time)
ScalingPatchedCausalStdScaler per variate (causal mean/std per patch, patch_size 32) + asinh transform, inverse not needed for quantile output (quantiles are in real space via loc/scale)
Masktarget_mask all True (clean synthetic), has_missing_values=False for deterministic path
Series IDsseries_ids [B,N] – [[0,1],[0,1]] distinct per variate to enable variate attention
Patch Size32
Dtypefloat32 (weights fp32, compute fp32, NPU float64 fallback to float32)
PreprocessingSynthetic sinusoid: sin(2π freq t + phase) + 0.001*t + N(0,0.1), freq 0.02/0.025, seed 42 deterministic
Data SourceSynthetic deterministic (no external CSV), reproducible with seed 42
SHA256Synthetic – no dataset file
Outputquantiles [9,B,N,H] float32 – 9 quantiles [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]

No fit() required; zero-shot inference.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04
  • transformers 4.57.6, einops 0.8.2, safetensors, huggingface_hub 0.36.2, jaxtyping, unit_scaling 0.3.5, dd_unit_scaling 0.1.0, toto2 2.0.0 (patched for Python 3.11, gluonts optional)
  • numpy 1.26.4, pandas 3.0.2
  • Ascend CANN 8.5.1, torch.npu.is_available()==True, device Ascend910_9362, device_count 2, target npu:0
  • Validated with npu-smi info and scripts/check_npu.py

Installation

pip install -r requirements.txt
# additional: install toto2 and dd_unit_scaling from Datadog repo (requires --ignore-requires-python for Python 3.11)
pip install --ignore-requires-python --no-deps git+https://github.com/DataDog/toto.git#subdirectory=dd_unit_scaling
pip install --ignore-requires-python --no-deps git+https://github.com/DataDog/toto.git#subdirectory=toto2
# or use pre-cloned /tmp/toto if available
pip install --ignore-requires-python --no-deps /tmp/toto/dd_unit_scaling /tmp/toto/toto2

Model weights: auto-loaded from /opt/atomgit/adapt-npu-agent/working/models/Toto-2.0-22m if present, else from https://huggingface.co/Datadog/Toto-2.0-22m via from_pretrained (requires HF_ENDPOINT mirror if needed). No extra tokenizer.

NPU Inference

Default command (runs synthetic demo with NPU):

python inference.py

Expected output includes:

  • model_name, task, backend, device_name, target_device
  • config: d_model=512, num_layers=6, patch_size=32
  • target shape [2,2,512], sample values, stats
  • CPU baseline quantiles shape [9,2,2,96], median sample, monotonic True
  • first_param device: npu:0, input device: npu:0, NPU quantiles shape: [9,2,2,96] device: npu:0
  • first run (compile) time with torch.npu.synchronize() and second run time
  • Benchmark avg/min/max/p50/p90/p95 and throughput
  • Consistency max_abs, mean_abs, allclose
  • Final state: SUCCESS

Supports different horizon (e.g. 192) and decode_block_size for KV-cache block decoding.

Real Results (Verified NPU)

Run: python inference.py (batch=2, n_var=2, context=512, horizon=96, float32, npu:0)

Input:

  • target [2,2,512], sample [0.1926, 0.2750, 0.3407, 0.1605, 0.5535], mean 0.2648 std 0.7235

Output:

  • CPU quantiles [9,2,2,96], median CPU [1.53833, 1.53186, 1.51287, 1.48750, 1.43271]
  • NPU quantiles [9,2,2,96], median NPU [1.53833, 1.53186, 1.51287, 1.48750, 1.43271] (max_abs 3.93e-06)
  • Quantile q0.1 CPU [1.41978, 1.40434, 1.41403, 1.37293, 1.33509] vs NPU same diff <4e-06
  • Quantile q0.9 CPU [1.65090, 1.64137, 1.63793, 1.61175, 1.57550] vs NPU same
  • monotonic True, finite True

Timing (npu:0, synchronized):

  • First run (compile): ~350 ms
  • Second run: ~34 ms
  • Stable avg: ~32 ms (warmup 3, test 10)
  • Throughput: ~124 windows/s (2*2 variates), ~62 samples/s
  • Memory: allocated ~107 MB, reserved ~178 MB

No CPU fallback; all tensors on npu:0.

Consistency Verification

Saved CPU/NPU outputs to .npy and compared:

python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/cpu_toto.npy --npu /tmp/npu_toto.npy --task forecasting --atol 1e-4 --rtol 1e-3

Result: max_abs 3.9339e-06 mean_abs 7.09e-07 passed True (fp32 atol=1e-4). Quantile monotonic and finite checked, allclose True. Differences due to NPU float64→float32 fallback in scaler (acceptable within tolerance).

Performance

Warmup 3, test 10, synchronized:

  • compile/first_run 350.73 ms, avg 32.09 ms, min 31.91 ms, max 32.37 ms, p50 32.11 ms, p90 32.24 ms, p95 32.31 ms
  • batch=2, n_var=2, context=512, horizon=96, dtype float32, device npu:0
  • throughput ~124 windows/s, ~62 series/s
  • peak NPU memory 107 MB allocated, 178 MB reserved
  • preprocessing (synthetic generation) not included in timed region; timed region is model.forecast only

Additional: horizon 192 with decode_block_size=768 (KV-cache multi-block) validates KV-cache path: shape [9,2,2,192] correct.

Evidence

Three PNGs generated by xterm.js from real logs (render_xterm_evidence.mjs --style raw):

  • assets/agent_workflow.png – workflow (inspect, download, NPU check, inference, compare, benchmark, validation)
  • assets/npu_device_call.png – npu-smi + torch.npu availability + model param device + input/output device
  • assets/model_result.png – full python inference.py output

Images are rendered from actual terminal logs, not screenshots, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$ is display label only.

agent workflow npu device call model result

Limitations

  • Synthetic data only; real observability series may differ in distribution but architecture is zero-shot foundation.
  • Context must be multiple of patch_size 32 (512 in demo); longer contexts up to training max (4096) supported but not benchmarked here.
  • Horizon must be multiple of patch_size; arbitrary horizon via ceil(patch).
  • FP64 scaler on NPU falls back to FP32 (NPU does not support double), causing ~1e-6 diff vs CPU (within tolerance).
  • decode_block_size must be divisible by patch_size; KV-cache path validated for horizon 192.
  • Weights not included in repo (download from HuggingFace); model.safetensors 84 MB.