Skip to content

Sequences, streaming data, robotics, and scientific extensions · Entry index · SEQ015 · Model

TimesFM: decoder-only time-series foundation model

A pretrained time-series model using continuous-valued patches and a decoder-only Transformer to support forecasting across many series.

Explained here Component demo, not a trained model CodeSplash's own run

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's own run
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, but on a different version of the code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

A pretrained time-series model using continuous-valued patches and a decoder-only Transformer to support forecasting across many series. The original design differs from tokenizing each observation into a discrete vocabulary. Release-specific context limits, output heads, and covariate interfaces must be checked rather than generalized across the entire family.

Question / hypotheses

How well can shared time-series pretraining support forecasts for new series with varying history length and horizon? There is no inherent H0. Evaluate transfer, adaptation benefit, forecast error, and available predictive uncertainty under fixed information sets.

Architecture / computational structure

Numerical input patches enter a decoder-only stack, with output patches produced from contextual hidden states. Training handles relevant context-length variation through its masking design. Continuous numeric outputs and patch embeddings distinguish this original construction from language-model token vocabulary forecasting.

Assumptions

History must be ordered and scaled according to the implementation, with missingness and frequency features handled consistently. Pretraining coverage influences transfer, and overlapping series/windows can leak information across splits. The existence of a pretrained model does not eliminate the need for seasonal-naive and domain-specific baselines.

Formula / computational definition

Partition observations into patches Pj=(x(j−1)p+1,…,xjp)P_j=(x_{(j-1)p+1},\ldots,x_{jp}), embed each patch, and apply causal Transformer processing. A forecast head predicts future values from contextual states; the original point-forecast training uses squared-error objectives. Newer quantile/distribution heads require their own documented losses and calibration checks.

Parameters and notation

Learned parameters: patch projection/residual layers, causal attention and feed-forward blocks, positional/frequency representations where used, and output head. Hyperparameters: input/output patch sizes, context/horizon, masking scheme, model width/depth, and adaptation rate. Patching reduces sequence length while potentially obscuring very short-scale variation.

Fitting, fine-tuning, and adaptation

Test frozen inference before fitting. For domain adaptation, use chronological training windows, consider output-head adaptation before broader unfreezing, and retain evaluation on series unseen during adaptation. Refit domain-specific normalization deliberately and verify that release-specific fine-tuning APIs support the intended head rather than silently substituting another model.

How to use and calibrate

Report horizon-specific errors, aggregated metrics with explicit scale weighting, inference cost, and baseline comparisons. If the chosen release outputs quantiles, test crossing and interval calibration separately. Evaluate rare events and short histories because aggregate average error can hide those limitations.

Example application

Inspect how an eight-value synthetic history becomes two four-step patches, then compare forecasts from a selected pretrained release against a seasonal-naive baseline in a separate experiment.

Interpretation / pitfalls

Watch out

Python: official TimesFM repository and release-matched instructions; R: reticulate with native scoring and plotting. The paired code only demonstrates deterministic input patching; it has no learned embedding, attention, pretrained weights, or forecasting head.

Python and R code examples (dependencies/validation)

Python uses NumPy and the shared mse helper when called; base R uses the shared helper when called. Validation: Python component executed; R companion reviewed, not executed. Scope: the specific component described above, not the full model or its training.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
import numpy as np

def mse(a,b):
    a,b=np.asarray(a),np.asarray(b)
    if a.shape!=b.shape or a.size==0:
        raise ValueError("MSE needs nonempty equal shapes")
    return float(np.mean((a-b)**2))
history=np.array([1.,2.,3.,4.,2.,3.,4.,5.]); patch_length=4
patches=history.reshape(-1,patch_length)
result={"patches":patches.tolist(),"patch_means":patches.mean(axis=1).tolist()}
print(result)
R

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
mse <- function(a,b) {
  stopifnot(length(a)>0L, identical(dim(a),dim(b)), length(a)==length(b))
  mean((a-b)^2)
}
history <- c(1,2,3,4,2,3,4,5); patch_length <- 4L
patches <- matrix(history,ncol=patch_length,byrow=TRUE)
result <- list(patches=patches,patch_means=rowMeans(patches))
print(result)

Sources

From the CodeSplash reference, entry SEQ015.