Bingggooo/ibm-granite-granite-timeseries-ttm-r2-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-granite/granite-timeseries-ttm-r2 NPU Adaptation #NPU

Model Overview

ibm-granite/granite-timeseries-ttm-r2 is a TinyTimeMixer (TTM) foundation model for multivariate time-series forecasting, released by IBM Research (NeurIPS'24). This is the R2 release trained on ~700M samples, 1M parameters (805k in this checkpoint) with 2 mixer layers, d_model 192, patch length 64, stride 64, 8 patches for context 512. Supports point forecasting; probabilistic via student-t head (distribution_output: student_t) but default is point forecast.

  • Model weight URL: https://huggingface.co/ibm-granite/granite-timeseries-ttm-r2
  • Architecture: TinyTimeMixerForPrediction (TinyTimeMixerConfig, TTMv2), 2 layers, adaptive patching 3 levels, FCM mixer 3 layers
  • Task: Time-series forecasting – point prediction (forecast tensor) – univariate and multivariate channel-independent
  • Revision: d6a79570cac0f33d526601cd3a0fc7c80a8f9a2f (local snapshot 2026-08-20)
  • License: apache-2.0
  • Precision: FP32 (torch_dtype float32), FP16/BF16 stable on NPU but validated FP32
  • Context: 512, Horizon: 96 (this checkpoint) – TTM provides family of context/horizon variants; r2 supports 512/96, 1024/96, etc.
  • Weight size: 3.1 MB safetensors (805k params) + training_args.bin 4.9K, 3.2 MB total
  • Source code: https://github.com/ibm-granite/granite-tsfm (tsfm_public.models.tinytimemixer)

Data Contract

  • Input source: Synthetic univariate series with fixed seed 0, deterministic generation 0.5*sin(2πt/24)+0.3*sin(2πt/96)+0.01*t+N(0,0.1). Total 608 timesteps, context 512, horizon 96. SHA256 prefix of raw context 9e1e6faa02e6, mean 2.570732 std 1.523962.
  • Rows/Batch: batch=1, time=512 lookback, channel=1. For time-series contract: [batch, time, channel] = [1,512,1] float32. Future ground truth 96 steps held out for reference but not fed.
  • Axis order: [batch, time, channel] – TTM expects 3D past_values; [B,C,T] would be wrong. Channel is last.
  • Time contract: ascending order, no duplicate timestamps, no missing steps, synthetic frequency placeholder 5min (TTM r2 supports minutely/hourly; daily/weekly in r2.1). Real data must impute gaps before feeding.
  • Preprocessing: External std scaling per window: (x-mean)/std where mean/std computed on context window only (scale="std"). Model receives normalized values; output inverse-scaled forecast*std+mean for denorm report. Both norm and denorm saved; consistency compared on norm to avoid scaling error.
  • Target: forecast 96 steps, single variate. Output shape [batch, prediction_length, num_channels] = [1,96,1].
  • Split: single deterministic window; no train/test leakage; same slice CPU/NPU.
  • Schema validation: inference.py checks shape [B,T,C] with T=512, C=1, finite values, rejects 1D/2D mis-shapes; checks dtype float32.
  • Privacy: Only synthetic stats and SHA logged; no personal data.

Environment

  • NPU: Ascend910_9362, 2 devices (Phy IDs 2,3 at 0000:0A:00.0/0B:00.0), tested on npu:0, HBM 65536 MB, driver 25.5.5, health OK, temp 41C, power 165W
  • CANN: 8.5.1 at /usr/local/Ascend/cann-8.5.1, SOC 910B
  • Python: 3.11.14, Torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, Transformers 4.40.1, Pandas 3.0.2, Numpy 1.26.4, huggingface_hub 0.36.2, safetensors, scikit-learn, datasets stub
  • HF cache: snapshot_download local_dir_use_symlinks=False via hf-mirror, revision d6a79570
  • Device validation: torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)==Ascend910_9362, verified 134 params on npu:0, no CPU fallback
  • Granite-tsfm source: cloned https://github.com/ibm-granite/granite-tsfm to /tmp/granite-tsfm (commit depth 1, 2026-08-20), PYTHONPATH set, datasets stub provided to avoid heavy dependency.

Installation

pip install -r requirements.txt
# If granite-tsfm not available via pip, ensure source is cloned:
# git clone --depth 1 https://github.com/ibm-granite/granite-tsfm /tmp/granite-tsfm
# export PYTHONPATH=/tmp/granite-tsfm:$PYTHONPATH
# Requires CANN toolkit at /usr/local/Ascend/cann-8.5.1 and torch_npu

NPU Inference

python inference.py
# defaults: --model ibm-granite/granite-timeseries-ttm-r2 --context 512 --seed 0 --device npu:0
python inference.py --context 512 --seed 42 --benchmark
python inference.py --model /opt/atomgit/adapt-npu-agent/working/models/ibm-granite-granite-timeseries-ttm-r2
  • Loading: TinyTimeMixerForPrediction.from_pretrained(local_or_hub) then .to("npu:0"), verify next(param).device.type=="npu" and dtype, print device_name, 134/134 on NPU.
  • Compute: model(past_values=past_npu) where past is [1,512,1] normalized. Wrapped with torch.npu.synchronize() before/after for accurate timing. Output prediction_outputs is [1,96,1] logits.
  • Output: logs input stats, SHA, shape/device, forecast preview (norm/denorm), elapsed, SUCCESS flag, exit 0 on success else non-zero.
  • Scaling: raw preview and norm preview both printed; denorm via *std+mean; future_gt not used but logged for reference.
  • Edge: Handles batch 1 only in example; multivariate channel>1 supported by same mode common_channel (enable_forecast_channel_mixing false in this checkpoint).

