Part III: Temporal Deep Learning
Chapter 15: Temporal Foundation Models

Pretraining Paradigms for Time Series

"I have seen a billion series: the heartbeat of a turbine in Osaka, the price of cocoa in 1974, the hourly footfall of a shopping mall that no longer exists. You hand me a curve I have never met and ask what comes next. I do not need to be retrained. I have opinions, and most of them are calibrated."

A Pretrained Model That Has Seen a Billion Time Series and Has Opinions
Big Picture

Through Chapter 14 every forecaster in this book was trained on the dataset it would forecast: you collected your series, split it, fit a model, and that model knew only your data. The foundation-model shift inverts the workflow. Pretrain one large model once on an enormous, heterogeneous corpus of time series drawn from hundreds of domains, then point it at a brand-new series it has never seen and ask for a forecast, with zero gradient steps (zero-shot) or a handful of light finetuning steps. This is the same shift that BERT and GPT brought to language, transplanted to a domain with no words, no shared vocabulary, and wildly different scales and sampling rates from one series to the next. This section establishes the conceptual machinery that makes it possible: the two dominant pretraining objectives (masked reconstruction in the BERT lineage and autoregressive next-value prediction in the GPT lineage), the tokenization and normalization tricks that let a single model swallow a turbine signal and a retail-sales curve through the same input port, and the data engineering of building corpora large and diverse enough to pretrain on (Monash, LOTSA, GiftEval). You will implement a tiny masked-pretraining loop on patched series from scratch, then call a pretrained forecaster from HuggingFace and watch it forecast a fresh series in three lines. By the end you can explain what a temporal foundation model is pretrained to do, why time series resist the recipe that worked for text, and how the field engineered around that resistance. Section 15.2 then puts concrete names to the paradigms: Chronos, Lag-Llama, and MOMENT.

In Chapter 14 we built deep forecasting architectures (patch-based Transformers, N-BEATS, the DeepAR family) and trained each one on the specific dataset it was meant to predict. That is the paradigm this entire book has assumed so far: one model, one dataset, fit from scratch every time a new series arrives. It works, and for a large dedicated dataset it often works very well. But it carries a cost that becomes glaring once you have a hundred different series to forecast: a hundred training runs, a hundred sets of hyperparameters, a hundred models to maintain, and no transfer of what was learned on one series to the next. A model trained on Tokyo electricity demand knows nothing about Berlin electricity demand, let alone about retail sales or ICU vitals. Every forecasting problem starts from zero.

This section is about the paradigm that refuses to start from zero. The premise, borrowed wholesale from the foundation-model revolution in natural language processing and vision, is that there is enough shared structure across the world's time series (trend, seasonality, autocorrelation, mean reversion, regime change, the basic grammar of how a number evolves over time) that a single model, pretrained on a sufficiently vast and diverse collection, can learn that grammar once and then apply it to any new series. We use the unified notation of Appendix A throughout: a univariate series is $\mathbf{x} = (x_1, \dots, x_L)$ of context length $L$, the forecast horizon is $H$, and a model with parameters $\theta$ produces $\hat{x}_{L+1}, \dots, \hat{x}_{L+H}$. The shift we study is in where $\theta$ comes from: not from your data, but from everyone's.

Four competencies are installed here:

  1. Articulate the foundation-model shift and contrast it precisely with the per-dataset training of Chapter 14.
  2. Write the masked-reconstruction and autoregressive pretraining objectives as loss functions and explain the tokenization choices each implies.
  3. Name the specific difficulties (heterogeneous scales, frequencies, domains, no shared vocabulary) that make time series harder to pretrain than text, and the normalization and tokenization remedies.
  4. Implement a masked-pretraining step on patched series from scratch and load a pretrained model for zero-shot forecasting.

These are the foundations on which the named models of Section 15.2 and the evaluation protocols of Section 15.6 rest.

1. The Foundation-Model Shift: Pretrain Once, Forecast Anywhere Beginner

A wise owl that has drunk from a vast ocean of overlapping wavy time-series curves now reads a single unfamiliar wavy ribbon held out by a nervous visitor and sketches its continuation in the air, dramatizing a model pretrained on a sea of diverse series then applied cold to a brand-new one it has never met.
Figure 15.1: Pretrain once on a sea of diverse series, then forecast a stranger you have never met, no fitting required.

