Skip to main content

PatchTST — Patch-based Time Series Transformer

Multivariate forecasting · Fine-tunable · HuggingFace-native


Overview​

  • Model ID: patchtst-forecasting
  • Architecture: PatchTSTForPrediction
  • Framework: HuggingFace Transformers
  • Backend: forecasting specialist (specialists-ts-cu121)
  • specialist_type: forecasting
  • Hardware: GPU (small footprint, ~512 MB VRAM); also runs on CPU (slower)
  • Training time: 5–60 minutes depending on dataset size

PatchTST divides a time series into patches (like ViT patches for images) and processes them with a Transformer encoder, reaching strong results on standard benchmarks with fewer parameters than channel-mixing models.


When to Use​

✅ Perfect for:

  • Multivariate forecasting (multiple correlated series)
  • ETT-style benchmarks (energy, weather, traffic)
  • When you have enough data to fine-tune
  • Point forecasts with a fixed horizon

❌ Not ideal for:

  • Zero-shot forecasting — use TimesFM 2.5
  • Very short series
  • Probabilistic forecasts / quantiles — use TimesFM
  • Irregular timestamps — use Prophet

Training​

Fine-tune PatchTST on your own time series.

from colabhive import ColabHive

client = ColabHive(api_key="YOUR_KEY", account_id="YOUR_ACCOUNT")

# CSV time series: a value column (and optional extra channels), ordered in time
dataset = client.datasets.upload(name="my-timeseries", file="./train.csv")

job = client.training.create(
model="patchtst-forecasting",
dataset_id=dataset.id,
hyperparameters={
"context_length": 512,
"prediction_length": 96,
"d_model": 128,
"learning_rate": 1e-4,
"num_train_epochs": 20,
},
)
job.wait()
print(job.get_metrics())

The exact accepted hyperparameters come from the template's schema: GET /api/builder/v1/training/model-configs/{model_config_id}/schema.

Register for inference​

endpoint = client.training.register_for_inference(
run_id=job.id,
name="patchtst-energy-forecast",
description="PatchTST multivariate forecaster",
visibility="account",
)

Inference​

# Univariate: list of floats. Multivariate: list of channel lists.
result = client.endpoints.infer(
endpoint_id=endpoint.endpoint_id,
input_data={
"values": [1.2, 1.5, 1.3, 1.8, 2.1, 2.4, 2.2, 2.6], # historical points
"horizon": 96, # steps to predict
},
)
print(result)
curl -X POST "https://api.colabhive.com/api/builder/v1/endpoints/{ENDPOINT_ID}/infer" \
-H "X-Account-ID: YOUR_ACCOUNT_ID" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": {"values": [1.2, 1.5, 1.3, 1.8, 2.1, 2.4], "horizon": 24}}'

Multivariate input — pass one list per channel under values.


Hyperparameter Guide​

ParameterEffectTypical Range
context_lengthHow much history the model sees96–2048
prediction_lengthForecast horizon24–720
d_modelTransformer hidden dim64–512
dropoutRegularization0.1–0.3
num_input_channelsNumber of input series (channels)1–512
learning_rateOptimizer step size1e-5 to 1e-3
num_train_epochsTraining epochs1–200

The template fixes the rest of the architecture: patch_length=16, stride=8, 16 attention heads, 3 encoder layers and a batch size of 32. They are not configurable.

Typical configs by dataset size:

Dataset sizecontext_lengthd_modelepochs
Small (< 1k windows)966450
Medium (1k–10k)33612830
Large (> 10k)51212820

For the original benchmark numbers, see the PatchTST paper.