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

Granite-TimeSeries-PatchTST-FM-r1 on Ascend NPU

This is the IBM Granite-branded version of PatchTST-FM-r1 (Apache-2.0 licensed), adapted for Ascend NPU via torch_npu.

Model Description

PatchTST was originally released prior to the interest in creating pre-trained, zero-shot time series foundation models. PatchTST-FM (patched time-series transformer-based foundation model) has the architectural simplicity of PatchTST, but differs in some crucial ways. Coupled with a revised training strategy and a significantly larger training corpus, it achieves state-of-the-art results on GiftEval.

The architecture incorporates:

  • Residual blocks in the input and output projections
  • A quantile head (99 quantiles) for probabilistic forecasting
  • Enhanced training strategies with contiguous patch masking and random masking in the forecast period
  • Trained with reconstruction-loss objective

Architecture: PatchTSTFMForPrediction

  • Transformer: 20 layers, d_model=1024, n_head=16
  • Context length: 8192 (512 patches, d_patch=16)
  • Prediction length: 64 (configurable)
  • Quantile heads: 99 (0.01..0.99)
  • Parameters: ~260M
  • Weight format: fp32 safetensors (1.03GB)

Environment

  • Hardware: Ascend 910 ×2 (64GB HBM/card)
  • CANN: 8.5.1
  • Python: 3.11.14
  • torch: 2.9.0 / torch-npu 2.9.0.post1
  • transformers: 4.57.6

NPU Adaptation

Zero source modifications! The upstream PatchTSTFMForPrediction.forward moves every tensor with .to(self.device), so all computation automatically lands on NPU. The wrapping torch.autocast(device_type="cpu") does not affect NPU ops, keeping fp32.

  • SDPA (float add mask) → NPU aclnnFlashAttentionScore native
  • RevIN torch.asinh/sinh, softplus, cumsum all NPU native
  • All operators eager matmul/LayerNorm/GELU, no CUDA dependencies

Performance

MetricValue
Load time1.5~1.7s
First request (w/ compile)~250-300ms
Steady-state (single series)233ms (99 quantiles)
Steady-state (median only)~13ms
Batch 2 series~15ms
CPU reference98.8s (single core)
Speedup~423×
HBM (process)~1.4GB
NPU vs CPU cosine1.0000000000
NPU vs CPU max_abs_diff3.45e-03

Usage

Start server

bash start_serve.sh

API endpoints

POST /v1/forecast

{
  "past_values": [0.1, 0.2, ...],
  "prediction_length": 64
}

Response: {"quantile_predictions": [[[B,99,H]]], "quantile_levels": [...], "median": [[B,H]], "latency_ms": 32.7}

POST /v1/forecast/median

{
  "past_values": [0.1, 0.2, ...]
}

GET /health → {"status": "ok"}

Python library

from inference import PatchTSTFMEngine
engine = PatchTSTFMEngine()
q = engine.forecast([0.1, 0.2, ...])  # returns (1, 99, 64) numpy array

Files

FilePurpose
inference.pyPatchTSTFMEngine (NPU inference)
server.pyFastAPI server
download_model.pyModelScope download + sha256 verify
make_test_data.pyGenerate demo test data
verify_npu_vs_cpu.pyNumerical consistency check
test_server.pyHTTP endpoint tests
start_serve.shOne-click start script
vendor/patchtst_fm/Vendored patchtst_fm module (6 files)
requirements.txtPython dependencies
.gitignoreExcludes weights, data, screenshots

References

  • PatchTST paper
  • PatchTST-FM paper
  • IBM Granite TSFM Repository
  • GiftEval Benchmark