TiRex 是基于 xLSTM 的零样本时间序列预测模型(35M 参数),支持任意长度的自回归预测。
本仓库为 NPU (Ascend 910) 适配版本,使用 torch_npu + tirex-ts 的 torch 后端(纯 PyTorch sLSTM 实现,无需自定义 CUDA 内核)。
| 配置 | 延迟 |
|---|---|
| batch=1, pred_len=32, context=128 | ~348ms |
| batch=8, pred_len=32, context=128 | ~347ms |
| batch=1, pred_len=100, context=20 | ~1.4s |
| 指标 | 值 |
|---|---|
| AICore 利用率 | ~6-7% |
| HBM 占用 | 3249 MB / 65536 MB |
| 进程内存 | 434 MB |
| 持续推理吞吐 | ~2.9 iters/s (batch=8) |
pip install tirex-ts torch_npu fastapi uvicorn pydantic# 默认使用 npu:1
python3 app.py
# 或指定设备和端口
TIREX_NPU_DEVICE=npu:0 TIREX_MODEL_PATH=/path/to/model.ckpt python3 app.pyPOST /forecast
{
"context": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
"prediction_length": 32,
"output_type": "numpy"
}响应:
{
"quantiles": [[[0.1_quantile, ..., 0.9_quantile], ...]],
"mean": [[0.5_quantile, ...]],
"quantile_labels": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"prediction_length": 32,
"inference_ms": 412.5,
"context_length": 10
}GET /health
{
"status": "ok",
"device": "npu:1",
"model_loaded": true,
"max_context_length": 2016
}import torch
from tirex import load_model
model = load_model("NX-AI/TiRex", device="cpu", backend="torch")
data = torch.rand((2, 128)) # 2 条时间序列, 每条 128 步
quantiles, mean = model.forecast(context=data, prediction_length=32)tirex-ts 库的 torch 后端(sLSTMCellTorch),无需自定义 CUDA 内核torch.minimum(torch.exp(...), torch.ones_like(...)) 会触发 allow_internel_format=False 告警,不影响正确性torch.npu 后端全流程测试,输出与 CPU 参考结果相关性 > 0.999999