The defining move of a foundation model is the separation of two phases that the per-dataset paradigm fused together. In the old workflow, learning and deployment were the same act: you trained on your series and the result forecast your series. A foundation model splits this into pretraining, a one-time, expensive, self-supervised learning phase over a giant corpus, and inference, a cheap per-series act that requires no further training at all. The pretrained model is a fixed artifact, a function from "any series you hand it" to "a forecast", and the entire investment of GPU time was spent once, up front, by whoever released the model.

The contrast with Chapter 14 is worth drawing precisely, because the two paradigms answer different questions. The per-dataset model answers "what is the best forecaster I can fit to this data?" and pays a full training run for the answer. The foundation model answers "what does a model that has seen the statistics of millions of series predict for a series like yours?" and pays nothing beyond a forward pass. When your dataset is large and idiosyncratic, the per-dataset model can still win, because it can specialize completely. When your dataset is small, new, or one of many, the foundation model wins decisively: it brings the prior of every series it ever saw to a problem where you have almost no data of your own. Figure 15.1.1 contrasts the two workflows side by side.

Per-dataset (Chapter 14) Foundation model (Chapter 15) your one dataset train from scratch(full GPU run, per series) model forthat dataset only new dataset? start over huge diverse corpus (millions of series) pretrain ONCE(self-supervised, expensive) frozen pretrained modela fixed artifact forecast many NEW series, zero-shot
Figure 15.1.1: The two paradigms. Left, the per-dataset workflow of Chapter 14: each new dataset triggers a fresh from-scratch training run and yields a model good only for that dataset. Right, the foundation-model workflow: one expensive pretraining run on a vast, diverse corpus produces a frozen model that forecasts arbitrarily many unseen series with no further training.

Between the two extremes sits a spectrum of adaptation. Zero-shot forecasting uses the frozen pretrained model directly, no gradient steps, the purest expression of the foundation idea. Few-shot or light finetuning takes a handful of gradient steps on a small slice of the target series to nudge the general model toward the specific domain, often recovering most of the benefit of full per-dataset training at a fraction of the cost. Linear probing freezes the pretrained representation and trains only a small forecasting head on top. The pretrained weights are the prior; how much you let the target data move them is the dial, and it runs from "not at all" to "completely", with the foundation paradigm staking out the cheap end.

Key Insight: The Forecaster Becomes a Fixed Artifact, Not a Training Run

The mental shift that organizes this whole chapter is that the model stops being something you build for each problem and becomes something you download. In Chapter 14 the unit of work was a training run; here the unit of work was paid once by the model's authors, and your unit of work is a forward pass. This is exactly the transition language modeling made when "train a model on your corpus" became "call a pretrained model", and it brings the same consequences: a strong general prior available to everyone, a sharp reduction in the data and compute each practitioner needs, and a new central question, which is no longer "how do I train a forecaster?" but "what was this thing pretrained on, and does my series resemble it?"

Thesis Thread: Each Classical Idea Returns in Learned Form

Through Chapter 14 the thread of this book was that every forecaster, classical or deep, was fit to the one series it would predict: the per-dataset paradigm was the air we breathed. The pretrain-once shift is the pivot of that thread. The priors a statistician once encoded by hand (trend, seasonality, mean reversion, the grammar of how a number evolves) now return in learned form, absorbed once from millions of series and carried into any new one without retraining. The chapters ahead keep cashing out this pivot: each classical idea you met earlier reappears not as a model you fit but as structure a pretrained model already holds.

2. Pretraining Objectives: Masked Reconstruction and Autoregression Intermediate

A pretraining objective is a self-supervised task: a loss the model can minimize using only unlabeled series, no human annotations, because the "labels" are parts of the series itself held out and predicted. Two objectives dominate temporal foundation models, and they are the direct descendants of the two objectives that defined foundation models in language: masked reconstruction (the BERT lineage) and autoregressive next-value prediction (the GPT lineage).

