Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
TimesFM(Time Series Foundation Model,时间序列基础模型)是 Google Research 开发的预训练时间序列基础模型,用于时间序列预测。
此开源版本并非 Google 官方支持的产品。
最新模型版本: TimesFM 2.5
已归档模型版本:
v1。你可以 pip install timesfm==1.3.0 安装该软件包的旧版本以加载
它们。已将 PyPI 更新至 timesfm=2.0.2。参见 Install.
新增使用 HuggingFace Transformers + PEFT(LoRA)的微调示例 — 参见
timesfm-forecasting/examples/finetuning/。
同时新增单元测试(tests/),并纳入多项社区修复。
特别鸣谢 @kashif 与 @darkpowerxo.
大力感谢 @borealBytes 添加了对 AGENTS! 的支持;TimesFM SKILL.md 已发布。
通过 XReg 为 TimesFM 2.5 重新加入协变量(covariate)支持。
TimesFM 2.5 正式发布!
与 TimesFM 2.0 相比,全新的 2.5 模型:
frequency 指示器。自 2025 年 9 月发布以来,已完成以下改进:
timesfm-forecasting/)。timesfm-forecasting/examples/finetuning/)。tests/)。PyPI 安装# Install the package with torch
pip install timesfm[torch]
# Or with Flax
pip install timesfm[flax]
# And when XReg is needed
pip install timesfm[xreg]
克隆仓库:
git clone https://github.com/google-research/timesfm.git
cd timesfm
使用 uv 创建虚拟环境并安装依赖:
# Create a virtual environment
uv venv
# Activate the environment
source .venv/bin/activate
# Install the package in editable mode with torch
uv pip install -e .[torch]
# Or with flax
uv pip install -e .[flax]
# And when XReg is needed
uv pip install -e .[xreg]
[可选] 根据你的操作系统与加速器(CPU、GPU、TPU 或 Apple Silicon)安装偏好的 torch / jax 后端:
import torch
import numpy as np
import timesfm
torch.set_float32_matmul_precision("high")
model = timesfm.TimesFM_2p5_200M_torch.from_pretrained("google/timesfm-2.5-200m-pytorch")
model.compile(
timesfm.ForecastConfig(
max_context=1024,
max_horizon=256,
normalize_inputs=True,
use_continuous_quantile_head=True,
force_flip_invariance=True,
infer_is_positive=True,
fix_quantile_crossing=True,
)
)
point_forecast, quantile_forecast = model.forecast(
horizon=12,
inputs=[
np.linspace(0, 1, 100),
np.sin(np.linspace(0, 20, 67)),
], # Two dummy inputs
)
point_forecast.shape # (2, 12)
quantile_forecast.shape # (2, 12, 10): mean, then 10th to 90th quantiles.