TL;DR
PatchTST is a Transformer for forecasting: given the last L values of several related series, it predicts the next T values of each. It makes two design changes. First, it groups neighbouring time steps into short patches and feeds each patch to the Transformer as one token, instead of one token per time step. Second, it treats each variable (channel) as its own univariate series that shares one set of weights with the others. On long-horizon benchmarks it beats earlier Transformer forecasters, and a version pre-trained by hiding patches transfers well to other datasets.
Builds on: Time Series Forecasting, Transformer, Masked Autoencoder, Instance Normalization · Leads to: patch-based time series Transformers, which the paper itself proposes as a building block for time series foundation models
Why it mattered
Forecasting is used for planning. The paper's benchmarks are the datasets the field had settled on: Traffic (road occupancy from 862 sensors on San Francisco freeways), Electricity (hourly consumption of 321 customers), Weather (21 meteorological indicators in Germany) and four ETT datasets from electrical transformers. Before this paper, the Transformer forecasters it compares against (Informer, Autoformer, FEDformer and others) were run with default look-back windows of 96 steps. A 2022 study showed that a very simple linear model could beat them, which raised the question of whether attention helps time series at all (Are Transformers Effective for Time Series Forecasting?). PatchTST answered yes, with a design that uses long histories. Its reported gain over the best Transformer baselines is 21.0% lower MSE and 16.7% lower MAE, averaged across the benchmarks.
The idea has traveled. Patches were already the input unit of the Vision Transformer, which cuts images into 16 by 16 blocks (An Image is Worth 16x16 Words (Vision Transformer)), and this paper brings that unit to time series with channel-independence and masked pre-training added. The paper ends by calling the design a candidate building block for time series foundation models.
The problem
A Transformer treats each input as a sequence of tokens and lets every token attend to every other one. That is powerful, but it has two costs that matter for time series.
- One time step is too small to be a token. A single reading of a temperature or a traffic count carries little meaning on its own, much as a single letter does not carry much meaning in a sentence. Point-wise tokens make the model work out local shape from scratch.
- Attention cost grows with the square of the token count. If every time step is a token, a look-back window of 336 steps means 336 tokens and a 336 by 336 attention table. Long histories become slow and memory-hungry, so practitioners shortened them. In the paper's Table 1 on Traffic with horizon 96, a channel-independent Transformer with a 96-step window reaches MSE 0.518, while a 336-step window reaches 0.397. More history helps, but the cost grows quickly.
Multivariate data adds a third question: should the model mix the variables into one token, or keep each variable separate?
How it works
The model takes a window of L past values for each of M variables and predicts T future values for each. The pipeline runs in this order:
flowchart LR A["Multivariate series: M channels, look-back L"] --> B["Split into M univariate series"] B --> C["Instance normalization: subtract mean, divide by spread"] C --> D["Pad last value S times, cut into N patches of length P"] D --> E["Linear projection plus position vector per patch"] E --> F["Transformer encoder, same weights for every channel"] F --> G["Flatten and linear head"] G --> H["Forecast T future values per channel"]
Now a tiny instance, traced from start to finish. The series is one channel with 12 values, 1 to 12. Patch length P is 4 and stride S is 2, so consecutive patches overlap by 2 values. We want T = 2 future values.
- Start. The input is x = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), so L = 12. Check: 12 numbers go in.
- Normalize. Instance normalization rescales this window to zero mean and unit spread, and the mean and spread are saved. This trace skips the arithmetic; the math section shows it, and the saved values are added back at the end. Check: the saved mean and spread are the only numbers kept for later.
- Pad. Repeat the last value S = 2 times at the end: (1, ..., 12, 12, 12), which has 14 values. Check: 14 = 12 + 2.
- Count the patches. N = 6, from the formula in the math section. Check: the patches start at positions 1, 3, 5, 7, 9 and 11, so six of them fit.
- Cut the patches. They are [1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8], [7, 8, 9, 10], [9, 10, 11, 12] and [11, 12, 12, 12]. Check: each has 4 values and neighbours share 2.
- Embed each patch as one token. A linear projection maps each patch to a vector of size D. Pretend D = 2 and the projection adds the first two values and the last two values. Patch 1 becomes (1 + 2, 3 + 4) = (3, 7), and patch 2 becomes (7, 11). A learned position vector is added to each token so the model knows the order. Check: 6 tokens, each of size 2.
- Attend. Each of the 6 tokens attends to all 6, so there are 6 times 6 = 36 attention scores. If each of the 12 raw time steps were a token, there would be 12 times 12 = 144 scores. Check: 36 is one quarter of 144 here, and the gap grows with the window.
- Output. The encoder gives 6 representations. They are flattened into one vector and a linear head maps it to T = 2 numbers, the forecast. Those numbers are scaled and shifted back using the saved mean and spread. Check: two forecast values, in the original units.
For several variables, steps 3 to 8 run once per variable with the same weights. That is the channel-independence idea.
The math
The walkthrough is formalised here, with the same symbols. Let L be the look-back length, P the patch length, S the stride between patch starts, N the number of patches, D the size of each token, and T the horizon.
A window of L values padded by S repeated copies of its last value is cut into patches of length P that start S apart. The number of patches is The floor part counts the patches that fit inside the original window, and the extra 1 counts the patch that reaches into the padding.
Step 4 in symbols
For the trace, L = 12, P = 4 and S = 2 give N = floor(8 / 2) + 2 = 4 + 2 = 6. The default setting, L = 336, P = 16 and S = 8, gives N = floor(320 / 8) + 2 = 42.
Step 6 in symbols
Each patch is a column vector x_p of length P. The embedding of channel i is where W_p is a learned D by P matrix that maps each patch to size D, and W_pos is a learned D by N matrix that gives each position its own vector. Both are trained, not fixed. The output has one column per patch.
Step 7 in symbols
For each head h, the representation is turned into queries, keys and values, Q = X^T W^Q, K = X^T W^K and V = X^T W^V, where X is the matrix of token columns. The attention output is The score matrix Q K^T is N by N. Its size is what patching shrinks. Going from L = 336 to N = 42 cuts the number of scores from 336 squared to 42 squared, which is a factor of 8 squared = 64.
Instance normalization
For one window x_1, ..., x_L of one channel, compute its mean and spread: The network sees the normalized values (x_t - mu) / sigma. Its prediction is turned back into the original units by multiplying by sigma and adding mu. Because mu and sigma come from each window, a level shift between training and test periods has less effect.
Loss
The training objective averages squared errors over the channels and samples: This is the mean squared error of Mean Squared Error applied to each future value.
Masked pre-training
For representation learning, the paper uses non-overlapping patches, sets 40% of them to zero, and trains the same encoder with an MSE loss to rebuild the zeroed patches. The model cannot simply copy from the neighbours, because a hidden patch is a whole block of values, not a single time step.
Worked examples
Take L = 12, P = 4 and S = 2.
- Apply the patch-count formula: floor((12 - 4) / 2) + 2.
- Inside the floor, 12 - 4 = 8, and 8 / 2 = 4, so the floor is 4.
- Add 2: N = 6 patches.
- Now the default setting: L = 336, P = 16, S = 8.
- 336 - 16 = 320, and 320 / 8 = 40, so the floor is 40.
- Add 2: N = 42 tokens.
Interpretation: 336 raw time steps become 42 tokens. The attention table shrinks from 336 by 336 to 42 by 42.
Try it: how many patches does L = 96, P = 16 and S = 8 give? Answer: floor((96 - 16) / 8) + 2 = 10 + 2 = 12 patches.
PatchTST/64 uses a look-back window of L = 512 with P = 16 and S = 8.
- Patch count: floor((512 - 16) / 8) + 2 = floor(62) + 2 = 64.
- Score-table size with raw time steps: 512 by 512 = 262,144 entries.
- Score-table size with patches: 64 by 64 = 4,096 entries.
- Ratio: 262,144 / 4,096 = 64.
- The model sees 512 steps, about 1.5 times the default 336-step window, with 64 tokens instead of 512.
Interpretation: patching is what lets the model use the longer history. Its gain comes from the window it can afford, not from a bigger attention table.
The paper's ablation (Table 7) on Traffic with horizon 96 gives these MSE values: patching and channel-independence together (P+CI) 0.367; channel-independence only (CI) 0.397; patching only (P, which mixes channels) 0.595; and the original Transformer, which ran out of GPU memory even at batch size 1. FEDformer, the strongest baseline, gets 0.576.
- Effect of channel-independence when patching is on: from P (0.595) to P+CI (0.367). The drop is 0.595 - 0.367 = 0.228. Divided by 0.595, that is 38.3%.
- Effect of patching when channel-independence is on: from CI (0.397) to P+CI (0.367). The drop is 0.030. Divided by 0.397, that is 7.6%.
- Compare the best design to the baseline: P+CI (0.367) against FEDformer (0.576) is a drop of 0.209, about 36.3% of 0.576.
- Read the result. Channel-independence gives the larger gain in this setting. Patching gives a smaller MSE gain, plus the memory savings that make the long window possible at all.
Try it: what is the percent MSE reduction from FEDformer (0.576) to P+CI (0.367)? Answer: 0.209 / 0.576 = 0.363, so 36.3%.
Results
- Supervised forecasting, averaged over benchmarks: PatchTST/64 reduces MSE by 21.0% and MAE by 16.7% against the best Transformer baseline; PatchTST/42 reduces them by 20.2% and 16.4%.
- Weather, horizon 96: PatchTST/64 gets MSE 0.149 and MAE 0.198, against FEDformer's 0.238 and Informer's 0.354. DLinear gets 0.176.
- Traffic, horizon 96: PatchTST/64 gets 0.360, against FEDformer's 0.576 and DLinear's 0.410.
- Self-supervised pre-training followed by fine-tuning gives MSE 0.352 on Traffic at horizon 96. Linear probing, which trains only the head, gives 0.399, close to the supervised model trained from scratch at 0.367.
- On the ETTh1 representation benchmark, the paper reports improvements over the baselines of 34.5% to 48.8%, across the prediction lengths it tests.
- Limits the paper states or shows: DLinear wins some settings, the paper does not model cross-channel dependence, and it leaves exchange-rate data out of the benchmark.
Common mistakes and tradeoffs
It is tempting to think a patch is just a downsampled series. In fact downsampling throws values away, while a patch keeps all of its values and the linear projection combines them into one token. Table 1 shows the difference: downsampling a 380-step window into 96 tokens gives MSE 0.447, while patching a 336-step window into 42 tokens gives 0.367.
It is tempting to think channel-independence means the variables are ignored. In fact each channel is processed separately, but all channels share one set of weights, so the model learns one pattern language for them. What it does not model is how the channels affect each other. The paper names that as future work.
It is tempting to think a longer window always helps a Transformer. In fact the paper's Figure 2 shows that most Transformer baselines do not gain from longer windows, while PatchTST's MSE keeps falling as the window grows. The paper also notes that the Transformer baselines overfit easily with long windows.
It is tempting to think a Transformer always beats a linear model. In fact PatchTST is not best everywhere. On ETTm1 with horizon 336, DLinear's MAE of 0.386 beats both PatchTST variants (0.392), although its MSE of 0.369 is no better than PatchTST/42's 0.366.
Use this design when you have a long history, several related series, and enough data to train a Transformer without overfitting. Do not expect it to help when the series are very short, when the data is small (the paper shrinks the model for the smallest datasets to avoid overfitting), or when the key signal is how the series affect each other. The paper excluded an exchange-rate dataset because a random walk is the hard baseline there, a reminder that the right model depends on the data.
History
Transformers appeared in 2017 and quickly took over language work. Vision Transformers, cited by the paper as published in 2021, cut images into 16 by 16 patches and treated each patch as a token. The paper's own citations place Informer and Autoformer in 2021 and FEDformer in 2022, all Transformer forecasters that still looked at point-wise tokens. DLinear, the simple linear model from 2022, showed that a linear map could match or beat them. PatchTST was posted to arXiv in November 2022, which is the 2211 in its identifier.
Reading guide
Read the paper in this order. The lesson's walkthrough follows section 3.1, and the masked pre-training follows section 3.2.
- Introduction: the case for Transformers and the two ideas, patching and channel-independence. Needs Transformer and Time Series Forecasting.
- Related work: patches in vision and language, which needs An Image is Worth 16x16 Words (Vision Transformer), and the earlier Transformer forecasters. Skim it first.
- Section 3.1, model structure: the pipeline in the walkthrough. Needs Instance Normalization, Positional Encoding, Layer Normalization and Batch Normalization (the paper's block uses batch normalization, citing evidence that it beats layer normalization on time series), and Mean Squared Error.
- Section 3.2, representation learning: masked pre-training. Needs Masked Autoencoder and Self-Supervised Learning.
- Section 4.1 and Tables 1 to 3: forecasting benchmarks and results. Needs Are Transformers Effective for Time Series Forecasting? as the main rival.
- Section 4.2 and Tables 4 to 6: pre-training results, linear probing and Fine-Tuning.
- Section 4.3 and Figure 2: ablations and look-back windows. Needs Overfitting to read the baseline discussion.
- Appendix A.1: model sizes and dropout (the paper uses Dropout and a Gaussian Error Linear Unit (GELU) feed-forward layer).
Next to read: Are Transformers Effective for Time Series Forecasting? for the linear baseline that started the debate, and An Image is Worth 16x16 Words (Vision Transformer) for the image patch idea this paper borrows.
Check yourself
QuestionWhat is a patch in PatchTST, and what does channel-independence mean?Show answer
A patch is a block of P consecutive time steps, with consecutive patches starting S steps apart. The patch is turned into one token. Channel-independence means each variable is processed as its own univariate series by a shared Transformer, so the input tokens never mix values from different variables.
QuestionA window has L = 96 steps, patch length P = 16 and stride S = 8. How many patches are there?Show answer
N = floor((96 - 16) / 8) + 2 = floor(10) + 2 = 12. The first 11 patches fit inside the window, and the last one reaches into the padding that repeats the final value.
QuestionWhy does cutting the tokens from 336 to 42 reduce the attention cost by about 64, and not by 8?Show answer
Attention compares every token with every other token, so the score table has N squared entries. Going from 336 to 42 tokens is a factor of 8 in N, and squaring it gives a factor of 64 in the table. The cost falls with the square of the change in token count.
QuestionA team wants to forecast daily sales for 300 stores from three years of history, and suspects the stores strongly affect one another. Should they rely on channel-independence?Show answer
It is a reasonable first model to try, since it shares weights across stores and handles many series cheaply. But the paper's design does not model cross-channel dependencies, so if store interactions matter, it may miss them. The team should compare against a linear baseline such as DLinear and against a model that does mix channels before choosing.
Sources
- Nie, Nguyen, Sinthong and Kalagnanam, "A Time Series is Worth 64 Words: Long-term Forecasting with Transformers", arXiv:2211.14730 (2022). https://arxiv.org/abs/2211.14730
- DOI for the same paper: https://doi.org/10.48550/arXiv.2211.14730
- Code: https://github.com/yuqinie98/PatchTST