google-research/timesfm · error · RuntimeError
Model is not compiled. Please call compile() first.
Error message
Model is not compiled. Please call compile() first.
What it means
`forecast()` requires the model to have been compiled (`compile()` sets `compiled_decode`); since `compiled_decode` is None, forecasting cannot proceed. TimesFM compiles the JAX decode kernel up front for fast, shape-specialized decoding, so forecasting without compilation is unsupported. The library raises RuntimeError to enforce the required call order: load checkpoint -> compile -> forecast.
Source
Thrown at src/timesfm/timesfm_2p5/timesfm_2p5_base.py:160
forecast_config: ForecastConfig | None = None
compiled_decode: Callable[..., Any] | None = None
global_batch_size: int = 0
def load_checkpoint(self, path: str):
"""Loads a TimesFM model from a checkpoint."""
raise NotImplementedError()
def compile(self, forecast_config: ForecastConfig | None = None):
"""Compiles the TimesFM model for fast decoding."""
raise NotImplementedError()
def forecast(
self, horizon: int, inputs: list[np.ndarray]
) -> tuple[np.ndarray, np.ndarray]:
"""Forecasts the time series."""
if self.compiled_decode is None:
raise RuntimeError("Model is not compiled. Please call compile() first.")
assert self.global_batch_size > 0
assert self.forecast_config is not None
context = self.forecast_config.max_context
num_inputs = len(inputs)
if (w := num_inputs % self.global_batch_size) != 0:
inputs += [np.array([0.0] * 3)] * (self.global_batch_size - w)
output_points = []
output_quantiles = []
values = []
masks = []
idx = 0
for each_input in inputs:
value = linear_interpolation(strip_leading_nans(np.array(each_input)))
if (w := len(value)) >= context:
value = value[-context:]View on GitHub (pinned to 331c6d33cb)
Solutions
- Call `model.compile(forecast_config)` before the first `forecast()` call
- If the process restarted, re-create the model, re-run compile, then forecast
- If you intended covariates, call `forecast_with_covariates` after compile with return_backcast=True
Example fix
// before model = TimesFMFlax(...); model.load_checkpoint(path) point, quantiles = model.forecast(96, inputs) // after model = TimesFMFlax(...); model.load_checkpoint(path) model.compile(forecast_config=ForecastConfig(max_context=512, max_horizon=96, return_backcast=False)) point, quantiles = model.forecast(96, inputs)
Defensive patterns
Strategy: validation
Validate before calling
if getattr(model, 'compiled_decode', True) is None:
model.compile(forecast_config=ForecastConfig(max_context=512, max_horizon=horizon)) Type guard
def is_compiled(model) -> bool:
return getattr(model, 'compiled_decode', None) is not None Try / catch
try:
point, quantiles = model.forecast(horizon, inputs)
except RuntimeError as e:
if 'not compiled' in str(e):
model.compile(forecast_config=ForecastConfig(max_context=512, max_horizon=horizon))
point, quantiles = model.forecast(horizon, inputs)
else:
raise Prevention
- Make compile() part of model initialization right after load_checkpoint
- Guard against process restarts by re-running the full setup (load + compile)
- Add an is_compiled assertion in service startup/health checks
When it happens
Trigger: Calling `model.forecast(horizon, inputs)` (directly or via `forecast_with_covariates`) before ever calling `compile()`; constructing the model, loading a checkpoint, and immediately forecasting; re-instantiating the model in a new process and forgetting to recompile (compiled state is not persisted in the checkpoint).
Common situations: Notebook cells executed out of order after a kernel restart; a script that only loads the checkpoint; code paths that skip compile because an older TimesFM version forecasted without compilation.
Related errors
- For XReg, `return_backcast` must be set to True in the forec
- At least one of dynamic_numerical_covariates, dynamic_catego
- Unsupported mode: {xreg_mode}
- Forecast horizon length inferred from the dynamic covariates
- Context + horizon must be less than the context limit. {fc.m
AI-assisted analysis of google-research/timesfm@331c6d33cb (2026-08-29).
Data as JSON: /api/errors/8bb5c0d28c618cee.
Report an issue: GitHub.