liaogx_/ttm-research-r2
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

IBM TTM Research R2 (ttm-research-r2) on Ascend NPU

TinyTimeMixer (TTM) is a compact pre-trained multivariate time-series forecasting foundation model by IBM Research (NeurIPS 2024, arXiv:2401.03955). This is the research-use TTM R2 checkpoint (512-96-ft-r2): context length 512, prediction length 96, 854,972 parameters, pre-trained on ~700M time-series samples. TTM uses an encoder-decoder backbone built from lightweight T5-style mixing blocks with patch-based channel mixing and per-channel standard scaling. This R2 checkpoint enables resolution-prefix tuning: a learned frequency token is prepended to the input patches, so the caller passes the data resolution (h, min, …).

This adaptation deploys the model as a FastAPI service on Ascend NPU using torch_npu + the official granite-tsfm library (TinyTimeMixerForPrediction) — zero source-code patches required.

FieldValue
Modelibm-research/ttm-research-r2
ArchitectureTinyTimeMixerForPrediction (T5-style encoder-decoder, 2+2 layers)
Params854,972
Context / Prediction512 / 96 time points
Inputper-channel raw history [T], [T,C] or [B,T,C] (internally std-scaled) + freq
Backendtorch_npu 2.9.0.post1 (Ascend 910)
LicenseCC-BY-NC-SA-4.0 (research use)

Environment

  • Ascend 910 (2× 64GB HBM), CANN 8.5.1, torch 2.9.0 / torch-npu 2.9.0.post1
  • transformers 4.57.6, granite-tsfm 0.3.8, python 3.11

Note: TinyTimeMixerForPrediction is not part of the transformers 4.57.6 model registry — it ships in the official IBM granite-tsfm PyPI package, which requires transformers>=4.57.6,<6 (matches this environment).

Deployment

# 1. weights (ModelScope, ~3.4MB, sha256-verified)
python3 download_model.py

# 2. install runtime
pip install granite-tsfm==0.3.8 fastapi "uvicorn[standard]"   # torch/torch-npu preinstalled

# 3. start service on NPU 1, port 8043
bash start_serve.sh
# or:  python3 server.py --host 0.0.0.0 --port 8043 --device npu:1

Usage

# single channel, 512 history points -> 96-step forecast (hourly resolution)
curl -s http://127.0.0.1:8043/v1/forecast \
  -H 'Content-Type: application/json' \
  -d '{"past_values": [0.1, 0.2, 0.3, ... 512 values], "freq": "h"}'

Response:

{
  "prediction": [[[0.6030], [0.4919], ...]],
  "shape": [1, 96, 1],
  "context_length": 512,
  "prediction_length": 96,
  "freq": "h",
  "latency_ms": 6.82,
  "backend": "npu:1"
}

Supported input shapes: [T] (single channel), [T,C] (multi-channel), [B,T,C] (batched). Shorter histories are left-padded internally; longer histories are truncated to the last 512.

freq (default h) selects the resolution-prefix token: oov/min/2min/5min/10min/15min/30min/h (mapped to token indices 0..7 per tsfm_public's DEFAULT_FREQUENCY_MAPPING; the research R2 was trained with frequency_token_vocab_size=8, so daily/weekly are out of vocab and rejected with HTTP 400). Minutely-to-hourly resolutions are supported, matching the official model card.

NPU adaptation notes

  • vLLM-Ascend 0.18 is not applicable — TTM is a non-autoregressive time-series encoder-decoder, not an LLM in the vLLM registry. Deployment uses torch_npu.
  • Unique to research R2: resolution_prefix_tuning=true — the forward pass requires a freq_token (a [B] integer embedding index); without it the model raises "Expecting freq_token in forward". The engine maps a frequency string to the token index and broadcasts it across the batch.
  • The model uses only eager matrix ops / GELU / LayerNorm / nn.Embedding — no flash-attention, no custom CUDA kernels, so no source patch is needed (fp32).
  • Internal per-channel standard scaling (TinyTimeMixerStdScaler) is applied by the model, so raw values are fed directly.

Results (on Ascend 910, NPU 1)

  • Model load: ~1.15 s
  • NPU forward (batch 1, 512×1, freq=h): p50 5.12 ms / forecast
  • Steady-state HTTP (30 reqs after warmup): p50 6.82 ms, p95 6.92 ms, ~148 req/s
  • NPU vs CPU (fp32, 2-batch / 2-channel): max_abs_diff 1.10e-04, cosine 1.0000000000 (PASS)
  • NPU HBM footprint: 128 MB process memory (855K-param model)

Files

  • inference.py — engine + CLI (--past_values, --freq, --serve)
  • server.py — FastAPI service (/health, /v1/forecast)
  • download_model.py — ModelScope weight fetch + sha256 check (idempotent)
  • start_serve.sh — one-shot launch
  • make_test_data.py — synthetic demo series generator
  • test_server.py — service smoke test (4 input-shape cases)
  • verify_npu_vs_cpu.py — NPU/CPU parity check