Kairos-23M (mldi-lab/Kairos_23m) — an adaptive time-series foundation model
(arXiv:2509.25826) for zero-shot forecasting, adapted for Ascend NPU via
torch_npu.
Kairos-23M is a 23M-parameter time-series foundation model pre-trained on the PreSTS corpus (300B+ time points). It uses a dynamic patching tokenizer (mixture-of-size MoE), instance-wise Dynamic Rotary Position Embedding (DRoPE) driven by FFT spectral features, and a T5-style encoder–decoder with eager attention. It produces a 9-quantile forecast (0.1..0.9) for an input context of up to 2048 points.
Architecture (from config.json):
model_type: kairos, d_model: 384, encoder layers 4, decoder layers 4
(2 decoder segments), num_heads: 8, d_kv: 64, d_ff: 1536input_patch_size: 128, input_patch_stride: 128,
levels: 3, MoE n_activated_experts: 3, n_null_experts: 2position_embedding_type: instance_wise_rope,
instance_rope_input_feature_dim: 128, rope_init: exp, scale_method: logcontext_length: 2048, prediction_length: 64 per segment
(max single-pass horizon 2 × 64 = 128)[0.1, ..., 0.9], ~23.00M parameters, fp32The official Kairos model code (tsfm package from
github.com/foundation-model-research/Kairos) is vendored into tsfm/.
The architecture is already NPU-friendly — T5 attention is eager matmul
(no flash-attention / SDPA), and the dynamic patching, MoE routing
(topk/bincount), InstanceNorm (nanmean), and complex rotary embeddings
(torch.polar/view_as_complex) all run natively on the NPU.
One source change (patches/kairos_ascend_npu.diff, in
tsfm/model/kairos/modeling_kairos.py::fft_process):
torch.abs on the complex64 rfft output is not supported by the NPU
(aclnnAbs error 161002) → the amplitude is computed manually as
sqrt(real^2 + imag^2) (max error 4.8e-6 vs torch.abs). Everything else is
zero code modification.
vLLM-Ascend 0.18 has no registry entry for the custom kairos encoder–
decoder architecture, so inference is served with torch_npu + FastAPI.
python3 download_model.py # -> /data/.cache/models/mldi-lab/Kairos_23mWeights are fetched from the GitCode HF mirror
(https://ai.gitcode.com/hf_mirrors/mldi-lab/Kairos_23m, resolve API) with
hf-mirror.com fallback; sha256 verified against the HF LFS oid
(8ad0e8f8…ffe482e3, 92,028,212 bytes).
KAIROS_DEVICE=npu:1 PORT=8056 ./start_serve.sh
# or:
python3 server.py --port 8056import json, urllib.request
payload = json.dumps({
"past_values": [[...], [...], [...]], # [C, T] (each row = one series, T >= 2048)
"prediction_length": 64, # horizon <= 128
}).encode()
req = urllib.request.Request("http://localhost:8056/v1/forecast",
data=payload, headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req) as resp:
out = json.loads(resp.read())
print(out["prediction"]) # [C, 9, L] quantile forecastspython3 make_test_data.py
python3 inference.py --input-json demo_series.json --device npu:1| context | horizon | latency (NPU p50) | HBM |
|---|---|---|---|
| 2048 | 64 | ~74 ms | ~1300 MB (process) |
First request includes aclnn operator compilation (~0.5 s); steady state is
kernel-cached. NPU vs CPU (fp32, same checkpoint) prediction cosine
≈ 0.99999+ / max_abs_diff ≤ 1e-4 — see verify_npu_vs_cpu.py.
inference.py — KairosEngine (library + CLI)server.py — FastAPI /v1/forecast, /healthdownload_model.py — weight download + sha256 verificationmake_test_data.py / test_server.py / verify_npu_vs_cpu.py — demo & checkstsfm/ — vendored official Kairos model code (1 NPU patch)patches/kairos_ascend_npu.diff — the single source changeWeights are not included in this repository; download them with
download_model.py.