liaogx_/granite-timeseries-patchtst
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Granite-TimeSeries-PatchTST on Ascend NPU

IBM Granite-TimeSeries-PatchTST time-series forecasting model (ICLR 2023, arXiv:2211.14730), pre-trained on the 7-channel ETTh1 dataset, adapted for Ascend NPU via torch_npu.

Model Description

PatchTST (A Time Series is Worth 64 Words: Long-term Forecasting with Transformers) segments a time series into subseries-level patches, which are then served as input tokens to a vanilla Transformer encoder. Each channel is processed independently (channel independence) while sharing the same embedding and Transformer weights, which both preserves local semantic information and quadratically reduces attention compute. This checkpoint is the IBM pre-trained model for the ETTh1 dataset (7 channels: HUFL/HULL/MUFL/MULL/ LUFL/LULL/OT), forecasting the next 96 hours from a 512-hour window, reporting MSE 0.3881 on the ETTh1 test split.

Architecture: PatchTSTForPrediction (native in transformers 4.57.6)

  • Patch embedding: patch_length=12, patch_stride=12 → 42 patches + CLS token
  • Transformer encoder: 3 layers, d_model=128, 16 heads, FFN 512, pre-norm
  • sincos positional encoding, use_cls_token, shared embedding/projection
  • std scaling (RevIN-style) + deterministic linear forecast head (loss=mse)
  • Context 512, prediction 96, 7 input channels
  • 614,496 parameters (~0.6M), fp32, safetensors 2.47MB

NPU Adaptation

vLLM-Ascend 0.18 does not support this non-autoregressive time-series architecture (not in the LLM registry), so we use torch_npu + transformers 4.57.6 native PatchTSTForPrediction + FastAPI — zero source modifications, no vendoring, no patching.

All operators used by PatchTST (eager matmul attention, LayerNorm, BatchNorm, GELU, sincos positional encoding, std scaling) are natively supported by the Ascend NPU. The model's default attn_implementation="eager" avoids flash-attention entirely.

Environment

  • Ascend 910 (64GB HBM), CANN 8.5.1, torch_npu 2.9.0.post1
  • Python 3.11, torch 2.9.0, transformers 4.57.6, fastapi/uvicorn

Steps

# 1. download weights (ModelScope mirror, sha256-verified)
python download_model.py

# 2. generate demo data
python make_test_data.py

# 3. start the service (npu:1, port 8043)
./start_serve.sh            # or: python server.py --port 8043

# 4. test the service
python test_server.py --port 8043

# 5. verify NPU vs CPU numerics
python verify_npu_vs_cpu.py

Test Case

curl -X POST http://127.0.0.1:8043/v1/forecast \
  -H 'Content-Type: application/json' \
  -d @demo_series.json
# -> {"prediction": [[[...], ...]], "loc": [...], "scale": [...],
#     "prediction_length": 96, "context_length": 512, "latency_ms": 5.0, ...}

Request body (past_values) accepts [T], [T, C] or [B, T, C] (float32). Each series must have length >= 512; the most recent 512 points are used. Response prediction has shape [B, 96, C] (one forecast per input channel).

Performance (Ascend 910, npu:1)

MetricValue
Model load~2.8 s
Steady-state forward (NPU)~5 ms
Steady-state HTTP p509.0 ms / p95 9.1 ms
CPU single-core forward~14.1 ms
NPU vs CPU acceleration~2.8×
NPU vs CPU cosine1.0000000000
NPU vs CPU max_abs_diff6.7e-05
HBM usage (process)156 MB
Port / device8043 / npu:1

Repository

  • inference.py — PatchTSTEngine (torch_npu inference, [B,T,C] input)
  • server.py — FastAPI service (/v1/forecast, /health)
  • download_model.py — ModelScope downloader with sha256 idempotent check
  • make_test_data.py — ETTh1-style 7-channel synthetic demo data
  • verify_npu_vs_cpu.py — NPU vs CPU numerical equivalence check
  • test_server.py — HTTP end-to-end smoke test
  • start_serve.sh — one-click start script
  • assets/ — screenshot materials (workflow / result / npu-smi)

Model weights are not committed to this repository; run download_model.py to fetch them.