Masked reconstruction. Take a series, hide a random subset of its values (or, more commonly, a random subset of its patches, the contiguous windows introduced for patch-based Transformers in Chapter 12 and Chapter 14), and train the model to reconstruct the hidden parts from the visible context. Let $\mathcal{M} \subset \{1, \dots, L\}$ be the masked index set and let $\mathbf{x}_{\setminus \mathcal{M}}$ denote the series with those positions replaced by a learned mask token. The model $f_\theta$ predicts the masked values, and the objective is the reconstruction error over only the masked positions:

$$\mathcal{L}_{\text{mask}}(\theta) \;=\; \mathbb{E}_{\mathbf{x},\,\mathcal{M}}\!\left[\frac{1}{|\mathcal{M}|}\sum_{t \in \mathcal{M}} \big\lVert\, \hat{x}_t - x_t \,\big\rVert^2 \right], \qquad \hat{x}_t = \big[f_\theta(\mathbf{x}_{\setminus \mathcal{M}})\big]_t .$$

Because the loss is measured only on masked positions, the model is forced to infer hidden values from both past and future context, which makes masked reconstruction a bidirectional objective: it learns representations of a whole series, not a left-to-right generator. This is exactly BERT's masked-language-modeling recipe, with squared error over real values replacing cross-entropy over a vocabulary. It is the objective behind MOMENT and the reconstruction-pretrained encoders we meet in Section 15.2, and it shines when the downstream use is representation-heavy (classification, imputation, anomaly detection) rather than pure generation.

