liucu/ibm-granite-granite-timeseries-patchtsmixer-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-granite/granite-timeseries-patchtsmixer - Ascend NPU

#NPU

  • Model: ibm-granite/granite-timeseries-patchtsmixer (PatchTSMixerForPrediction)
  • Revision: 90dc5a88d45f032b7dceefb5d814ca2af54f2ff9
  • Task: time-series point forecasting (512 -> 96, 7 channels)
  • HF Hub: https://huggingface.co/ibm-granite/granite-timeseries-patchtsmixer

Model Introduction

PatchTSMixer (TSMixer: Lightweight MLP-Mixer Model for Multivariate Time Series Forecasting) is an MLP-Mixer-based forecaster. This IBM Granite checkpoint is pretrained on ETTh1 (7 channels: HUFL, HULL, MUFL, MULL, LUFL, LULL, OT) with context_length=512, prediction_length=96, patch_length=16, patch_stride=16, num_patches=32, d_model=48, num_layers=2, expansion_factor=3, gated_attn=True, head_aggregation=max_pool, scaling=True (StdScaler inside model), distribution_output=student_t, loss=mse, mode=common_channel. It forecasts 96 steps for all 7 variates from 512 past steps. Architecture: patch embedding -> 2 x Mixer layers (token+channel mixing) -> distribution head (loc/scale + prediction).

  • Architecture: PatchTSMixerForPrediction, 1.6 MB weights (safetensors+bin)
  • Input: past_values [batch, 512, 7] float32, optional past_observed_mask (ones)
  • Output: prediction_outputs [batch, 96, 7] float32 point forecasts + loc [B,1,7] and scale [B,1,7]

Data Contract

FieldValue
task_typeforecasting
architecture_familytime-series PatchTSMixer
loading_backendtransformers.PatchTSMixerForPrediction.from_pretrained
dtypefloat32
context_length512
prediction_length96
num_input_channels / num_targets7 / 3 (config) but outputs 7 channels
patch_length / stride / num_patches16 / 16 / 32
scalingtrue (PatchTSMixer StdScaler, loc/scale returned)
distribution_outputstudent_t (mean used)
modecommon_channel
input_shape[B, T=512, C=7]
output_shape[B, H=96, C=7] forecast
preprocessingnone external; scaler inside model on past_values
axis order[B,T,C] (no transpose)
missing handlingobserved_mask all True
validation_strategyCPU vs NPU forecast tensor compare (forecasting) atol=1e-4 rtol=1e-3

Demo input: deterministic synthetic sine-wave multisignal (seed 0): past = 0.1*randn[B,512,7] + sin(linspace 0..4π)[B,T,1] * linspace 0.2..1.0[1,1,C] . SHA256 bc4da4e77f40c4d5 for past_values.

Environment

  • Device: Ascend910_9362 (npu:0), driver 25.5.5, 2 NPUs
  • CANN: /usr/local/Ascend/cann-8.5.1
  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, numpy 1.26.4, safetensors
  • npu-smi info both NPUs OK, HBM 3108/65536 MB
  • torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)==Ascend910_9362
  • HF_ENDPOINT=https://hf-mirror.com (env proxy, no manual override)
  • Weight memory: ~1585929 bytes (~1.6 MB) local /tmp/patchtsmixer_verify

Dependencies: see requirements.txt (torch, torch_npu, transformers, safetensors, huggingface_hub, numpy).

Installation

pip install -r requirements.txt
# weights auto-download via HF mirror if /tmp/patchtsmixer_verify missing; snapshot_download with local_dir fallback

NPU Inference

Default (NPU):

python inference.py

Steps in script:

  1. Check torch.npu.is_available() on npu:0 (fail fast if not).
  2. Load same weights from local /tmp/patchtsmixer_verify (or fallback snapshot_download) via PatchTSMixerForPrediction.from_pretrained.
  3. model.to("npu:0"), assert next(model.parameters()).device == npu:0.
  4. Build deterministic past_values [2,512,7] (seed 0), move to npu:0.
  5. torch.npu.synchronize() before/after each forward; warmup compile run + 2 extra warmups.
  6. 10 timed runs, report compile time, avg/min/max/p50/p90/p95, throughput windows/s, peak NPU memory.
  7. Print input summary, output prediction_outputs [2,96,7] preview, stats, SHA256, device checks, success flag; no CPU fallback.

