{"record":{"id":"8bb5c0d28c618cee","repo":"google-research/timesfm","slug":"model-is-not-compiled-please-call-compile-first","errorCode":null,"errorMessage":"Model is not compiled. Please call compile() first.","messagePattern":"Model is not compiled\\. Please call compile\\(\\) first\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/timesfm/timesfm_2p5/timesfm_2p5_base.py","lineNumber":160,"sourceCode":"\n  forecast_config: ForecastConfig | None = None\n  compiled_decode: Callable[..., Any] | None = None\n  global_batch_size: int = 0\n\n  def load_checkpoint(self, path: str):\n    \"\"\"Loads a TimesFM model from a checkpoint.\"\"\"\n    raise NotImplementedError()\n\n  def compile(self, forecast_config: ForecastConfig | None = None):\n    \"\"\"Compiles the TimesFM model for fast decoding.\"\"\"\n    raise NotImplementedError()\n\n  def forecast(\n    self, horizon: int, inputs: list[np.ndarray]\n  ) -> tuple[np.ndarray, np.ndarray]:\n    \"\"\"Forecasts the time series.\"\"\"\n    if self.compiled_decode is None:\n      raise RuntimeError(\"Model is not compiled. Please call compile() first.\")\n\n    assert self.global_batch_size > 0\n    assert self.forecast_config is not None\n\n    context = self.forecast_config.max_context\n    num_inputs = len(inputs)\n    if (w := num_inputs % self.global_batch_size) != 0:\n      inputs += [np.array([0.0] * 3)] * (self.global_batch_size - w)\n\n    output_points = []\n    output_quantiles = []\n    values = []\n    masks = []\n    idx = 0\n    for each_input in inputs:\n      value = linear_interpolation(strip_leading_nans(np.array(each_input)))\n      if (w := len(value)) >= context:\n        value = value[-context:]","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/google-research/timesfm/blob/331c6d33cb1ac2611de3056d0ac7164aab6301eb/src/timesfm/timesfm_2p5/timesfm_2p5_base.py#L142-L178","documentation":"`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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nmodel = TimesFMFlax(...); model.load_checkpoint(path)\npoint, quantiles = model.forecast(96, inputs)\n// after\nmodel = TimesFMFlax(...); model.load_checkpoint(path)\nmodel.compile(forecast_config=ForecastConfig(max_context=512, max_horizon=96, return_backcast=False))\npoint, quantiles = model.forecast(96, inputs)","handlingStrategy":"validation","validationCode":"if getattr(model, 'compiled_decode', True) is None:\n    model.compile(forecast_config=ForecastConfig(max_context=512, max_horizon=horizon))","typeGuard":"def is_compiled(model) -> bool:\n    return getattr(model, 'compiled_decode', None) is not None","tryCatchPattern":"try:\n    point, quantiles = model.forecast(horizon, inputs)\nexcept RuntimeError as e:\n    if 'not compiled' in str(e):\n        model.compile(forecast_config=ForecastConfig(max_context=512, max_horizon=horizon))\n        point, quantiles = model.forecast(horizon, inputs)\n    else:\n        raise","preventionTips":["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"],"tags":["python","runtime-state","compile-required"],"backgroundTag":"model-not-compiled","analyzedSha":"331c6d33cb1ac2611de3056d0ac7164aab6301eb","analyzedAt":"2026-08-29T01:04:23.138Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}