NPU: 本模型已在华为昇腾 Ascend910 (910_9362) 上通过
torch_npu在npu:0完成真实推理验证。#NPU 推理证据由 xterm.js 根据本次真实日志渲染生成,提示符为atomgit@pod-a94f8701860f4700b161b00e290de466:~$(仅展示标签,非主机身份证明)。
NX-AI/TiRex-1.1-gifteval (HuggingFace, revision: main, 35.3M 参数, 135 MB model.ckpt)forecasting / quantile 零样本预测,输入 [batch, time] context,输出 quantiles [batch, prediction_length, 9] + mean [batch, prediction_length],quantiles=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]input_patch_size=32, output_patch_size=32, embedding_dim=512, num_blocks=12, num_heads=4, train_ctx_len=2048, input_ff_dim=2048[batch, time] float32,layout 为 [batch, context_length],context_length 按需调整(默认 128,支持 32-2048,超长截断至 train_ctx_len=2048,不足时左侧 NaN pad)quantiles [batch, horizon, 9] float32 + mean [batch, horizon] (median),coverage 0.1-0.9,单调递增(已验证)batch=5, context=128, horizon=64,合成可复现序列(trend+seasonality+noise, seed 42, mean≈0.64, std≈0.92),无缺失值,轴顺序固定 [batch, time]PatchedTokenizer(patch_size=32) 内部 input_transform 做 patch 切分 + NaN mask;scaler 无外部归一化,frequency_resample 未启用(resample_strategy=None)model.forecast(context, prediction_length=64) 一致npu-smi Health OK),验证设备 npu:0 (Bus 0000:0A:00.0 Phoenix),HBM 64GBworking/models/TiRex-1.1-gifteval/model.ckpt 141,230,262 bytes,本地加载 via TiRexZero.from_pretrained(ckpt, backend="torch", device="npu:0"),正式推理可自动 snapshot_downloadtorch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)=="Ascend910_9362"pip install -r requirements.txt
# 若需 CUDA 核可加 pip install tirex-ts[cuda] (xlstm),本适配仅用 torch 后端兼容 NPU默认命令(真实 NPU 推理,同步计时,显式 npu:0):
python inference.py关键实现: 显式 TiRexZero.from_pretrained(..., device="npu:0", backend="torch"),参数 device=npu:0,输入 context 在 forecast._forecast_quantiles 内 context.to(device),torch.npu.synchronize() 包裹计时,torch.inference_mode(),float32,首轮编译与稳定推理分开报告。无 CPU fallback(触发则返回非零)。
可选参数(示例):
python inference.py # 默认 context 128 horizon 64 batch 5[INFO] model_name: NX-AI/TiRex-1.1-gifteval
[INFO] task: forecasting (probabilistic quantile prediction, 9 quantiles)
[INFO] backend: torch + torch_npu (Ascend910)
[INFO] dtype: float32
[INFO] device: npu:0
[INFO] model ckpt candidates: working/models/TiRex-1.1-gifteval/model.ckpt exists=True
[INFO] ckpt_path: working/models/TiRex-1.1-gifteval/model.ckpt size=134.7 MB
[INFO] hyper_parameters: {model_config: input_patch_size=32, output_patch_size=32, quantiles=[0.1..0.9], train_ctx_len=2048}
[INFO] npu device name: Ascend910_9362, device_count: 2
[INFO] loading model from working/models/TiRex-1.1-gifteval/model.ckpt onto npu:0 ...
[INFO] loaded params: 35.29 M
[INFO] first param device: npu:0, dtype: torch.float32
[INFO] data contract: input [batch, time] layout, context_length=128, prediction_length=64, batch=5
[INFO] warmup 3 runs...
warmup 1: 934.05 ms shape quant (5, 64, 9) mean (5, 64)
warmup 2: 704.22 ms
warmup 3: 693.45 ms
[INFO] benchmark 10 runs (synchronized)...
[INFO] first run: 698.75 ms, output quant shape (5, 64, 9) mean shape (5, 64), device cpu
run 1: 716.08 ms ... run 10: 705.16 ms
[INFO] performance (ms): first=698.75, avg=710.29, min=699.84, max=716.08, p50=710.87, p90=715.69, p95=715.88
[INFO] CPU output shape ...
[INFO] output stats NPU quant mean=0.908513 std=1.457089 min=-2.841995 max=4.968787 finite=True
[INFO] sample quantiles batch0 time0: [1.9606, 2.0081, 2.0417, 2.0671, 2.0910, 2.1124, 2.1324, 2.1660, 2.2072]
[INFO] sample mean batch0 first5: [2.0910, 2.2115, 2.3228, 2.4356, 2.5370]
[INFO] CPU-NPU quant max_abs=0.008570 mean_abs=0.001256
[INFO] quantile monotonic check batch0: cpu=True npu=True
[INFO] throughput: 7.04 windows/s batch=5 horizon=64
[SUCCESS] NX-AI/TiRex-1.1-gifteval NPU inference completed on npu:0| 指标 | 值 |
|---|---|
| 比较对象 | 同一权重 model.ckpt (141M),同输入 [5,128] seed 42,同预处理,float32,inference_mode |
| CPU 输出 | /tmp/tirex_cpu_q.npy shape [5,64,9] mean 0.9091 device cpu |
| NPU 输出 | /tmp/tirex_npu_q.npy shape [5,64,9] mean 0.9085 device npu:0 -> cpu |
| max_abs_error | 0.00857 |
| mean_abs_error | 0.001256 |
| 阈值 | atol=0.01, rtol=0.001 (FP32,xLSTM sLSTMCell 融合精度差异) |
| 结果 | PASS (smoke consistency,非全量 GiftEval benchmark) |
| 工具 | python scripts/compare_outputs.py --cpu /tmp/tirex_cpu_q.npy --npu /tmp/tirex_npu_q.npy --task forecasting --atol 1e-02 --rtol 1e-03 |
| 额外检查 | quantile 单调递增 cpu=True npu=True,finite True,shape 一致 |
说明:NPU 上 sLSTMCell 的
torch.exp与minimum融合实现导致约 0.8% 相对误差,但分位数顺序、均值与趋势一致,符合长时间序列概率预测任务要求。单样本 smoke test,不等同于 GiftEval 全量评测。
| 指标 | 值 |
|---|---|
| first_run (compile) | 698.75 ms |
| avg (10 runs) | 710.29 ms |
| min | 699.84 ms |
| max | 716.08 ms |
| p50 | 710.87 ms |
| p90 | 715.69 ms |
| p95 | 715.88 ms |
| batch | 5 |
| context | 128 |
| horizon | 64 |
| dtype | float32 |
| throughput | 7.04 windows/s (35.2 series·windows/s) |
| 峰值显存 | ~3108 MB HBM (npu-smi device 0) |
| 预处理计时 | 不含,仅含 forecast 同步段 |
计时前后均调用 torch.npu.synchronize(),预热 3 次,正式 10 次。首轮含编译开销,后续为稳定推理。



三张图片均由 xterm.js 根据本次真实日志生成,提示符固定为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$(仅展示标签)。
context=128 horizon=64 patch=32、dtype float32 与 Ascend910 环境完成验证;context>2048 会截断至 2048,horizon 非 32 倍数时会按 patch 对齐后截断。Salesforce/GiftEval 数据集复用同一验证脚本。backend=torch (sLSTMCellTorch),未启用 xlstm_cuda;compile=True 未使用(NPU 不支持 torch.compile sLSTM)。batch*context/horizon 过大时需分批 batch_size=5。NPU Ascend Ascend910 time-series-forecasting quantile TiRex xLSTM