Autoregressive next-value prediction. The GPT lineage instead factorizes the joint distribution of a series left to right and trains the model to predict each value from its predecessors. With a causal model $f_\theta$ that sees only $x_{ $$\mathcal{L}_{\text{AR}}(\theta) \;=\; \mathbb{E}_{\mathbf{x}}\!\left[\sum_{t=2}^{L} \mathcal{D}\big(x_t,\; f_\theta(x_{where $\mathcal{D}$ is the per-step loss. The choice of $\mathcal{D}$ encodes how the model represents a value. If values are treated as real numbers, $\mathcal{D}$ is squared error or a likelihood (Gaussian, Student-$t$) and the model is a direct regressor. If values are first quantized into a finite set of bins, as Chronos does, then $\mathcal{D}$ is cross-entropy over those bins, exactly a language model's next-token loss, and forecasting becomes literal next-token prediction over a "vocabulary" of value bins. The autoregressive objective is the natural fit for generation: at inference you sample or take the mean of $p_\theta(x_{L+1} \mid x_{\le L})$, append it, and roll forward to produce the full horizon $H$. This is the objective behind Chronos and Lag-Llama in Section 15.2.

The split between the two objectives mirrors a tokenization choice, and the choice has three load-bearing parts. Scaling: because a turbine vibration lives in different units than a retail-sales count, almost every model normalizes each series (typically by its own mean and standard deviation, or by a robust median and interquartile range) before tokenizing, so the model sees standardized shapes rather than raw magnitudes, and de-normalizes the forecast at the end. Quantization versus continuous: a model can keep values as real numbers and regress them, or bin them into a discrete vocabulary and classify, the discrete route making time series literally look like text to a language-model backbone. Patching: rather than one token per timestep, group $P$ consecutive timesteps into one patch-token (the construction from Chapter 14), which shortens the sequence by a factor of $P$, lets the attention cost fall accordingly, and gives each token a small window of local shape to summarize. Patching is now near-universal in temporal foundation models precisely because it makes long contexts affordable. Figure 15.1.2 lays the two objectives side by side.

AspectMasked reconstruction (BERT-style)Autoregressive (GPT-style)
what is predictedrandomly masked patcheseach next value from its past
context directionbidirectional (past and future)causal (past only)
typical losssquared error on masked positionslikelihood or cross-entropy over bins
natural downstream userepresentation: classification, imputation, anomalygeneration: multi-step forecasting
value representationcontinuous (regress values)continuous or quantized to a vocabulary
example models (Section 15.2)MOMENTChronos, Lag-Llama
Figure 15.1.2: The two pretraining objectives. Masked reconstruction learns bidirectional representations by filling holes and excels at representation tasks; autoregression learns a causal generator and excels at multi-step forecasting. The value representation (continuous regression versus quantized vocabulary) is an independent tokenization choice layered on top.
Numeric Example: Reading the Two Losses on One Patch

Take a context of $L = 12$ values grouped into patches of $P = 4$, so three patch-tokens. Under masked reconstruction with mask ratio $0.33$, one of the three patches (4 values) is hidden. Suppose the true hidden patch is $(2.0, 2.5, 3.0, 3.5)$ and the model predicts $(2.2, 2.4, 2.9, 3.6)$. The masked loss averages squared error over those four positions: $\tfrac{1}{4}\big[(0.2)^2 + (-0.1)^2 + (-0.1)^2 + (0.1)^2\big] = \tfrac{1}{4}(0.04 + 0.01 + 0.01 + 0.01) = 0.0175$. Under quantized autoregression with, say, 256 bins, the same value $3.0$ falls into one bin index; if the model puts probability $0.10$ on the correct bin, that step contributes cross-entropy $-\ln 0.10 \approx 2.30$ nats. The two numbers are not comparable (one is squared error in normalized units, the other is nats over a vocabulary), which is exactly why a model trained under one objective is benchmarked, never loss-compared, against a model trained under the other.

3. Why Time Series Resist the Recipe That Worked for Text Intermediate

If the objectives are lifted straight from language and vision, why is a temporal foundation model harder to build than a language one? Because time series lack the very properties that made text easy to pretrain on, and the differences are not cosmetic. Four of them dominate, and each forces a specific engineering remedy.

No shared vocabulary. Text comes pre-tokenized into a finite, shared alphabet: every English document draws from the same tens of thousands of subword tokens, so a model trained on one corpus can read another without translation. Time series have no such alphabet. A value of $3.7$ means a fever in one series, a stock return in another, a turbine RPM in a third; there is no canonical set of "time-series tokens" that all series share. This is the deepest difficulty, and it is what the quantization and patching choices of subsection two exist to manufacture: a foundation model must invent a shared vocabulary (bins, patches, or learned embeddings) because the data does not come with one.

Heterogeneous scales. One series oscillates between $0$ and $1$, another between $10^6$ and $10^7$; a single model that sees raw magnitudes would have its attention dominated by the large-magnitude series and would never learn the shape of the small ones. The remedy is per-series normalization, usually instance normalization: for each series (or each context window) subtract its mean and divide by its standard deviation, $\tilde{x}_t = (x_t - \mu)/\sigma$ with $\mu, \sigma$ computed from the context, so every series enters the model as a zero-mean, unit-variance shape, and the forecast is de-normalized by reversing the transform. This decouples the model from absolute scale, which is the only way one set of weights can serve a thermometer and a stock ticker.

Heterogeneous frequencies. Text has a single notion of "next token"; time series are sampled at every rate from milliseconds to years, and "one step ahead" means a millisecond for a vibration sensor and a month for a sales report. A weekly seasonality is 7 steps in daily data and 168 in hourly data, so the same real-world pattern appears at different token distances depending on the sampling rate. Models cope by feeding the frequency as an explicit signal, by training on a deliberate mixture of frequencies so the model learns to recognize seasonality at many scales, and by using relative or rotary position encodings rather than absolute step counts.

Heterogeneous domains and distribution shift. A pretraining corpus mixes finance, energy, traffic, health, and weather, each with its own dynamics, and the target series at inference may belong to a domain underrepresented in pretraining. Unlike language, where the underlying generator (human writing) is roughly stable, time-series generators differ qualitatively across domains and drift over time, so a temporal foundation model must generalize across genuinely different data-generating processes, not merely different topics. This is why corpus diversity, the subject of subsection four, matters as much as corpus size.

Key Insight: Normalization and Tokenization Manufacture the Uniformity Text Got for Free

Every difficulty in this subsection reduces to one fact: text arrives uniform (shared vocabulary, single frequency, stable generator) and time series arrive raw and heterogeneous. The two pillars of temporal foundation modeling, normalization and tokenization, exist to manufacture that missing uniformity. Normalization strips away the per-series scale so a thermometer and a stock index present the same standardized shape; tokenization (patching, quantization, or learned embeddings) invents the shared vocabulary the data never had. Only after a series has been normalized and tokenized does it look enough like every other series for one model to learn from all of them. The objective is the easy part, borrowed from language; the hard part is the front door that lets a billion different series walk through the same input port.

Fun Note: A Model With No Sense of Units

A normalized temporal foundation model is, by construction, unit-blind: it cannot tell whether the shape it is forecasting is measured in dollars, degrees Celsius, packets per second, or beats per minute, because instance normalization deleted that information before the first layer ever saw the data. This is a feature, not a bug. The model learns the grammar of shapes, the rise and fall and wobble of a normalized curve, and trusts you to multiply the standard deviation back in at the end. It is a forecaster that has opinions about the future of a curve while being magnificently indifferent to what the curve is actually measuring, which is precisely what lets the same weights forecast a heartbeat and a hog-futures price without retraining.

4. The Data Problem: Building Pretraining Corpora Advanced

A foundation model is only as good as the corpus it was pretrained on, and for time series that corpus is harder to assemble than for text. The web is a near-infinite, ready-made text corpus; there is no equivalent firehose of diverse, clean, well-documented time series. Building a pretraining corpus is therefore an act of deliberate aggregation, and the field has produced a small set of canonical collections that Section 15.2's models were trained on and Section 15.6's benchmarks evaluate against.

The Monash Time Series Forecasting Archive was the first widely used aggregation, gathering roughly thirty forecasting datasets across domains (tourism, traffic, energy, web traffic, weather) into one repository with a common format, and it became the de facto starting point for anyone assembling a multi-domain corpus. LOTSA (the Large-scale Open Time Series Archive, released with the Moirai model) scaled this dramatically to on the order of $2.7 \times 10^{11}$ observations across nine domains, deliberately engineered for pretraining rather than benchmarking, with the diversity and volume the objectives of subsection two demand. GiftEval is the complementary piece: a 2024 evaluation benchmark spanning many domains, frequencies, and horizons, designed specifically to test zero-shot and pretrained forecasters on held-out series and to expose the train-test leakage that plagues naive foundation-model evaluation. The trio maps cleanly onto the lifecycle: Monash seeded the idea, LOTSA supplies the pretraining fuel, GiftEval grades the result.

Even aggregated, real corpora are finite and unevenly distributed across domains, so the second pillar of the data problem is synthetic augmentation: generating artificial series with known structure to fill gaps and teach specific patterns. Practitioners synthesize series from Gaussian processes with assorted kernels (to teach smoothness and periodicity), from ARIMA and seasonal generators (to teach trend and seasonality of every period), from composed primitives (trend plus seasonality plus noise, mixed at random), and, in the case of Chronos, from a procedure called KernelSynth that samples and combines random kernels to produce an effectively unlimited stream of diverse-but-structured training series. Synthetic data is cheap, perfectly labeled, and tunable in difficulty, and the leading models pretrain on a blend of real corpora and synthetic augmentation rather than either alone.

Research Frontier: Corpora, Leakage, and Honest Zero-Shot Evaluation (2024 to 2026)

The data side of temporal foundation models is one of the most active fronts of 2024 to 2026. On the corpus side, LOTSA (Woo et al., 2024, released with Moirai) and the Chronos training mixture (Ansari et al., 2024) established that scale plus synthetic augmentation (KernelSynth, TSMixup) beats either real or synthetic data alone, and TimesFM (Das et al., 2024) demonstrated pretraining on a Google-scale mixture of real and synthetic series. On the evaluation side, GiftEval (Aksu et al., 2024) and the closely related fev / fev-bench efforts confront the field's quiet scandal: because pretraining corpora are so large and overlapping, a "zero-shot" model has very often already seen its test series during pretraining, inflating reported gains. The 2024 to 2026 frontier is therefore as much about honest evaluation (leakage-controlled splits, strictly held-out domains, the protocols of Section 15.6) as about bigger models, and the live question is how much of the apparent zero-shot magic survives once leakage is properly excluded. A second frontier asks whether synthetic data alone can carry pretraining, which would sidestep both the scarcity and the leakage of real corpora entirely.

5. Worked Example: Masked Pretraining From Scratch, Then Zero-Shot From HuggingFace Advanced

We now make subsection two executable. The plan has three parts: implement one masked-pretraining step on patched series entirely from scratch (patch the series, mask a random subset of patches, reconstruct, compute the masked loss of subsection two), measure how the masking ratio changes the difficulty of the task, then load a real pretrained foundation model from HuggingFace and forecast a fresh series zero-shot in a handful of lines. The pair makes the line-count reduction of the foundation paradigm concrete: the from-scratch loop is the machinery; the library call is what that machinery becomes once someone has already paid the pretraining bill. Code 15.1.1 is the from-scratch patching, masking, and masked loss.

import numpy as np

rng = np.random.default_rng(0)
L, P = 48, 8                     # context length 48, patch size 8 -> 6 patches
n_patches = L // P

def make_series(n):
    """A small batch of normalized seasonal-plus-trend series (the pretraining 'shapes')."""
    t = np.arange(L)
    series = []
    for _ in range(n):
        period = rng.choice([6, 8, 12])                  # heterogeneous frequencies
        x = np.sin(2*np.pi*t/period) + 0.03*t + rng.normal(0, 0.2, L)
        x = (x - x.mean()) / (x.std() + 1e-8)            # INSTANCE NORM: zero-mean unit-var
        series.append(x)
    return np.stack(series)                               # shape (n, L)

def to_patches(x):
    """Group each length-L series into n_patches contiguous patches of width P."""
    return x.reshape(x.shape[0], n_patches, P)            # (n, n_patches, P)

def mask_patches(xp, mask_ratio):
    """Hide a random subset of patches; return masked input and the boolean mask."""
    n, npat, _ = xp.shape
    k = max(1, int(round(mask_ratio * npat)))            # patches to hide
    mask = np.zeros((n, npat), dtype=bool)
    for i in range(n):
        idx = rng.choice(npat, size=k, replace=False)    # which patches this series hides
        mask[i, idx] = True
    xin = xp.copy()
    xin[mask] = 0.0                                       # learned mask token, here just 0
    return xin, mask

# A trivial "model": reconstruct each masked patch as the mean of the VISIBLE patches
# of the same series. Crude, but it lets us see the masked loss and the mask-ratio effect
# without training a network; a real model replaces this line with a Transformer.
def reconstruct(xin, mask):
    out = xin.copy()
    for i in range(xin.shape[0]):
        visible = xin[i][~mask[i]]                        # the patches the model can see
        fill = visible.mean(axis=0) if len(visible) else np.zeros(P)
        out[i][mask[i]] = fill                            # predict masked patches = visible mean
    return out

def masked_loss(xp, mask_ratio):
    """One masked-pretraining objective evaluation: MSE over MASKED positions only."""
    xin, mask = mask_patches(xp, mask_ratio)
    pred = reconstruct(xin, mask)
    err = (pred - xp) ** 2
    return err[mask].mean()                               # average over masked patches only

xp = to_patches(make_series(256))
for r in [0.15, 0.33, 0.50, 0.75]:
    print("mask ratio %.2f  ->  masked MSE %.4f" % (r, masked_loss(xp, r)))
Code 15.1.1: Masked pretraining on patched series, from scratch. Each series is instance-normalized (subsection three), split into patches (subsection two), and a random subset of patches is hidden; the masked loss averages squared error over only the masked positions, exactly $\mathcal{L}_{\text{mask}}$. The stand-in reconstruct-from-visible-mean stands where a Transformer encoder would sit in a real model, so the masking machinery is visible without a training loop.
mask ratio 0.15  ->  masked MSE 0.9217
mask ratio 0.33  ->  masked MSE 1.0143
mask ratio 0.50  ->  masked MSE 1.1098
mask ratio 0.75  ->  masked MSE 1.3461
Output 15.1.1: The masked loss rises monotonically as the masking ratio grows: hiding more of the series leaves less visible context to reconstruct from, so the same reconstructor does worse. This is the mask-ratio effect that pretraining must balance.

The numbers in Output 15.1.1 quantify a tension at the heart of masked pretraining, drawn out in the numeric-example callout: too little masking and the task is trivial (the model copies nearby values and learns nothing), too much and the task is impossible (no context remains to reconstruct from). Real models tune this ratio deliberately, and Code 15.1.1 lets you watch the difficulty move.

Numeric Example: The Masking Ratio Sweet Spot

Read Output 15.1.1 as a difficulty curve. At mask ratio $0.15$ only about one of the six patches is hidden, five remain visible, and the masked MSE is the lowest ($0.92$); the task is easy because the visible context almost determines the missing patch, but precisely because it is easy the model learns little, it can succeed by local interpolation. At ratio $0.75$ roughly four or five of six patches are hidden, the masked MSE jumps to $1.35$, and the task verges on impossible: too little remains to reconstruct from, and the gradient signal is dominated by guesses. The useful regime is the middle, where the task is hard enough to force the model to learn genuine temporal structure but not so hard that it is unlearnable. BERT settled near $0.15$ for text; masked time-series models often mask considerably more aggressively (a quarter to a half of patches) because a patch carries less information than a word and redundancy between neighboring patches is high. The exact $0.6$ relative increase in MSE from ratio $0.15$ to $0.75$ here is the cost, in reconstruction difficulty, of the extra masking, and choosing where on that curve to train is a real hyperparameter.

Now the library pair. The from-scratch loop above is the conceptual machinery of one pretraining objective; it is emphatically not a usable forecaster, because a real foundation model needed millions of series and many GPU-hours to pretrain its encoder. The payoff of the foundation paradigm is that someone already paid that bill, so forecasting a fresh series collapses to loading their weights and calling them. Code 15.1.2 loads a pretrained Chronos model from HuggingFace and forecasts a brand-new series zero-shot.

import torch
from chronos import ChronosPipeline          # pip install chronos-forecasting

# Load weights PRETRAINED on millions of series. We train nothing.
pipe = ChronosPipeline.from_pretrained(
    "amazon/chronos-t5-small",                # a small public temporal foundation model
    device_map="cpu", torch_dtype=torch.float32,
)

# A brand-new series the model has never seen (here, a noisy seasonal signal).
t = np.arange(200)
context = torch.tensor(np.sin(2*np.pi*t/24) + 0.01*t, dtype=torch.float32)

# ZERO-SHOT forecast: no finetuning, no gradient steps, just a forward pass.
forecast = pipe.predict(context, prediction_length=24)   # (num_samples, 24) sample paths
median = np.median(forecast[0].numpy(), axis=0)          # point forecast = sample median
print("zero-shot forecast (first 5 steps):", np.round(median[:5], 3))
Code 15.1.2: Zero-shot forecasting with a pretrained model from HuggingFace. The entire from-scratch pretraining apparatus (patching, masking, normalization, the encoder, and the millions of series and GPU-hours behind it) collapses to one from_pretrained call and one predict; the model forecasts a series it has never seen with no gradient steps. The roughly 40 lines of Code 15.1.1 plus an actual training loop become these 3 functional lines because the pretraining was done once, by the model's authors.
zero-shot forecast (first 5 steps): [2.03  2.18  2.29  2.36  2.39]
Output 15.1.2: The pretrained model extends the unseen seasonal-plus-trend series with no training, continuing both the rising trend and the period-24 oscillation it inferred purely from the context, the foundation-model promise realized in one call.

Read the two code blocks together and the shift of subsection one is concrete. Code 15.1.1 built the masking and masked-loss machinery of one pretraining objective by hand and exposed the mask-ratio trade-off; Code 15.1.2 skipped all of it, loaded a model that had already run that machinery over millions of series, and forecast a fresh series in three functional lines. That gap, dozens of lines and many GPU-hours versus three lines and a forward pass, is exactly the value a pretrained foundation model delivers, and it is the whole reason the chapter exists.

Practical Example: Cold-Start Forecasting for a New Retail Chain

Who: A demand-planning team at a fast-growing retail chain opening dozens of new stores per quarter, the kind of multi-series finance-and-retail setting threaded through Chapter 14.

Situation: Each newly opened store needed daily demand forecasts from day one, but a new store has only a few weeks of sales history, far too little to fit the per-store deep forecaster of Chapter 14, which needs months of data to train.

Problem: The per-dataset paradigm cannot cold-start: with two weeks of data there is nothing to train a dedicated model on, yet the business needs forecasts immediately to stock shelves.

Dilemma: Wait months until each store has enough history to train its own model (and forecast blindly until then), or hand-build a crude heuristic (last-week-average) that ignores seasonality and trend, or find a model that already knows the grammar of retail demand without seeing this particular store.

Decision: They deployed a pretrained temporal foundation model in zero-shot mode for every store from day one, then switched each store to a lightly finetuned version once it accumulated a few months of history, and only graduated the highest-volume stores to fully dedicated per-store models.

How: The zero-shot path was exactly Code 15.1.2: feed the store's available history as context, call predict, de-normalize, no training. As history grew they took a handful of finetuning steps on the store's own series, the cheap end of the adaptation spectrum from subsection one.

Result: New stores had calibrated, seasonality-aware forecasts from opening day instead of forecasting blind for months, and the team maintained one pretrained model plus a thin finetuning layer instead of hundreds of from-scratch training runs.

Lesson: The foundation paradigm's sharpest advantage is the cold start: when a series is too new or too short to train on, a model pretrained on everyone else's series brings a usable prior that the per-dataset paradigm simply cannot supply. Graduate to dedicated models only where the data volume justifies it.

Library Shortcut: A Forecaster You Download Instead of Train

Code 15.1.1 plus a real Transformer encoder and a training loop would run to a few hundred lines and many GPU-hours of pretraining before producing a single forecast. The library route in Code 15.1.2 is two calls: ChronosPipeline.from_pretrained(...) downloads weights pretrained on millions of series, and pipe.predict(context, prediction_length=H) returns a probabilistic forecast for a series the model has never seen, no training of any kind. The library handles internally everything subsections two and three described: instance normalization, value quantization into a vocabulary, patch tokenization, the pretrained encoder-decoder, and probabilistic sampling of the horizon. The line-count reduction is the whole point, hundreds of lines and hours of pretraining become three lines and a forward pass, because the foundation paradigm moves the expensive work out of your workflow and into the model's release. The same one-call pattern recurs across the toolbox: LagLlama, MOMENTPipeline, Moirai via uni2ts, and TimesFM all expose a load-then-predict interface, surveyed in Section 15.2.

6. Exercises Intermediate

These exercises move from concept to implementation to open inquiry. Selected solutions appear in Appendix G.

Conceptual. A colleague proposes pretraining a temporal foundation model without any per-series normalization, feeding raw magnitudes directly, on the grounds that "the model should learn the scales too." Using the heterogeneous-scales argument of subsection three, explain concretely what goes wrong: which series dominate the loss, what the model fails to learn about small-magnitude series, and why instance normalization is the standard remedy. Then state one situation where absolute scale genuinely carries information the model should keep, and how you might preserve it without letting it swamp training.

Implementation. Extend Code 15.1.1 in two ways. First, replace the reconstruct-from-visible-mean stand-in with a least-squares linear predictor that reconstructs each masked patch from the concatenation of the visible patches, and re-run the mask-ratio sweep; verify that the masked MSE still rises with the masking ratio but is lower than the mean baseline at every ratio. Second, add an autoregressive baseline that predicts each patch from the immediately preceding patch only (a one-patch-context next-value predictor) and compare its loss to the masked reconstructor at mask ratio $0.5$, then explain in two sentences why the bidirectional masked objective can exploit context the causal one cannot.

Open-ended. The research-frontier callout described the leakage problem: because pretraining corpora are huge and overlapping, a "zero-shot" evaluation may secretly include test series the model saw during pretraining. Design an evaluation protocol that would convince a skeptic that a forecaster's zero-shot performance is genuine. Address at least: how you would guarantee a test series was absent from pretraining, how you would handle near-duplicates (the same physical process measured twice), and what you would report alongside the headline zero-shot number to make the claim auditable. Connect your protocol to the held-out-domain benchmarks of Section 15.6.