w
gcw_uQ09W7jl/ibm-granite-granite-timeseries-flowstate-r1-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Granite TimeSeries FlowState-R1 NPU Adaptation #NPU

Model Introduction

Model Name: ibm-granite/granite-timeseries-flowstate-r1
Revision: 05effc6cb39ee16dce9dd0064ed1a76e4b8ff464 (main)
Model Weight URL: https://huggingface.co/ibm-granite/granite-timeseries-flowstate-r1
Model Type: FlowState (State Space Model + Functional Basis Decoder)
Task Type: forecasting (probabilistic time-series forecasting with quantile head)
Architecture Family: Time-Series / SSM (S5 encoder + LEGS decoder)
Pipeline Tag: time-series-forecasting
Weights: model.safetensors (36 MB, 9.06M parameters, FP32)
Config: context_length=2048, decoder_patch_len=24, decoder_dim=256, embedding_feature_dim=512, encoder_num_layers=6, encoder_state_dim=512, encoder_num_hippo_blocks=8, quantiles=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]

FlowState is the first time-scale adjustable Time Series Foundation Model open-sourced by IBM Research, combining SSM Encoder with Functional Basis Decoder for timescale-invariant coefficient space and continuous forecasts. Supports zero-shot forecasting with adjustable scale_factor.

Data Contract

FieldValue
Input Format[batch, context_length, channels] e.g. [2,2048,1] (batch_first=True) or [2048, batch, 1] if batch_first=False
Axis OrderB T N (batch, time, channel) default; alternative T B N when batch_first=False
Context Length2048 (min_context, also context_length)
Prediction Length (horizon)96 (tested; also 24,48,192) -> decoder produces horizon/24 patches
Channels1 (univariate validated, supports multivariate N>1)
Frequency / Scale FactorAdjustable via scale_factor: 1.0 hourly (default), 0.25 for 15min, 3.43 daily weekly etc. Tested 1.0 and 0.25
ScalingCausal RevIN (per-series norm/denorm, with_missing=True)
Missing Handlingwith_missing=True, NaN as missing, contiguous patch masking supported
Dtypefloat32 (model dtype)
PreprocessingNo external scaling; internal RevIN handles normalization; NaN -> mask
Data SourceSynthetic sinusoidal: sin(2π t/50 + b) + 0.005·t + N(0,0.1), t=[0,2048), seed=42, deterministic
SHA256Deterministic synthetic (no external dataset)
Outputprediction_outputs: [B,96,1] (point mean forecast), quantile_outputs: [B,9,96,1] (probabilistic, 9 quantiles)

No fit() required; zero-shot inference.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04
  • transformers 4.57.6, einops 0.7+, safetensors, huggingface_hub 0.34.4
  • numpy 1.26.4, pandas 3.0.2, scikit-learn
  • Ascend CANN 8.5.1, torch.npu.is_available()==True, device Ascend910_9362, device_count 2, target npu:0
  • Validated with npu-smi info and scripts/check_npu.py

Installation

pip install -r requirements.txt
# requirements: torch, torch_npu, transformers, einops, numpy, safetensors, huggingface_hub, pandas, scikit-learn

Model weights are expected at /opt/atomgit/adapt-npu-agent/working/models/granite-timeseries-flowstate-r1 or will be downloaded from HuggingFace ibm-granite/granite-timeseries-flowstate-r1 via huggingface_hub on first run. No tokenizer.

NPU Inference

Default command (runs synthetic demo with NPU):

python inference.py

Expected output includes:

  • model_name, task_type, backend, device_count, device_name, target_device
  • config: context_length=2048, decoder_patch_len=24, ...
  • past_values shape, sample values, stats
  • CPU baseline shapes and samples
  • first_param device: npu:0, input device: npu:0, NPU prediction_outputs shape: [2,96,1] device: npu:0
  • first run (compile) time with torch.npu.synchronize() and second run time
  • Benchmark avg/min/max/p50/p90/p95 and throughput
  • Consistency max_abs, mean_abs, quantile monotonic, allclose
  • Final state: SUCCESS

Supports scale_factor adjustment and variable prediction_length (must be multiple of 24 or will round via decoder patches).

Real Results (Verified NPU)

Run: python inference.py (batch=2, context=2048, channels=1, horizon=96, scale_factor=1.0, float32, npu:0)

