Base model: ibm-research/patchtst-fm-r1 (also mirrored as ibm-granite/granite-timeseries-patchtst-fm-r1)
This repository is an Ascend NPU #NPU adaptation of PatchTST-FM (260M params, Foundation Model for time-series). Verified on Ascend 910_9362 (npu:0) with CPU-NPU consistency max_abs_error 2.1e-05, mean 1.93e-06 (threshold atol=1e-4, rtol=1e-3) ✅
PatchTSTFMForPrediction (PatchTST FM, 20 layers, d_model 1024, n_head 16, patch 16, 512 patches)tsfm_public (granite-tsfm)ETTh1.csv (public benchmark, hourly, 17420 rows, 8 cols: date + 7 numeric HUFL/HULL/MUFL/MULL/LUFL/LULL/OT) or synthetic fallback (randn seed 0)[1, 336, 7] window from offset 1000 (cols HUFL..OT), hourly frequency, sorted by date, no time_zone, no missing steps in slice (nan handled via mean if present)past_values shape [B, T, C] where T=336 (tested) up to 8192 with pruning, C=7, B=1, dtype float32, device npu:0quantile_outputs shape [B, 99, 64, 7] (99 levels 0.01..0.99), prediction_outputs shape [B, 64, 7] (point), device npu:0[batch, quantile, time, channel] for quantiles; prediction_length=64 fixed for NPU validation (config default); context/horizon/channel documentednpu:0, torch.npu.is_available()==True, torch.npu.device_count()==2pip install torch torch_npu transformers einops pandas numpy scikit-learn datasets
# granite-tsfm for PatchTST-FM (provides PatchTSTFMForPrediction)
git clone https://github.com/ibm-granite/granite-tsfm.git /tmp/granite-tsfm
export PYTHONPATH=/tmp/granite-tsfm:$PYTHONPATHDevice proof logged: model parameters on npu:0, past_values on npu:0, quantile_outputs on npu:0, torch.npu.synchronize() before/after timing.
import sys; sys.path.insert(0, "/tmp/granite-tsfm")
import torch, torch_npu
from tsfm_public.models.patchtst_fm import PatchTSTFMForPrediction
model = PatchTSTFMForPrediction.from_pretrained("/tmp/ms_patchtst_final").to("npu:0").eval()
past = torch.randn(1, 336, 7).to("npu:0")
with torch.no_grad():
torch.npu.synchronize(); out = model(past_values=past, prediction_length=64); torch.npu.synchronize()
print(out.quantile_outputs.shape) # [1, 99, 64, 7]Or run directly:
python inference.py --model-dir /tmp/ms_patchtst_final --device npu:0 --context-length 336 --prediction-length 64Default python inference.py runs ETTh1 slice if available else synthetic, prints NPU proof and benchmark.
[1,336,7] offset 1000 (same slice for CPU/NPU, same dtype float32, eval mode, seed)[1,99,64,7], finite true, max_abs 2.098e-05, mean_abs 1.93e-06, atol 1e-4 rtol 1e-3 ✅ via scripts/compare_outputs.py --task regressionquantile mean 9.575349, std 9.470970, min -0.114555, max 41.609299q0.01 8.5977, q0.5 11.1107, q0.99 13.3735 (first step ch0)median first 5 steps ch0: [11.1107, 10.9083, 9.9149, 11.3855, 15.5348]Measured on Ascend910_9362, single npu:0, synchronize surrounding each run:
Images generated by xterm.js from real logs (workflow, device proof, result):

Only xterm.js --style raw rendering is used; images are not simulated.
Apache-2.0 (original model). NPU adaptation retains same license.