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.
| Field | Value |
|---|---|
| Model | ibm-research/ttm-research-r2 |
| Architecture | TinyTimeMixerForPrediction (T5-style encoder-decoder, 2+2 layers) |
| Params | 854,972 |
| Context / Prediction | 512 / 96 time points |
| Input | per-channel raw history [T], [T,C] or [B,T,C] (internally std-scaled) + freq |
| Backend | torch_npu 2.9.0.post1 (Ascend 910) |
| License | CC-BY-NC-SA-4.0 (research use) |
torch 2.9.0 / torch-npu 2.9.0.post1transformers 4.57.6, granite-tsfm 0.3.8, python 3.11Note:
TinyTimeMixerForPredictionis not part of the transformers 4.57.6 model registry — it ships in the official IBMgranite-tsfmPyPI package, which requirestransformers>=4.57.6,<6(matches this environment).
# 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# 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.
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.TinyTimeMixerStdScaler) is applied by the
model, so raw values are fed directly.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 launchmake_test_data.py — synthetic demo series generatortest_server.py — service smoke test (4 input-shape cases)verify_npu_vs_cpu.py — NPU/CPU parity check