﻿# PatchTST patch geometry: stride and end padding also determine the forecast head

Preserve PatchTST context length, patch length, stride and replication padding together because patch count controls positional structure and flattened head dimensions.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-patchtst-patch-stride-end-padding-flatten-head-shape/
Language: en

## Describe the complete patch geometry

PatchTST turns a history into local patches rather than treating every observation as a separate transformer token. The [original paper](https://arxiv.org/abs/2211.14730) explains the patch-based design. An implementation record must include context length, patch length, stride and padding policy. Patch length alone does not identify which observations enter each token, how much adjacent tokens overlap or how many representations reach the forecasting head.

## Inspect the final partial-window policy

The [supervised backbone](https://raw.githubusercontent.com/yuqinie98/PatchTST/main/PatchTST_supervised/layers/PatchTST_backbone.py) constructs patch count from configured geometry. Its end-padding option uses replication and adds a patch. That repeats the context edge; it does not supply additional observed future measurements. A port using zero padding, discarding the edge or choosing a different stride can create a different token sequence while still accepting the same raw history. Compare actual patch contents before comparing neural outputs.

## Follow patch count into the head

The backbone's flattened forecasting head uses a feature width determined by hidden representation size and patch count. Positional structure also depends on the constructed patch sequence. Changing context or stride therefore need not be compatible with a trained head merely because the attention width matches. The [model wrapper](https://raw.githubusercontent.com/yuqinie98/PatchTST/main/PatchTST_supervised/models/PatchTST.py) passes these geometry choices into the backbone. Preserve both components when loading or exporting a checkpoint.

## Separate shape adaptation from learned compatibility

Replacing a mismatched head can produce valid output dimensions while introducing newly initialized parameters. That is a new training-state decision rather than evidence of a faithful inference port. The [MOMENT head-initialization guide](/journal/fg2-moment-pretrained-reconstruction-new-task-head-init/) provides a related distinction. If geometry is intentionally changed, document which parameters remain compatible, which are adapted and which require fitting before reporting the revised system's forecasting quality.

## Verify boundary patches explicitly

Use a history with recognizable position values and inspect its first, overlapping and final patches. Check patch count, replicated edge values, positional layout and head input width against the reference. The [artifact-manifest guide](/journal/tokenizer-artifact-release-manifest/) supports release packaging. Accept geometry compatibility before benchmarking execution. A smooth output chart is insufficient evidence that a port preserved the model's original temporal segmentation or that a shape-correct replacement head contains the learned mapping from the selected checkpoint.
