This is the IBM Granite-branded version of PatchTST-FM-r1 (Apache-2.0 licensed), adapted for Ascend NPU via torch_npu.
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:
Architecture: PatchTSTFMForPrediction
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.
torch.asinh/sinh, softplus, cumsum all NPU native| Metric | Value |
|---|---|
| Load time | 1.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 reference | 98.8s (single core) |
| Speedup | ~423× |
| HBM (process) | ~1.4GB |
| NPU vs CPU cosine | 1.0000000000 |
| NPU vs CPU max_abs_diff | 3.45e-03 |
bash start_serve.shPOST /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"}
from inference import PatchTSTFMEngine
engine = PatchTSTFMEngine()
q = engine.forecast([0.1, 0.2, ...]) # returns (1, 99, 64) numpy array| File | Purpose |
|---|---|
inference.py | PatchTSTFMEngine (NPU inference) |
server.py | FastAPI server |
download_model.py | ModelScope download + sha256 verify |
make_test_data.py | Generate demo test data |
verify_npu_vs_cpu.py | Numerical consistency check |
test_server.py | HTTP endpoint tests |
start_serve.sh | One-click start script |
vendor/patchtst_fm/ | Vendored patchtst_fm module (6 files) |
requirements.txt | Python dependencies |
.gitignore | Excludes weights, data, screenshots |