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,
"patch_length": 16,
"stride": 8,
"d_model": 128,
"num_attention_heads": 16,
"num_hidden_layers": 3,
"learning_rate": 1e-4,
"num_train_epochs": 20,
"per_device_train_batch_size": 32,
},
)
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
patch_lengthPatch size (like kernel size)8–64
strideOverlap between patchespatch_length / 2
d_modelTransformer hidden dim64–512
num_hidden_layersTransformer depth2–6
num_attention_headsAttention heads4–16
dropoutRegularization0.1–0.3

Typical configs by dataset size:

Dataset sizecontext_lengthd_modellayersepochs
Small (< 1k windows)9664250
Medium (1k–10k)336128330
Large (> 10k)512128320

For the original benchmark numbers, see the PatchTST paper.