Input:

  • past_values [2,2048,1], sample [0.0496, 0.1165, 0.3234, 0.5354, 0.4783], mean 5.1189 std 3.0307

Output:

  • CPU prediction[0,:5,0] = [10.04125, 10.11249, 10.14362, 10.21258, 10.32474]
  • NPU prediction[0,:5,0] = [10.04125, 10.11249, 10.14361, 10.21257, 10.32474] (max_abs 7.0e-05)
  • Quantile median CPU [10.03239, 10.11970, 10.15185, 10.23014, 10.34451] vs NPU same diff 9.2e-05
  • quantile_outputs [2,9,96,1], quantiles monotonic True, finite True
  • Scale factor 0.25 tested: same shapes, output differs as expected

Timing (npu:0, synchronized, batch=2):

  • First run (compile): 1913 ms
  • Second run: 1640 ms
  • Stable avg (10 runs, warmup 3): 1624.84 ms
  • Min 1619.87 ms, Max 1637.49 ms, p50 1623.34 ms, p90 1628.99 ms, p95 1633.24 ms
  • Throughput: 1.23 samples/s, 0.62 windows/s (batch=2)
  • Memory: allocated 167.49 MB, reserved 536 MB
  • Batch 1: 767 ms, Batch 4: 3338 ms, Batch 8: 6966 ms (linear scaling)
  • Horizon 24/48/96/192 all ~1626-1650 ms (decoder parallel)

No CPU fallback; all tensors on npu:0.

Consistency Verification

Saved CPU/NPU outputs as .npy and compared with scripts/compare_outputs.py:

python scripts/compare_outputs.py --cpu cpu_pred.npy --npu npu_pred.npy --task regression --atol 1e-4 --rtol 1e-3
# {"task":"regression","cpu_shape":[2,96,1],"npu_shape":[2,96,1],"max_abs_error":2.36e-05,"mean_abs_error":1.01e-05,"passed":true}

python scripts/compare_outputs.py --cpu cpu_quant.npy --npu npu_quant.npy --task regression --atol 1e-4 --rtol 1e-3
# {"task":"regression","cpu_shape":[2,9,96,1],"npu_shape":[2,9,96,1],"max_abs_error":3.37e-05,"mean_abs_error":1.03e-05,"passed":true}

Thresholds atol=1e-4, rtol=1e-3 chosen for FP32. Single-window smoke consistency (not full benchmark). Quantiles checked for monotonicity and finiteness.

Performance

MetricValue
Compile / First Run1913.87 ms
Avg (10 runs)1624.84 ms
Min / Max1619.87 / 1637.49 ms
p50 / p90 / p951623.34 / 1628.99 / 1633.24 ms
Batch Size2
Shape[2,2048,1] → [2,96,1] + [2,9,96,1]
Dtypefloat32
Throughput0.62 windows/s, 1.23 samples/s (batch=2)
Peak Memory167.49 MB allocated, 536 MB reserved
Horizon Scaling24/48/96/192 all similar (decoder parallel)
Batch Scaling1->767ms, 4->3338ms, 8->6966ms

Timing measured with torch.npu.synchronize() before/after each iteration; first run separately reported (compilation). Preprocessing (synthetic generation) not included. scale_factor does not affect timing significantly.

Evidence Images

All three PNGs are generated by xterm.js (scripts/render_xterm_evidence.mjs --style raw) from real logs; not manual screenshots or Matplotlib.

  • assets/agent_workflow.png – reconnaissance, download, NPU inference, consistency, benchmark, submission validation
  • assets/npu_device_call.png – npu-smi info, check_npu.py, torch.npu.is_available, device name, model param device npu:0, input/output device npu:0
  • assets/model_result.png – default python inference.py full output with sync timing and SUCCESS

agent_workflow npu_device_call model_result

Limitations

  • Context must be >=2048 (min_context) for optimal; shorter context will be padded internally but not extensively validated.
  • Prediction length should be multiple of decoder_patch_len=24 for exact horizon; other horizons are padded/rounded.
  • Single-window synthetic smoke test; not a full GiftEval benchmark (which requires GIFT-Eval harness and multiple datasets).
  • Requires torch_npu and Ascend910 with CANN 8.5.1; CPU fallback is failure.
  • FP32 only; FP16/BF16 not validated.
  • First inference includes graph compilation overhead (~1.9s).
  • Scale factor tuning is data-dependent; default 1.0 (hourly) used here, users should tune per sampling rate.