timesfm
Librarygoogle-research/timesfm
Pretrained foundation model for time series forecasting by Google Research.
Overview
TimesFM is a pretrained decoder-only foundation model for time-series forecasting developed by Google Research. It supports long context lengths and continuous quantile forecasting, available in PyTorch and Flax.
README Preview
# TimesFM\n\nTimesFM (Time Series Foundation Model) is a pretrained time-series foundation\nmodel developed by Google Research for time-series forecasting.\n\n* Paper:\n [A decoder-only foundation model for time-series forecasting](https://arxiv.org/abs/2310.10688),\n ICML 2024.\n* All checkpoints:\n [TimesFM Hugging Face Collection](https://huggingface.co/collections/google/timesfm-release-66e4be5fdb56e960c1e482a6).\n* [Google Research blog](https://research.google/blog/a-decoder-only-foundation-model-for-time-series-forecasting/).\n* TimesFM in Google 1P Products:\n * [BigQuery ML](https://cloud.google.com/bigquery/docs/timesfm-model): Enterprise level SQL queries for scalability and reliability.\n * [Google Sheets](https://workspaceupdates.googleblog.com/2026/02/forecast-data-in-connected-sheets-BigQueryML-TimesFM.html): For your daily spreadsheet. \n * [Vertex Model Garden](https://pantheon.corp.google.com/vertex-ai/publishers/google/model-garden/timesfm): Dockerized endpoint for agentic calling.\n\nThis open version is not an officially supported Google product.\n\n**Latest Model Version:** TimesFM 2.5\n\n**Archived Model Versions:**\n\n- 1.0 and 2.0: relevant code archived in the sub directory `v1`. You can `pip\n install timesfm==1.3.0` to install an older version of this package to load\n them.\n## Update - June 5, 2026\n\nUpdated PyPI to `timesfm=2.0.0`. See [Install](https://github.com/google-research/timesfm#from-pypi).\n\n## Update - Apr. 9, 2026\n\nAdded fine-tuning example using HuggingFace Transformers + PEFT (LoRA) — see\n[`timesfm-forecasting/examples/finetuning/`](timesfm-forecasting/examples/finetuning/).\nAlso added unit tests (`tests/`) and incorporated several community fixes.\n\nShoutout to [@kashif](https://github.com/kashif) and [@darkpowerxo](https://github.com/darkpowerxo). \n\n## Update - Mar. 19, 2026\n\nHuge shoutout to [@borealBytes](https://github.com/borealBytes) for adding the support for [AGE
FAQ (4)
TroubleshootingWhy does torch_compile=True have no effect in TimesFM PyTorch, and how do I make torch.compile speed up inference?
The no-op is caused by self = torch.compile(self) inside load_checkpoint: self is a local variable, so rebinding it does not change the model object returned by from_pretrained.
Apply the fix from PR #459, or compile forward directly after loading:
model = timesfm.TimesFM_2p5_200M_torch.from_pretrained(
"google/timesfm-2.5-200m-pytorch"
)
model.model.forward = torch.compile(model.model.forward)
Equivalently, replace the ineffective line in timesfm_2p5_torch.py with:
self.model.forward = torch.compile(self.model.forward)
The KV-cache slice assignment still causes graph breaks, but the attention and MLP matmuls are compiled, so inference is faster. On an A100 with batch=64, context=512, and horizon=128, this reduced latency from 108.8 ms to 73.7 ms (1.48x). Compiling the whole module after fixing the rebinding gave no measurable speedup in the reported benchmark.
TroubleshootingWhy does TimesFM's `xreg_mode` behave opposite to the docstring for `xreg + timesfm` and `timesfm + xreg`?
The docstring is reversed in the affected implementation. Use the mode according to the code, not the documentation:
- To fit xreg on the targets first and then forecast residuals with TimesFM, use:
xreg_mode="xreg + timesfm"- To generate the TimesFM forecast first and then fit xreg on its residuals, use:
xreg_mode="timesfm + xreg"
This is confirmed by the branch around L488–L494: timesfm + xreg uses max(0, input_len - self.input_patch_len) and is commented “For fitting residuals,” while xreg + timesfm uses input_len. Until the docstring is corrected, treat the documented descriptions as swapped.
TroubleshootingHow to fix TimesFM 2.5 PyTorch from_pretrained error: unexpected keyword argument 'proxies', and load_checkpoint NotImplementedError?
This is fixed by timesfm PR #435. Upgrade to a release containing that fix, or install the latest source:
pip install -U git+https://github.com/google-research/timesfm.git
Then retry:
import timesfm
tfm = timesfm.TimesFM_2p5_200M_torch.from_pretrained(
"google/timesfm-2.5-200m-pytorch"
)
If you cannot upgrade, temporarily pin an older Hub client:
pip install "huggingface_hub<0.34"
# for example:
pip install huggingface_hub==0.33.5
This may conflict with newer transformers/accelerate releases. In affected timesfm versions, do not use load_checkpoint(local_path) as a workaround because the PyTorch subclass raises NotImplementedError; use a patched timesfm build instead. A source-level fix is to make the model constructor accept and ignore newer Mixin kwargs, e.g. def __init__(self, config, **_ignored):.
how_toHow can I run TimesFM 3.0 on Apple Silicon without PyTorch?
Use the MLX backend. It is provided in PR #476 under src/timesfm3/mlx/ and keeps the existing PyTorch backend under src/timesfm3/torch/. The MLX version exposes the same timesfm3_forecaster interface, loads the same checkpoints, and matches PyTorch output to about 1e-6 max absolute error. A standalone implementation is available at https://github.com/rachittshah/mlx-tsfm.
Quick setup:
python -m pip install -U mlx
git clone https://github.com/rachittshah/mlx-tsfm.git
cd mlx-tsfm
pytest tests/test_timesfm.py
When using the TimesFM repository with PR #476, import the forecaster from timesfm3.mlx.timesfm3_forecaster instead of the Torch module and use the same initialization and forecast calls. On an M4 Max, the 330M model reportedly takes about 20 ms per single forecast and reaches roughly 475 forecasts/second when batched.