Tags: #NPU #Ascend #Ascend910 #TimeSeries #Forecasting
TiRex 是 NX-AI 团队的时序基础模型,基于 xLSTM,支持长短程零样本预测,输出分位数与均值。本仓验证上下文 128 预测 32 的时序窗口。
[batch, time] 浮点张量,形状 [B, T],当前验证 B=2, T=128 (context_length),预测长度 prediction_length=32。数据类型 float32。[batch, time],内部按 patch_size=32 切分。python inference.py 使用 torch.randn(batch=2, context=128, seed=42) 合成演示;可替换为真实 CSV 单列序列,保证 float32。trust_remote_code。pip install -r requirements.txt
# 需已安装 tirex-ts 1.4.2 (pip install -e /tmp/tirex_clone 或 pip install tirex-ts) 并配置 CANN 8.5.1 + torch_npupython inference.py
python inference.py --device npu:0 --context-length 128 --prediction-length 32 --batch-size 2
python inference.py --mode validate # CPU vs NPU 一致性
python inference.py --mode benchmark # 性能基准脚本默认完成真实 NPU 推理,固定 torch.manual_seed(42) 输入,前后调用 torch.npu.synchronize() 计时,首轮包含图编译,输出分位数形状与统计。
模型本地路径优先级: /tmp/NX-AI-TiRex > /opt/atomgit/adapt-npu-agent/workspace_npu/models/NX-AI_TiRex > ~/.cache/huggingface/hub/models--NX-AI--TiRex。联网未命中时自动 snapshot_download。
默认 python inference.py (batch=2, context=128, horizon=32, npu:0, float32) 的真实完整输出见 assets/model_result.png,文本摘要:
[INFO] Model: NX-AI/TiRex
[INFO] Task: time-series forecasting (probabilistic, 9 quantiles, horizon 32)
[INFO] Architecture: TiRexZero 35M, xLSTM, input_patch 32, quantiles [0.1-0.9], train_ctx 2048
[INFO] Loading backend: torch (pure sLSTM), device=npu:0
[INFO] Dtype: torch.float32, Batch: 2, Context: 128, Horizon: 32
[INFO] torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04
[INFO] NPU available: True, count: 2, name: Ascend910_9362
[INFO] Model dir: /tmp/NX-AI-TiRex
Loading weights from local directory
[INFO] Param device: npu:0, dtype: torch.float32
[INPUT] shape [2, 128], dtype torch.float32, device cpu, seed 42
[INPUT] stats min -2.5095 max 2.2181 mean 0.0630 std 0.9888
[INPUT] first series first 5: [1.9269, 1.4872, 0.9007, -2.1055, 0.6784]
[OUTPUT] quantiles shape [2, 32, 9], mean shape [2, 32], dtype torch.float32, device cpu
[OUTPUT] latency 613.23 ms (synchronized)
[OUTPUT] quantiles stats min -1.4445 max 1.5814 mean 0.1594 std 0.7490
[OUTPUT] mean stats min -0.0811 max 0.3989 mean 0.1723 std 0.1384
[OUTPUT] quantiles[0,0,:] [-0.6333, -0.2771, -0.0354, 0.1728, 0.3465, 0.5145, 0.7038, 0.9389, 1.2821]
[OUTPUT] quantiles[0,1,:] [-0.7086, -0.2948, 0.0044, 0.2193, 0.3988, 0.5792, 0.7737, 1.0183, 1.3401]
[OUTPUT] mean[0,:5] [0.3465, 0.3988, 0.3647, 0.2675, 0.2306]
[OUTPUT] quantile monotonic: True
[OUTPUT] param device check: npu:0, input device after forecast (quantiles): cpu
[SUCCESS] Inference completed on npu:0, latency 613.23 ms[2,128],seed 42,统计与首 5 值如上。quantiles [2,32,9] 9分位 (0.1-0.9),mean [2,32] (median 分位重合),有限值,已校验分位单调性。npu:0, torch_npu 可用, 2 设备 Ascend910_9362。/tmp/NX-AI-TiRex/model.ckpt SHA256 c28e2bcdd22503daa0f3eb197fce3c82)、输入 (seed 42, batch 2, context 128, horizon 32)、预处理、dtype float32、eval mode 下的 CPU 与 NPU quantiles 张量 [2,32,9] float32。python scripts/compare_outputs.py --cpu cpu_quantiles.npy --npu npu_quantiles.npy --task forecasting --atol 5e-3 --rtol 1e-3max_abs_error 0.001407 mean 0.000452 passed true (阈值 atol 5e-3 rtol 1e-3, FP32)。单调性 (axis -1) CPU True / NPU True。无 CPU fallback,均为真实设备输出,torch.npu.synchronize() 计时。quantile 模式 (轴 -1 正确检查) 亦通过,compare_outputs.py 旧版错误地在 -2 轴检查但 forecasting 模式验证数值一致性已足够;分位单调性在 inference.py 中独立校验。torch.npu.synchronize() 前后计时forecast 同步,不含 CSV 读取/随机数生成;batch 与 horizon 线性影响 latency。三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成 (深灰背景、白色等宽字体、固定提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$),非手工绘制:
assets/agent_workflow.png: 侦察、数据检查、下载、加载、NPU 推理、一致性、benchmark 与校验assets/npu_device_call.png: npu-smi、NPU 可用性、设备名、模型参数 device/dtype、输入与输出 Tensor deviceassets/model_result.png: 默认 python inference.py 的真实完整输出、同步耗时与状态

allow_internal_format=False 警告为 NPU 兼容提示,不影响结果。tirex.onnx 存在但未用于本 NPU torch 路径。