liaogx_/kairos-23m
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Kairos-23M on Ascend NPU

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.

Model Description

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: 1536
  • dynamic patching: input_patch_size: 128, input_patch_stride: 128, levels: 3, MoE n_activated_experts: 3, n_null_experts: 2
  • DRoPE: position_embedding_type: instance_wise_rope, instance_rope_input_feature_dim: 128, rope_init: exp, scale_method: log
  • context_length: 2048, prediction_length: 64 per segment (max single-pass horizon 2 × 64 = 128)
  • 9 quantiles [0.1, ..., 0.9], ~23.00M parameters, fp32

NPU Adaptation

The 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.

Environment

  • Ascend 910 (64 GB HBM), CANN 8.5.1
  • Python 3.11.14, torch 2.9.0 / torch-npu 2.9.0.post1, transformers 4.57.6
  • einops 0.8.2, jaxtyping, fastapi / uvicorn

Usage

1. Download weights

python3 download_model.py     # -> /data/.cache/models/mldi-lab/Kairos_23m

Weights 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).

2. Start the service

KAIROS_DEVICE=npu:1 PORT=8056 ./start_serve.sh
# or:
python3 server.py --port 8056

3. Inference

import 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 forecasts

4. CLI

python3 make_test_data.py
python3 inference.py --input-json demo_series.json --device npu:1

Benchmarks (Ascend 910, npu:1)

contexthorizonlatency (NPU p50)HBM
204864~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.

Files

  • inference.py — KairosEngine (library + CLI)
  • server.py — FastAPI /v1/forecast, /health
  • download_model.py — weight download + sha256 verification
  • make_test_data.py / test_server.py / verify_npu_vs_cpu.py — demo & checks
  • tsfm/ — vendored official Kairos model code (1 NPU patch)
  • patches/kairos_ascend_npu.diff — the single source change

Weights are not included in this repository; download them with download_model.py.