liaogx_/toto-2.0-313m
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Toto-2.0-313m on Ascend NPU

Datadog Toto-2.0-313m is the 313M-parameter member of the Toto 2.0 family of time-series foundation models for multivariate forecasting (technical report: arXiv:2605.20119, TIME benchmark: arXiv:2602.12147). It is a u-μP-scaled decoder-only patched transformer with alternating time-axis (causal) and variate-axis (full) attention, a quantile output head (9 knots 0.1…0.9 trained with pinball loss), contiguous patch masking (CPM) for single-pass parallel decoding, a robust arcsinh input scaler and a residual MLP patch projection. Datadog positions it as a strong general-purpose checkpoint — top-3 foundation model on GIFT-Eval.

This adaptation deploys the model for service-based probabilistic forecasting on an Ascend 910 NPU via torch_npu. vLLM-Ascend 0.18 does not support this custom time-series architecture, so the standalone Toto2Model (from DataDog/toto, vendored) is used as-is on torch_npu — zero source modification to the model; only the GluonTS wrapper was stripped from the vendored package.

Model

AttributeValue
Parameters313M (fp32 safetensors 1.17 GB)
Architecturedecoder-only transformer, d_model=1024, num_layers=24, num_heads=16, qk_dim/v_dim=64, d_ff=2736, patch_size=32, xPos RoPE, SwiGLU MLP, τ-rule residual (residual_mult=0.75), MuP (per-dim scale)
Attentiontime/variate alternating groups (layer_group_size=24, last layer = variate, heads_per_group=1)
Output9 quantiles [0.1 … 0.9], shape [9, batch, n_variate, horizon]
Taskzero-shot multivariate time-series forecasting (observability / GIFT-Eval / TIME)

Environment

  • Ascend 910 ×2 (64 GB HBM/card), CANN 8.5.1
  • Python 3.11, torch 2.9.0 + torch-npu 2.9.0.post1
  • unit-scaling==0.3.5 (PyPI) + vendored dd_unit_scaling + vendored toto2 (GluonTS-stripped)
  • fastapi / uvicorn / pydantic

Quick start

# 1. download weights (ModelScope, sha256-verified)
python3 download_model.py

# 2. generate a demo test series
python3 make_test_data.py

# 3. run a one-shot forecast on NPU
python3 inference.py --device npu:1 --num-variates 3 --time-steps 1024 --prediction-length 96

# 4. start the HTTP service (default port 8040, device npu:1)
./start_serve.sh 8040 npu:1

Service API

POST /v1/forecast

{
  "series": [[1.0, 2.0, ...], [...], ...],   // [variate, time_steps]; 1D accepted; NaN allowed
  "prediction_length": 96,                   // future steps (1..4096)
  "decode_block_size": 768,                  // CPM block size (multiple of 32)
  "has_missing_values": true
}

Response: {quantiles: {"0.1": […], …, "0.9": […]}, median, prediction_length, n_variates, latency_ms}, each quantile a [n_variate, horizon] array.

Test cases & results (Ascend 910, npu:1)

ConfigLatency (HTTP p50)Notes
3 var / ctx 1024 / pred 96~120 msquantiles monotonic
3 var / ctx 512 / pred 96~110 ms
1 var / ctx 4096 / pred 336~135 mslong context
1 var / ctx 1024 / pred 1024~250 msKV-cache block decoding
  • Model load: ~6 s; process HBM ~1.6 GB (npu:1)
  • NPU vs CPU (fp32) over 2 variates × 512 steps × pred 96: per-quantile max_abs_diff ≤ 1e-4, cosine ≥ 0.9999999, median corr ≈ 1.0 → PASS
  • Steady-state compute (2 var / ctx 1024 / pred 96): NPU vs CPU significant speedup from the 24-layer transformer (queries per-forecast latency).

NPU adaptation notes

  • Engine: torch_npu. vLLM-Ascend 0.18 (317-architecture registry) has no entry for this custom time-series model, so the standalone Toto2Model is loaded directly.
  • Zero source patch: native F.scaled_dot_product_attention → aclnnFlashAttentionScore; fp64 causal patch scaler, asinh, quantile head and torch.distributions all run natively on NPU.
  • Vendored packages (toto2/, dd_unit_scaling/): the toto2 Toto2GluonTSModel (GluonTS wrapper, pulls in lightning) is stripped — see patches/toto2_ascend_npu.patch. dd_unit_scaling (u-μP layer wrappers) is vendored; upstream unit-scaling comes from PyPI.
  • NaN handling: masked NaN positions are zero-filled on input so the causal scaler's cumsum is not poisoned; the model still treats them as missing via target_mask.

Deliverables

inference.py (torch_npu engine + CLI) · server.py (FastAPI /v1/forecast) · download_model.py (ModelScope + sha256) · make_test_data.py · verify_npu_vs_cpu.py · test_server.py · start_serve.sh · toto2/ + dd_unit_scaling/ (vendored) · patches/toto2_ascend_npu.patch · requirements.txt · assets/ (screenshots)

Weights are not included in this repo — download them with download_model.py (source: ModelScope Datadog/Toto-2.0-313m, sha256 5ee60664…aa2f9).