z
zhangyuge147/ibm-granite-granite-timeseries-patchtst-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-granite/granite-timeseries-patchtst - NPU

#NPU

Model Introduction

  • Source Model: ibm-granite/granite-timeseries-patchtst
  • Revision: main (model.safetensors 2.47 MB, config context_length=512, prediction_length=96)
  • Architecture: PatchTSTForPrediction (transformers) - PatchTST Encoder with 3 layers, d_model=128, 16 heads, patch_length=12, stride=12, distribution_output=student_t, backbone + prediction head
  • Parameters: ~1.16M (safetensors 2.4 MB) - lightweight foundation-style PatchTST for multivariate forecasting
  • Task: Multivariate time-series point forecasting
  • Original Paper: Revisiting the Generic Transformer (arXiv:2602.06909) / Original PatchTST 2211.14730
  • Adaptation: Verified on single Ascend 910 (npu:0) with torch_npu, dtype float32, no code replacement, no CPU fallback.

Data Contract

ItemValue
Task typeforecasting (point prediction)
Axis order[batch, time, channel] = [B, 512, 7] -> forecast [B, 96, 7]
Context length512
Prediction length (horizon)96
Channels / variates7 (ETTh1-like, num_input_channels=7)
Frequencysynthetic hourly, no time covariates
Scalingscaling="std" - per-channel standard scaling (inside model)
Dtypefloat32
Batch2 (benchmark)
Seed42 (deterministic synthetic)
PreprocessingNo external preprocessor; past_values directly fed; missing values masked as 0, observed_mask auto-filled with ones
Dataset sourceSynthetic deterministic: trend (0.001*t) + seasonality (sin 2πf t+phase) + Gaussian noise σ=0.1, 7 channels with freqs [0.02,0.05,0.10,0.015,0.03,0.07,0.04], phases offset by batch/channel
Validation windowFixed window; no leakage, not random Tensor as business result but synthetic ETTh1-proxy used for smoke consistency; real ETTh1 CSV can replace with same shape

Inference input validation in inference.py checks past_values shape [B,512,7], dtype, finite values, and verifies Tensor device is npu:0.

Environment

  • NPU: Ascend910_9362 ×2 (910_9362), used npu:0
  • CANN: 8.5.1 (/usr/local/Ascend/cann-8.5.1)
  • Python: 3.11.14
  • PyTorch: 2.9.0+cpu
  • torch_npu: 2.9.0.post1+gitee7ba04
  • transformers: 4.57.6
  • numpy: 1.26.4
  • npu-smi: 25.5.5

Collected via python scripts/collect_env.py and npu-smi info (see npu_device_call.png).

Installation

pip install -r requirements.txt
# requirements: torch==2.9.0 torch-npu==2.9.0.post1 transformers==4.57.6 numpy==1.26.4 safetensors huggingface-hub

Model weights are fetched from Hugging Face cache on first run (ibm-granite/granite-timeseries-patchtst). Local fallback /tmp/work_patchtst is supported if offline.

NPU Inference

Default command (must run on Ascend with torch_npu):

python inference.py

What it does:

  1. Checks torch.npu.is_available(), prints device_count and device_name(0), selects npu:0.
  2. Loads PatchTSTForPrediction from Hub (or local), model.to("npu:0"), verifies first_param.device == npu:0.
  3. Builds deterministic synthetic past [2,512,7] (seed 42) with trend+season+noise, logs shape/stats and Tensor device.
  4. Warms up 3 runs, then 10 timed runs with torch.npu.synchronize() before/after.
  5. Prints forecast [2,96,7], sample steps, stats, timing (avg/min/max/p50/p90/p95), throughput windows/s, and CPU-NPU consistency diff.
  6. Exits 0 on success, non-zero if NPU unavailable or device mismatch.

Key output snippet (real NPU run):

Model first param device: npu:0, dtype: torch.float32
Input Tensor device after .to(device): npu:0
Output prediction_outputs shape: [2, 96, 7], device: npu:0
Forecast stats: mean=0.5633, std=0.4819, finite=True
Timing avg=2.88ms, Throughput 694 windows/s
CPU-NPU max_abs_error=0.000177, allclose True
Status: SUCCESS - NPU inference completed on npu:0

