What Is the Maximum Context Length for TimesFM 2.5? (16,384 Time‑Steps)
TimesFM 2.5 supports a maximum context length of 16,384 time‑steps, enforced by the context_limit parameter in the model architecture definition.
The maximum context length for TimesFM 2.5 represents a hard upper bound on how many historical observations the model can process in a single forward pass. According to the google-research/timesfm repository, this limit is hardcoded into the 2.5 architecture to govern memory usage and attention computation during both training and inference.
Where the Context Limit Is Defined in TimesFM 2.5
In src/timesfm/timesfm_2p5/timesfm_2p5_base.py, the model definition class TimesFM_2p5_200M_Definition sets the architectural constraint:
context_limit = 16384
This constant dictates that the self-attention mechanism can attend to at most 16,384 previous time‑steps. Attempting to feed a longer sequence into the compiled decode function would result in automatic truncation of the input tensor to this boundary.
How ForecastConfig.max_context Enforces the Limit at Inference
At runtime, the user-facing ForecastConfig class (defined in src/timesfm/configs.py) exposes a max_context parameter that must respect the architectural ceiling:
- Truncation: If the input series exceeds
max_context, the pipeline slices the most recentmax_contextobservations (i.e.,series[-max_context:]). - Padding: If the series is shorter, the pipeline pads the left side with zeros to reach the configured length before the compiled decode function executes.
The relationship is documented in the configuration file: max_context is described as the “maximum context length … used by the compiled decode function at inference time” [src/timesfm/configs.py#L25-L30].
Practical Implementation: Handling Long Time Series
When initializing a TimesFM 2.5 model, ensure your ForecastConfig does not exceed the 16,384 limit:
from timesfm.configs import ForecastConfig
from timesfm.timesfm_2p5.timesfm_2p5_torch import TimesFM_2p5_200M
import numpy as np
# Configure inference respecting the hard limit
cfg = ForecastConfig(
max_context=16_384, # Must be ≤ TimesFM 2.5's context_limit
max_horizon=1024,
normalize_inputs=True,
)
# Load the 200M-parameter variant
model = TimesFM_2p5_200M(cfg)
# Preprocessing helper to align series with the context window
def prepare_series(series):
"""Truncates or pads a 1-D array to fit max_context."""
if len(series) > cfg.max_context:
return series[-cfg.max_context:] # Keep most recent history
else:
pad_width = cfg.max_context - len(series)
return np.pad(series, (pad_width, 0), mode='constant')
This pattern ensures that the TimesFM_2p5_200M model receives tensors of exactly the expected shape, preventing runtime errors or silent data loss beyond the 16,384‑step boundary.
Summary
- Hard limit: TimesFM 2.5’s architecture enforces
context_limit = 16384intimesfm_2p5_base.py. - Configuration:
ForecastConfig.max_contextcontrols truncation and padding but cannot exceed 16,384. - Truncation behavior: Long series are automatically truncated to the most recent 16,384 observations.
- Padding behavior: Short series are zero‑padded on the left to reach the configured context length.
Frequently Asked Questions
What happens if I provide a time series longer than 16,384 steps?
The inference pipeline automatically truncates the input to the most recent 16,384 observations. According to the source code in timesfm_2p5_base.py, any additional historical data is discarded before the model’s compiled decode function processes the tensor.
Can I increase the maximum context length beyond 16,384?
No. The context_limit = 16384 is a fixed architectural constant in TimesFM_2p5_200M_Definition. Modifying this value would require retraining the model with a different attention window, as the current weights and positional encodings are bound to this specific dimension.
Does the 200M parameter variant have a different context limit?
The analysis of TimesFM_2p5_200M_Definition shows that the 200M variant uses the same context_limit = 16384 as the base 2.5 architecture. There is no evidence in the repository of a variant with an expanded context window for this release.
How does padding work for short series in TimesFM 2.5?
When a series contains fewer than max_context observations, the preprocessing logic pads the left side (earlier time steps) with zeros to reach the full context length. This ensures the tensor shape matches the model’s input expectations while preserving the most recent actual data at the rightmost positions.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →