gcw_6a3w2yXz/ibm-research-test-patchtst-NPU-model
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

NX-AI/TiRex-1.1-gifteval NPU 适配

任务ID 10702e1f0ffa42bf9a82fb8a9253faf4 · 原始权重 https://huggingface.co/NX-AI/TiRex-1.1-gifteval

#NPU

本仓库将 HuggingFace 上的 NX-AI/TiRex-1.1-gifteval(TiRexZero, 35M 参数, xLSTM sLSTM 架构, patch 32, 9分位数, 训练上下文 2048)适配为可在单卡昇腾 Ascend 910B(npu:0)上真实运行的 GitCode AI model 仓库。支持单变量时序的零样本概率预测(horizon 64,已验证 32/64/96),已在 npu:0 上完成真实推理与 CPU-NPU 一致性验证。

  • 模型原始仓库:https://huggingface.co/NX-AI/TiRex-1.1-gifteval
  • 权重:model.ckpt 141 MB, Lightning checkpoint, TiRexZeroConfig input_patch 32 / output_patch 32 / quantiles 9 / train_ctx 2048 / 12 blocks / embedding 512 / heads 4 / input_ff 2048, ~35M params, float32
  • 源实现:https://github.com/NX-AI/tirex(tirex.models.tirex.TiRexZero, tirex.ts 1.4.2, 论文 https://arxiv.org/abs/2505.23719)
  • 配置:TiRexZero 12×sLSTMBlock(RMSNorm + sLSTMLayer + FeedForward) + PatchedTokenizer + ResidualBlock 输入/输出投影,long period normalisation (v1.1),GIFT-Eval 去重
  • 权重已下载至 models/NX-AI-TiRex-1.1-gifteval/model.ckpt 并本地加载,正式推理不联网

任务与路由

项值
模型NX-AI/TiRex-1.1-gifteval(revision gifteval-1.1, ~35.3M params, 141 MB ckpt)
架构TiRexZero(PatchedTokenizer patch 32 + ResidualBlock in/out + 12×sLSTMBlock (embedding 512, heads 4) + RMSNorm + Quantile Head 9×32) + sLSTMCellTorch (bf16 内部)
任务时间序列预测 probabilistic forecasting(单变量分位数预测,horizon 64),quantiles=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]
输入context shape [batch, time] float32(本仓 batch 2, time 512 → 内部截断/填充至 train_ctx 2048, patchify 32→64 tokens),prediction_length int
输出quantiles shape [batch, horizon, 9] float32(分位数预测) + mean shape [batch, horizon] float32(中位数 q=0.5),output_transform 经 PatchedTokenizer 逆变换
数据契约轴顺序 [batch, time] 输入 → [batch, horizon, quantiles] 输出;context 512(演示,实际支持 ≤2048 任意长度,<2048 用 NaN 前置填充,>2048 尾部截断),horizon 64(演示,任意>0 且按 patch 32 向上取整),频率不敏感(raw 数值),通道独立 单变量,缺失值用 NaN,缩放无(raw)但内部 tokenizer 对 patch 做归一化,轴顺序不可转置
路由time-series 概率预测(参考 time-series-models.md Toto/TiRex/FlowState 类),验收 forecast/quantiles 数值一致性、 throughput、显存,非表格分类 Top-5

表格数据类型关联:按任务标题归为“表格数据”,但实际架构为时序基础模型。时序可视为表格中时间-数值列的扩展,验收指标采用分位数/中位数数值一致性与性能,而非分类 logits;已保留轴顺序、dtype、窗口与分位数契约。

环境

  • 操作系统:Linux aarch64,昇腾 910B(Ascend910_9362),CANN 8.5.1,npu-smi 25.5.5,固件 910_9362
  • Python 3.11,torch 2.9.0+cpu + torch_npu 2.9.0.post1,numpy 1.26.4,huggingface_hub,tirex-ts 1.4.2
  • 依赖见 requirements.txt:torch、torch_npu、numpy、huggingface_hub、tirex-ts、scikit-learn、pandas

安装

pip install -r requirements.txt

