use case · basics · Patch-12 tokenization & channel independence lab · q8 WASM · 0.77 MB

Inside PatchTST: Patch-12 Tokenization & Channel Independence Lab

See the two core architectural choices declared in IBM's config.json: 1) Patch-12 tokenization (patch_length: 12, patch_stride: 12 slices 512 steps into 42 patches + 1 [CLS] token = 43 tokens, cutting attention cost by ~140× vs pointwise attention) and 2) Channel Independence (channel_attention: false, share_embedding: true — every channel passes through the exact same Transformer weights independently!).

1 · Granite PatchTST worker (0.77 MB q8 WASM)

2 · Live Channel-Independence Perturbation & Patch-12 Inspector

Spike a single channel's final 48 steps and run two back-to-back live inferences (baseline vs perturbed). Because channel_attention: false, the target channel shifts dramatically while the 6 other channels stay near-invariant (a small ~1–3% residual comes purely from shared per-tensor q8 dynamic activation scaling).

Prepare Granite PatchTST above to inspect Patch-12 tokens and test channel independence live.

Patch-12 token strip ([CLS] + 42 patches = 43 tokens)

512 steps ÷ stride 12 yields 42 non-overlapping patches (steps 0..503; 8 remainder steps) fed to 3 shared Transformer layers (d_model=128, 16 heads).

Measured cross-channel coupling (|Δpred| / σ)

Target channel reacts strongly to the shock; the 6 unperturbed channels exhibit near-zero drift, verifying channel independence in live WASM inference.

Perturbed target channel: baseline vs post-shock 96-step forecast

Tokens / channel43 (CLS + 42×12)
Target max |Δpred|—
Max other-ch drift—
Isolation ratio—
Wins vs naive—
2× WASM pass—

3 · All-7 Channels Benchmark: PatchTST vs Seasonal Persistence Baseline

Live MAE, RMSE, and sMAPE across all 7 channels on the 96-step held-out horizon compared against a 24-step seasonal persistence baseline.

Channel PatchTST MAE Naive MAE RMSE sMAPE Skill vs naive
Run the experiment above to compute live 7-channel holdout metrics.

4 · Show the code — Patch-12 inspection & worker forward pass

</> Show the code · computePatchTokens() — 512 steps → 42 Patch-12 tokens + [CLS] patchtst-core.mjs · L502–538
</> Show the code · runForecast() — past_values [1, 512, 7] → prediction_outputs [1, 96, 7] worker.js · L117–160