NX-AI/TiRex 是 35M 参数的预训练时序预测模型,基于 xLSTM 实现零样本长/短周期预测,输出 9 分位数 (0.1..0.9) 与均值点估计。论文 TiRex: Zero-Shot Forecasting across Long and Short Horizons with Enhanced In-Context Learning,模型卡见 NX-AI/TiRex。
63c740922493f5fbe60b277609ec62babfba2762model.ckpt 135 MB / tirex.onnx 136 MB,参数量 35,291,200,FP32,TiRexZeroinput_patch_size=32, output_patch_size=32, quantiles=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9], num_blocks=12, embedding_dim=512, num_heads=4, train_ctx_len=2048torch, tirex-ts, torch_npu, einops;backend="torch" 为纯 PyTorch 实现,无 CUDA kernel 编译,NPU 上无需 trust_remote_codecontext [batch=2, context_length=512] float32,单变量,确定性合成(seed 42),均值 ~1.0088,std ~1.1484quantiles [2, 64, 9] float32,9 分位数递增(monotonic=True),finite True;mean [2, 64] float32
mean[0,:5]=[2.0219,1.9578,1.8869,1.8924,1.9184],quantiles[0,0,:]=[0.8578,1.2295,1.5319,1.7955,2.0219,2.2448,2.4938,2.7983,3.2247]pip install -r requirements.txt默认 python inference.py 即在 npu:0 完成真实推理,无需参数。若环境无 NPU 则显式报错退出,不会静默回退 CPU。
python inference.py在 npu:0 上,使用上述合成输入(种子 42),单次 NPU 推理(同步计时):
quantiles [2,64,9] finite True, monotonic True;mean [2,64] finite TrueCPU 与 NPU 使用 同一权重、输入、预处理、dtype(FP32)、随机种子(42)、eval 模式,分别保存 quantiles 进行比较。为满足 compare_outputs.py 对 quantile 单调性的 axis=-2 检查,比较前将 [B, T, Q]=[2,64,9] 转置为 [B, Q, T]=[2,9,64].
python -c "import numpy as np; a=np.load('working/cpu_tirex.npy'); np.save('working/cpu_tirex_trans.npy', np.transpose(a,(0,2,1))); b=np.load('working/npu_tirex.npy'); np.save('working/npu_tirex_trans.npy', np.transpose(b,(0,2,1)))"
python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_tirex_trans.npy --npu working/npu_tirex_trans.npy --task quantile --atol 0.01 --rtol 0.01max_abs_error 0.005318 mean_abs_error 0.001754 passed true (atol 0.01 rtol 0.01)预热 3 次、正式 10 次,torch.npu.synchronize() 前后计时,batch=2, context=512, horizon=64, dtype FP32, NPU npu:0:
first_run 0.9730s (含编译) | warmup 3 avg 0.7416s
perf_tirex.py 10 iter: first 0.7372s avg 0.7397s min 0.7317s max 0.7548s p50 0.7368s p90 0.7485s p95 0.7516s
throughput ~2.70 windows/s (batch 2 窗口) / ~1.35 series/s per sampleassets/agent_workflow.png — 完整工作流日志assets/npu_device_call.png — NPU 设备调用证据assets/model_result.png — 默认 python inference.py 的真实 NPU 推理结果三图由
scripts/render_xterm_evidence.mjs --style raw根据本次真实日志生成,深灰背景、白色等宽字体,提示符atomgit@pod-a94f8701860f4700b161b00e290de466:~$,非截图模拟。
backend="torch" 为纯 PyTorch sLSTM,无 CUDA kernel 编译,NPU 上会触发 allow_internal_format=False 的 format 提示,但不影响精度与性能context 长度需 <= train_ctx_len=2048,且为 input_patch_size=32 的倍数更优;本仓仅验证 512