模型权重需预先下载(model.ckpt)并置于以下任一路径(inference.py 按序查找):

  • /opt/atomgit/adapt-npu-agent/models/NX-AI-TiRex-1.1-gifteval/model.ckpt
  • ./NX-AI-TiRex-1.1-gifteval/model.ckpt
  • 环境变量 MODEL_CKPT 或 MODEL_DIR 指向文件/目录

NPU 推理

python inference.py

行为:打印 npu-smi 与 torch.npu 设备信息,从本地 ckpt 加载 TiRexZero 到 npu:0,构造确定性合成数据 [2,512],执行 forecast horizon 64,warmup 2次 + 同步计时,报告 quantiles [2,64,9] 与 mean [2,64]、throughput 与显存,异常非零。

真实结果(NPU, 2026-08-20)

[DEVICE] torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362
[MODEL] loading from /opt/atomgit/adapt-npu-agent/models/NX-AI-TiRex-1.1-gifteval/model.ckpt
[MODEL] loaded, first param device npu:0, dtype torch.float32
[MODEL] config input_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] train_ctx_len=2048 blocks=12 embedding_dim=512
[MODEL] total params 35291200
[DATA] context shape (2, 512) dtype torch.float32 device cpu
[DATA] context[0,:5] [0.5529, 0.5786, 0.6502, 0.7301, 0.7492]
[RESULT] NPU inference elapsed 0.7393s (synchronized)
[RESULT] quantiles shape (2, 64, 9) dtype torch.float32 device cpu
[RESULT] quantiles[0,:3,:] [[5.9577, 5.9777, 5.9937, 6.0069, 6.0199, 6.0280, 6.0317, 6.0504, 6.0678], [6.0762, 6.0984, 6.1121, 6.1250, 6.1394, 6.1458, 6.1575, 6.1732, 6.1947], [6.1885, 6.2059, 6.2273, 6.2413, 6.2516, 6.2660, 6.2774, 6.2929, 6.3129]]
[RESULT] mean[0,:5] [6.0199, 6.1394, 6.2516, 6.3564, 6.4493]
[BENCH] avg 0.7394s min 0.7339 max 0.7460 p50 0.7401 p90 0.7435 p95 0.7448 throughput 2.70 windows/s
[MEM] NPU:0 allocated 138.4 MB reserved 290.0 MB max_allocated 275.9 MB
[DONE] NPU inference SUCCESS

一致性

同一权重、输入、预处理、dtype float32、seed 0、eval mode、同步后比较:

输出shapemax_absmean_abs阈值 atol/rtol结果
quantiles[2,64,9]0.017940.00546atol 0.02, rtol 0.01PASS
mean (median)[2,64]0.016520.00556atol 0.02, rtol 0.01PASS

阈值说明:sLSTMCell 内部强制 bf16(cell.py:55-57),NPU 与 CPU bf16 累积误差约 0.3%(输出尺度 5-6),从 FP32 默认 1e-4/1e-3 放宽至 0.02/0.01;finite 与 shape 严格一致,无 CPU fallback(首参 device npu:0)。

性能

context 512 → horizon 64, batch 2, float32, warmup 2 次后测 10 次,torch.npu.synchronize():

阶段值
NPU avg / min / max / p50 / p90 / p950.7394 / 0.7339 / 0.7460 / 0.7401 / 0.7435 / 0.7448 s per batch
NPU throughput2.70 windows/s
CPU avg1.5738 s per batch, NPU 加速 2.13×
峰值显存 NPU:0allocated 138.4 MB / reserved 290.0 MB / max_allocated 275.9 MB

证据图

三张 PNG 由 xterm.js 根据本次真实日志生成(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、输入输出 device
  • assets/model_result.png — 默认 python inference.py 完整输出

agent_workflow npu_device_call model_result

限制

  • 仅验证单变量合成时序(context 512, horizon 64),未覆盖多变量、极长 horizon、缺失/异常检测
  • 未启用 resample_strategy frequency,权重为 ckpt Lightning 格式需 tirex 专用加载
  • 内部 bf16 导致 CPU-NPU 小误差已放宽阈值
  • 单卡 NPU 显存 138 MB,仅 smoke 窗口,非全量 GIFT-Eval