Real Results

From python inference.py on npu:0 batch=2:

[INFO] model_name=ibm-granite/granite-timeseries-patchtsmixer revision=90dc5a88d45f032b7dceefb5d814ca2af54f2ff9
[INFO] config context_length=512 prediction_length=96 num_input_channels=7 d_model=48 num_layers=2 patch_length=16
[INFO] past_values stats mean -0.001386 std 0.472104 min -1.181783 max 1.217511 preview ch0 first5 [0.176405, -0.010217, 0.054219, 0.080103, 0.172919]
[CHECK] first param device npu:0 output device npu:0 fallback_detected False
[RESULT] prediction_outputs shape (2, 96, 7) device npu:0 dtype torch.float32 loc [2,1,7] scale [2,1,7]
[RESULT] output preview batch0 first5 ch0 [0.104764, 0.106123, 0.079585, 0.051965, 0.022495]
[RESULT] output preview 3x3 [[0.1047 0.0180 0.0258] [0.1061 -0.0302 -0.0061] [0.0795 -0.0655 -0.0314]]
[RESULT] output stats mean -0.155916 std 0.085205 min -0.390869 max 0.106124 SHA256 6596bf9f5a26eddc
[RESULT] finite True shape_ok True
[PERF] compile/first-run 156.87 ms
[PERF] stable 10 runs avg 1.63 ms min 1.59 max 1.74 p50 1.61 p90 1.66 p95 1.70 (batch 2)
[PERF] throughput 1228.60 windows/s batch2
[PERF] npu memory allocated 1014272 bytes
[SUCCESS] NPU inference completed on npu:0

CPU reference (same seed 0): mean -0.155913 std 0.085203 preview ch0 [0.104777, 0.106134, 0.079594, 0.051973, 0.022503] . NPU mean -0.155916 difference 3.6e-05 within FP32 tolerance.

Consistency

CPU vs NPU identical weights/input/preprocess/dtype/seed (seed 0, float32):

python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/patchtsmixer_cpu2.npy --npu /tmp/patchtsmixer_npu2.npy --task regression --atol 1e-4 --rtol 1e-3
{
  "task": "regression",
  "cpu_shape": [2, 96, 7],
  "npu_shape": [2, 96, 7],
  "finite": true,
  "atol": 1e-04, "rtol": 1e-03,
  "max_abs_error": 3.623e-05,
  "mean_abs_error": 5.99e-06,
  "passed": true
}

Threshold atol=1e-4 rtol=1e-3 for FP32 PatchTSMixer (MLP-Mixer + LayerNorm). Max_abs 3.62e-05 < atol. Single-window smoke consistency (not full ETTh1 benchmark). No CPU fallback; both tensors from same prediction_outputs.

Performance

  • torch.npu.synchronize() each side, pre-warm 3, measure 10
  • compile/first-run: 156.87 ms (first graph compile, cold)
  • stable: avg 1.63 ms, min 1.59, max 1.74, p50 1.61, p90 1.66, p95 1.70 (batch 2, float32, [2,512,7]->[2,96,7])
  • Throughput 1228 windows/s (batch 2)
  • Peak NPU memory 1014272 bytes + weights 1.6 MB
  • Preprocessing not timed (synthetic generation excluded; only model forward)
  • Device npu:0 verified via first param device and output device; fallback 0

Evidence

Three PNGs rendered by scripts/render_xterm_evidence.mjs --style raw from real logs (xterm.js, dark bg, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$):

agent workflow npu device call model result

Manifest working/evidence_patchtsmixer.json maps each PNG to source log, command, exit_code, UTC time. Logs are raw stdout/stderr (ANSI stripped, tokens redacted). Images generated by xterm.js from actual logs, not simulated.

Limitations

  • Point forecast only; student_t quantiles/sampling (num_parallel_samples=100) not validated.
  • Synthetic sine data; real ETTh1 CSV not bundled (model was pretrained on ETTh1, but demo uses synthetic).
  • FP32 only; FP16/BF16 not tested.
  • Single NPU npu:0, batch 2; larger batch/context not benchmarked.
  • No fine-tuning (fit) – inference only.