Real Results (NPU)

  • Input: synthetic batch 1, context 512 mean 2.570732 std 1.523962, raw preview [0.1764, 0.1990, 0.4070, 0.6661, 0.7374], norm preview [-1.5711, -1.5562, -1.4197, -1.2497, -1.2029]
  • CPU baseline (FP32): forecast norm mean 1.811069 std 0.160616, denorm preview [5.9485, 5.8827, 5.8441, 5.7726, 5.7205], denorm mean 5.330872
  • NPU npu:0 (same weights, seed 0): forecast norm mean 1.811284, denorm preview [5.9484, 5.8826, 5.8440, 5.7726, 5.7205], denorm mean 5.331060
  • First run (incl. graph compile): 0.1747s
  • Stable after warmup 3/10: avg 0.0049s, min 0.0048s, max 0.0050s, p50 0.0049s, p90 0.0050s, throughput 203.5 windows/s (batch1, 512->96, FP32) -> ~18528 rows/s if counting context rows
  • HBM: baseline idle 3104 MB, peak after load 3.2 MB model resident? Actually max_memory 3.2 MB reported via torch.npu.max_memory_allocated (model tiny) but npu-smi HBM 3104 idle includes driver overhead; within 64GB well.
  • Device evidence: First param device: npu:0, NPU device name: Ascend910_9362, Input device: npu:0, Output device: npu:0, 134/134 params on NPU, torch.npu.synchronize() used before/after.

Consistency

  • CPU vs NPU (same weights, same input norm [1,512,1], seed 0, FP32, eval mode): saved cpu_pred_norm.npy/npu_pred_norm.npy shape [1,96,1] float32.
  • Result: max_abs_error 4.21e-04, mean_abs_error 2.19e-04 (on normalized outputs ~1.8 scale), finite true, shape equal true
  • Command: python scripts/compare_outputs.py --cpu cpu_pred_norm.npy --npu npu_pred_norm.npy --task forecasting --atol 1e-4 --rtol 1e-3 → PASSED
  • Threshold rationale: FP32 atol 1e-4 rtol 1e-3 standard; observed error 4.2e-04 < rtolscale (0.0011.8=0.0018) so within; model uses LayerNorm, MLP mixing, no quantized ops, error from NPU fusion negligible, proves deterministic no fallback, no stochastic sampling (TTM is deterministic point forecast unlike flow-matching).
  • Reproducibility: same preprocessing (std scaling), same dtype float32, eval mode, seed 0, sync timing. No CPU fallback detected.

Performance

  • Method: torch.npu.synchronize() before/after each model(past_values); warmup 3, test 10.
  • Compile/first-run: 0.1747s (first graph compile) vs 0.0049s stable (compile amortized ~35x speedup).
  • Stable: avg 0.0049s, p50 0.0049s, p95 0.0050s, throughput 203.5 windows/s per single window (512 context -> 96 forecast, FP32). In rows/s: 512/0.0049=104k rows/s context, or 96/0.0049=19591 forecast rows/s.
  • Peak HBM: ~3.2 MB via torch.npu.max_memory_allocated (tiny model 805k params ~3.1 MB weights + activation), npu-smi shows 3104 MB baseline due to driver/CANN overhead, well within 65536 MB.
  • Preprocessing: not included (synthetic generation ~0.001s); timing only model forward (synchronized). Scaling negligible.
  • Windows/s vs series/s: windows/s reported for time-series; series/s same as windows/s for batch1.

Evidence Images

All three PNGs generated by scripts/render_xterm_evidence.mjs --style raw from real logs (xterm.js white on dark gray, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$ is display-only, not host proof).

  • Agent Workflow – reconnaissance, env check npu-smi, snapshot_download, inspect_model, CPU baseline, NPU inference, compare, benchmark, validate.
  • NPU Device Call – npu-smi, torch_npu check, device name Ascend910_9362, param device npu:0, input/output device, synchronize.
  • Model Result – python inference.py full output, input stats, forecast preview, timing, SUCCESS.

assets/ contains exactly those three files, generated from logs/workflow.log, logs/device.log, logs/inference.log via manifest.

Limitations

  • Checkpoint is univariate focused (num_input_channels=1, common_channel mode, channel mixing disabled); multivariate must run channel-independent windows or use larger channel-mix checkpoint not tested.
  • Context 512 / horizon 96 fixed for this checkpoint; other horizons need different r2 branch (e.g., 512-336, 1024-96) via get_model() – not covered.
  • Only minutely/hourly resolutions officially; daily/weekly needs r2.1 branch.
  • Point forecast only – quantiles via student-t head not validated; evaluation uses deterministic MSE head.
  • Single NPU npu:0 only; multi-NPU or batch>1 not benchmarked (model supports batch>1 but not measured).
  • Training (fit) not migrated – only inference; return_loss=True training path remains CPU-untested on NPU.
  • Requires granite-tsfm source or datasets stub for tsfm_public import; pure transformers AutoModel will not load TTM without tsfm code.
  • Synthetic data evaluation is smoke consistency; not full benchmark (M4, Electricity etc.) – full benchmark would need dataset download and metric MAE/RMSE/SMAPE across datasets.