liaogx_/test-patchtsmixer
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-research/test-patchtsmixer (PatchTSMixer forecasting) on Ascend NPU

IBM Research PatchTSMixer forecasting checkpoint for the 7-channel ETTh1 dataset (KDD'23, arXiv:2306.09364), adapted for Ascend NPU via torch_npu.

Model Description

PatchTSMixer (PatchTST-style time-series forecasting with MLP-Mixer) segments a time series into patches and mixes them with a lightweight channel-mixing MLP-Mixer backbone. This checkpoint is the fine-tuned forecasting model (PatchTSMixerForPrediction) pre-trained on the ETTh1 training split (7 channels: HUFL/HULL/MUFL/MULL/LUFL/LULL/OT).

Note: ibm-research/test-patchtsmixer is an IBM Research test/scratch release whose config.json and model.safetensors are byte-identical to the official ibm-granite/granite-timeseries-patchtsmixer. It is served here as a standalone time-series-forecasting endpoint.

Architecture: PatchTSMixerForPrediction (native in transformers 4.57.6)

  • Patch embedding: patch_length=16, patch_stride=16 → 32 patches
  • MLP-Mixer backbone: 2 layers, d_model=48, expansion_factor=3, gated_attn=true
  • std scaling (RevIN-style), common_channel mixing mode, sincos positional encoding
  • Deterministic linear forecast head (loss=mse, distribution_output=student_t)
  • Context 512, prediction 96, 7 input channels
  • 196,144 parameters (~0.2M), fp32

Ascend NPU adaptation

vLLM-Ascend 0.18 is not used (PatchTSMixer is a non-autoregressive time-series model, absent from the 317-architecture LLM registry). The model runs on torch_npu + transformers 4.57.6 native PatchTSMixerForPrediction with zero source modifications — PatchTSMixer ships out of the box in transformers 4.57.6 (no vendoring, no patching). Every operator used (eager matmul / LayerNorm / GELU / sigmoid / std scaling) is natively supported by the Ascend NPU.

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 (GitCode HF-mirror first, ModelScope fallback; sha256-verified)
python download_model.py

# 2. generate demo data
python make_test_data.py

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

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

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

Test Case

curl -X POST http://127.0.0.1:8058/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~1.1 s
Steady-state forward (NPU)~1.6–1.8 ms
Steady-state HTTP p505.99 ms / p95 6.06 ms
CPU single-core forward~3.2 ms
NPU vs CPU cosine1.0000000000
NPU vs CPU max_abs_diff2.20e-04
HBM usage (process)126 MB
Port / device8058 / npu:1

Repository

  • inference.py — PatchTSMixerEngine (torch_npu inference, [B,T,C] input)
  • server.py — FastAPI service (/v1/forecast, /health)
  • download_model.py — GitCode HF-mirror + ModelScope downloader (sha256 idempotent)
  • 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.