模型名称: mldi-lab/Kairos_50m
模型链接: HuggingFace
模型描述: Kairos-50M 是一个 5000 万参数的时序预测基础模型,支持零样本跨域时序预测。该模型采用动态分块分词器(Dynamic Patching Tokenizer)、混合大小编码器(Mixture-of-Size Encoder)和动态旋转位置编码(DRoPE),能够处理具有不同信息密度的异构时序数据。
模型架构: Transformer Encoder-Decoder + MoE(混合专家)
参数规模: ~50M(50,128,384 参数)
训练数据: PreSTS 语料库(3000 亿+时间点)
核心特性:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | 2.1.0+ | 与 torch_npu 匹配 |
| torch_npu | 2.1.0+ | 昇腾 NPU 后端 |
| transformers | >= 4.45.0 | HuggingFace 库 |
| jaxtyping | latest | 类型标注依赖 |
| 昇腾驱动 | CANN 8.0.RC2+ | 推荐最新版 |
安装命令:
pip install torch torch_npu transformers jaxtyping模型代码: 本模型使用 tsfm 库,需从 GitHub 获取模型代码:
git clone https://github.com/foundation-model-research/Kairos.git# 检查 NPU 设备
npu-smi info
# 确认 Python 环境
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"将模型文件和推理脚本放在同一目录下:
Kairos_50m/
├── config.json # 模型配置文件
├── model.safetensors # 模型权重(从 HuggingFace 下载)
├── inference.py # 推理脚本
├── tsfm/ # 模型代码(从 GitHub 获取)
│ ├── __init__.py
│ └── model/
│ └── kairos/
│ ├── __init__.py
│ ├── configuration_kairos.py
│ ├── modeling_kairos.py
│ └── ...
├── requirements.txt
└── README.md# NPU 推理(默认 context_length=2048, prediction_length=64)
python3 inference.py --device npu:0
# CPU 推理
python3 inference.py --device cpu
# 自定义参数
python3 inference.py --device npu:0 --context_length 1024 --prediction_length 96 --seed 42| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --device | str | 自动检测 | 推理设备(npu:0 / cpu) |
| --model_path | str | 当前目录 | 模型路径 |
| --context_length | int | 2048 | 输入序列长度 |
| --prediction_length | int | 64 | 预测序列长度 |
| --seed | int | 42 | 随机种子 |
import sys
sys.path.insert(0, "/path/to/Kairos_50m")
sys.path = [p for p in sys.path if not ('/.local' in p and 'torch' in p.lower())]
import torch
from tsfm.model.kairos import AutoModel
# 加载模型
model = AutoModel.from_pretrained("/path/to/Kairos_50m", trust_remote_code=True)
model = model.to("npu").eval()
# 准备输入:时序序列 (batch, context_length)
past_target = torch.randn(1, 2048).to("npu")
# 推理
with torch.no_grad():
forecast = model(
past_target=past_target,
prediction_length=64,
generation=True,
preserve_positivity=True,
average_with_flipped_input=True
)
# 输出:预测结果 (batch, num_quantiles, prediction_length)
predictions = forecast["prediction_outputs"]
print(predictions.shape) # torch.Size([1, 9, 64])
# 提取中位数预测(第 5 个分位数 = 0.5)
median_forecast = predictions[0, 4, :]
print(median_forecast)输入: 2048 个时间点的正弦波序列
python3 inference.py --device npu:0 --seed 42输出:
[模型] mldi-lab/Kairos_50m
[设备] Ascend910_9362 (npu:0)
[输入] 时序序列 (context_length=2048)
[输出] 预测shape=(1, 9, 64), 中位数范围=[-0.0146, 0.3856]
[耗时] 153.7ms
[状态] SUCCESS输入: 2048 个时间点的随机游走序列(seed=123)
输出:
预测 shape: (1, 9, 64)
预测范围: [2.1765, 3.9982]输入: 2048 个时间点,值恒为 5.0
输出:
中位数预测均值: 5.0020 (期望值 ~5.0)
中位数预测标准差: 0.0201


测试数据: 合成时序数据(正弦波、随机游走、常量信号)
评测指标:
| 测试场景 | MAE | RMSE | 80%区间覆盖率 |
|---|---|---|---|
| 正弦波 (2048→64) | 0.0037 | 0.0045 | 100.00% |
| 常量信号 | - | - | 均值偏差 0.002 |
| 随机游走 | - | - | 范围合理 |
model.safetensors,约 191MB)需自行从 HuggingFace 下载tsfm 库)需从 GitHub 克隆获取torch_npu 调用昇腾 NPUsys.path 过滤需保留 .local 路径中的非 torch 依赖(如 jaxtyping)