liucu/NX-AI-TiRex-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

NX-AI/TiRex NPU - Ascend 910B Time-Series Forecasting

#NPU Ascend 910B Ascend910 TiRex time-series-forecasting probabilistic

Model: NX-AI/TiRex (TiRexZero) - 35M parameter zero-shot forecasting based on xLSTM, 12 sLSTM blocks, embedding 512, patch 32. Revision: local download 2026-08-20 from https://huggingface.co/NX-AI/TiRex - ckpt 141,230,262 bytes, onnx 136MB. Provided via huggingface_hub snapshot_download, loaded from local /opt/atomgit/adapt-npu-agent/working/models/TiRex/model.ckpt with backend=torch, device=npu:0.

Task

Probabilistic time-series forecasting: given univariate context [B, T] -> quantiles [B, horizon, 9] + mean [B, horizon] (median as point estimate). Quantiles = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]. Uses internal PatchedTokenizer instance norm, no external scaler. No training/fit required - zero-shot inference only.

Data Contract

Source: /opt/atomgit/adapt-npu-agent/working/input.csv (real market 5-min K-line, SHA256 aa5efe0121b7cc098db1a169ed38f9878681ef14a93c85d54a618fd073048899, 2500 rows, 147854 bytes). Schema: columns [timestamps(str), open(float64), high(float64), low(float64), close(float64), volume(float64), amount(float64)], no missing, duplicate_rows 0. Time column: timestamps (string, 5-min interval, naive timezone, sorted), e.g. 2024-06-18 11:15:00 -> 2024-07-03. Target: close (156 unique, float64) univariate. Also OHLCVA available but TiRex univariate -> only close used for this demo; multi-series by stacking [B,T]. Axis order: [B, T] = [1, 512] for this run, dtype float32, device npu:0 for compute, output moved to cpu by model API (output_device=cpu default). Preprocessing: pandas read_csv, slice first 512 as context, no external scaling; tokenizer handles NaN padding and instance norm internally; no categoricals; missing filled with nan_mask_value 0 after tokenizer. Context length: 512, horizon (prediction_length): 32, max_context_length: 2016, train_ctx_len: 2048, patch 32. Validation strategy: smoke consistency on single window (512->32) CPU vs NPU same seed, weight, input; full benchmark not claimed.

Environment

Ascend 910_9362 (Ascend910), CANN 8.5.1, 2 devices (4->0,4->1), npu-smi 25.5.5. Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, tirex-ts 1.4.2, transformers 4.57.6, pandas 3.0.2, numpy 1.26.4. Device: npu:0 (explicit), fallback cpu if npu unavailable. Memory budget: weight 135MB, peak alloc 275.9MB within 64GB HBM.

Installation

pip install -r requirements.txt
# torch-npu must match CANN; on Ascend use: pip install torch-npu==2.9.0.post1 -f https://repo.ascend.gitcode.com
pip install tirex-ts==1.4.2 pandas numpy scikit-learn huggingface-hub

Model Download (local load first)

Weights downloaded once via huggingface_hub snapshot_download (HF_ENDPOINT=https://hf-mirror.com):

from huggingface_hub import snapshot_download
snapshot_download(repo_id="NX-AI/TiRex", local_dir="./working/models/TiRex")
# or single file
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="NX-AI/TiRex", filename="model.ckpt")

inference.py first checks /opt/atomgit/adapt-npu-agent/working/models/TiRex/model.ckpt, then local relative, then HF cache; no implicit net download during NPU inference if local exists.

NPU Inference

Default command (real NPU synchronized):

python inference.py

Behavior: resolves ckpt, loads TiRexZero.from_pretrained(ckpt, backend=torch, device=npu:0), prints param device/dtype/horizon, reads CSV 512 context, moves input to npu:0, calls model.forecast(context=t_npu, prediction_length=32) with torch.npu.synchronize() before/after, reports time, shape [1,32,9] quantiles / [1,32] mean, finite/monotonic checks, previews median/q10/q90, benchmarks 10 runs after 3 warmup, prints throughput and memory, saves /tmp/tirex_quantiles.npy. Output device is cpu (model returns cpu by design via output_device param) but compute is on npu:0 (verified via param device npu:0 and input device npu:0, CPU fallback not triggered).

Real Results (single run, npu:0)

  • First-run synchronized: 0.5897s (includes xLSTM compile), stable avg 0.3887s (bench log) / 0.3524s (isolated bench)
  • Output quantiles [1,32,9] float32 finite true, monotonic true
  • Preview step1: median 10.9288 mean 10.9288 q10 10.9115 q90 10.9468
  • step2: median 10.9295 q10 10.9043 q90 10.9556
  • step3: median 10.9298 q90 10.9623
  • Forecast mean 10.9407 std 0.0110, quantiles mean 10.9419
  • Device evidence: param device npu:0, input device npu:0, output cpu (by API), npu_available True, Ascend910_9362

Consistency

CPU vs NPU same weight, input, seed, dtype float32, eval mode:

  • quantiles [1,32,9] max_abs 0.0002365 mean_abs 0.0001003
  • mean [1,32] max_abs 0.0001516 mean_abs 0.000089 Threshold atol 1e-3 rtol 1e-3 (FP32) passed via scripts/compare_outputs.py task regression. Output is smoke consistency on single window, not full dataset benchmark. No CPU fallback (param still npu:0).

Performance (npu:0, single window 512->32, FP32, batch 1)

  • First run (compile): ~0.60s
  • Warmup 3, test 10: avg 0.3524s (isolated) / 0.3887s (inference.py bench), min 0.2847s max 0.4014s p50 0.3677s p90 0.3971s p95 0.3992s
  • Throughput: 2.84 windows/s, 90.82 steps/s
  • Memory allocated 138.4 MB, peak 275.9 MB, dtype float32, shape [1,512]->[1,32,9]
  • Saturated: no torch.compile, backend torch, allow_internal_format False warning is benign.

Evidence

Three PNGs rendered by xterm.js from real logs (prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$), style raw, deep gray background:

  • assets/agent_workflow.png : full workflow steps (env, download, inspect, NPU adapt, consistency, validate)
  • assets/npu_device_call.png : npu-smi + check_npu + param device npu:0 + input npu:0 + sync time
  • assets/model_result.png : python inference.py full output with forecast preview and SUCCESS Generated via: node scripts/render_xterm_evidence.mjs --manifest evidence.json --output-dir submission/assets --style raw

agent workflow npu device call model result

Limitations

  • Univariate only (close), multivariate must be looped or tiled per series; no channel cross-attention.
  • Context clipped to train_ctx_len 2048; longer series truncated to last 2016.
  • Prediction_length must be multiple of patch 32 internally rounded up; non-multiples trimmed.
  • Output is always float32 even if input float64; internal instance norm only.
  • NPU output returned to cpu by design; verify param device npu:0 to confirm NPU compute, not just npu-smi.
  • No quantization/ONNX acceleration in this path (tirex.onnx not used); custom sLSTM kernels require GPU, NPU uses torch fallback.
  • Smoke test only on one 512 window; full GiftEval/Chronos-ZS needs separate eval harness.

License

NXAI Community License (see original model LICENSE) - same as https://huggingface.co/NX-AI/TiRex/blob/main/LICENSE