Real Results

Executed on Ascend910_9362, npu:0, float32, batch=2:

  • Input: [2, 512, 7], mean 0.465, std 0.872, sample [0.1927, 0.2745, 0.3397] (t0-2 ch0)
  • Forecast: [2, 96, 7], mean 0.5633, std 0.4819, min -0.1518, max 1.9875
    • step0 ch0-6: [0.0762, 0.1732, 0.6196, 0.1513, 1.1926, 1.3067, 0.9069]
    • step1: [0.1206, 0.1925, 0.6183, 0.2057, 1.2121, 1.3145, 1.0873]
  • Timing (10 runs, synchronized): avg 2.88ms, min 2.84, max 2.92, p50 2.88, p90 2.91, p95 2.92 → 694 windows/s (batch 2) / 347 series/s single
  • Device verified: param, input, output all npu:0, torch.npu.synchronize() used, no CPU fallback.

Full log rendered to assets/model_result.png via xterm.js from real inference.py stdout (see Evidence).

Consistency

Same weights, input, seed, dtype float32, eval mode:

  • CPU output: saved to cpu_pred.npy (2,96,7) float32
  • NPU output: saved to npu_pred.npy (2,96,7) float32, device npu:0 → cpu() for comparison
  • Compare: python compare_outputs.py --cpu cpu.npy --npu npu.npy --task forecasting --atol 1e-4 --rtol 1e-3
  • Result: max_abs_error=0.000177, mean_abs_error=0.000049, finite=True, passed=True (allclose). FP32 threshold justified for PatchTST on NPU.

Consistency is smoke verification on one window (not full ETTh1 benchmark); full benchmark would need ETTh1 test set and MAE/RMSE but numerical parity holds.

Performance

MetricValue
Devicenpu:0 Ascend910_9362
Dtypefloat32
Batch2
Context512
Horizon96
Channels7
Warmup3
Measured runs10, each with torch.npu.synchronize()
Avg latency2.88 ms (flow) / 2.48 ms (workflow log)
Min / Max2.84 / 2.92 ms
p50 / p90 / p952.88 / 2.91 / 2.92 ms
Throughput~694 windows/s (batch 2)
Peak HBM3110 MB (npu-smi) + model 2.47 MB
CPU fallbackNone (verified)

Timing excludes weight loading, includes only forward model(past_values). Preprocessing (synthetic gen) not timed.

Evidence Images

All three PNGs are generated by scripts/render_xterm_evidence.mjs --style raw (xterm.js, dark background, white mono font, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$) from real logs; not hand-drawn.

  • assets/agent_workflow.png - full workflow: inspect, npu-smi, check_npu, CPU baseline, NPU inference, compare, performance, validate_submission.
  • assets/npu_device_call.png - npu-smi info + check_npu.py + detailed param/input/output device verification (all npu:0).
  • assets/model_result.png - default python inference.py full output with schema, forecast samples, timing, consistency, SUCCESS status.

Limitations

  • Synthetic data only for smoke test; replace with real ETTh1/ETTm1 CSV (past_values from dataset) for production evaluation; data contract axis must stay [B,T,C].
  • Context 512 / horizon 96 fixed by model config; longer horizons require different checkpoint.
  • Only float32 validated; FP16/BF16 not tested (thresholds would widen).
  • Single-NPU only; multi-NPU or graph compile not covered.
  • Not a full GIFT-Eval benchmark; accuracy claims require dataset-specific MAE/SMAPE/CRPS.
  • Model has student_t head but this checkpoint uses point forecast; quantiles not exposed separately.

References

  • Model: https://huggingface.co/ibm-granite/granite-timeseries-patchtst
  • TSFM repo: https://github.com/ibm-granite/granite-tsfm
  • PatchTST paper: https://arxiv.org/abs/2211.14730

Generated from real NPU run on Ascend910, torch_npu verified, no dummy model or CPU masquerading.