TimesFM (Time Series Foundation Model) is a pretrained time-series foundation model developed by Google Research for time-series forecasting.
Resources and Technical Documentation:
Authors: Google Research
This is not an officially supported Google product.
timesfm-1.0-200m is the first open model checkpoint:
Please refer to our result tables on the extended benchmarks and the long horizon benchmarks.
Please look into the README files in the respective benchmark directories within experiments/ for instructions for running TimesFM on the respective benchmarks.
This HuggingFace repo hosts TimesFm checkpoints. Please visit our GitHub repo and follow the instructions there to install the timesfm library for model inference.
In particular, the dependency lingvo does not support ARM architectures and the inference code is not working for machines with Apple silicon. We are aware of this issue and are working on a solution. Stay tuned.
Then the base class can be loaded as,
tcm = TimesFMConfig(<correct parameters>)
tfm_torch = PatchedTimeSeriesDecoder(tcm)
tfm_torch.load_state_dict(torch.load(PATH))
Note that the four parameters are fixed to load the 200m model
input_patch_len=32,
output_patch_len=128,
num_layers=20,
model_dims=1280,
tfm.forecast() function and the model will handle it. Currently, the model handles a max context length of 512, which can be increased in later releases. The input time series can have any context length. Padding / truncation will be handled by the inference code if needed.We provide APIs to forecast from either array inputs or pandas dataframe. Both forecast methods expect (1) the input time series contexts, (2) along with their frequencies. Please look at the documentation of the functions tfm.forecast() and tfm.forecast_on_df() for detailed instructions.
In particular, regarding the frequency, TimesFM expects a categorical indicator valued in {0, 1, 2}:
import numpy as np
forecast_input = [
np.sin(np.linspace(0, 20, 100))
np.sin(np.linspace(0, 20, 200)),
np.sin(np.linspace(0, 20, 400)),
]
frequency_input = [0, 1, 2]
point_forecast, experimental_quantile_forecast = tfm.forecast(
forecast_input,
freq=frequency_input,
)
pandas dataframe, with the frequency set to "M" monthly.
import pandas as pd
# e.g. input_df is
# unique_id ds y
# 0 T1 1975-12-31 697458.0
# 1 T1 1976-01-31 1187650.0
# 2 T1 1976-02-29 1069690.0
# 3 T1 1976-03-31 1078430.0
# 4 T1 1976-04-30 1059910.0
# ... ... ... ...
# 8175 T99 1986-01-31 602.0
# 8176 T99 1986-02-28 684.0
# 8177 T99 1986-03-31 818.0
# 8178 T99 1986-04-30 836.0
# 8179 T99 1986-05-31 878.0
forecast_df = tfm.forecast_on_df(
inputs=input_df,
freq="M", # monthly
value_name="y",
num_jobs=-1,
)
3 commits
TimesFM (Time Series Foundation Model) is a pretrained time-series foundation model developed by Google Research for time-series forecasting.
Resources and Technical Documentation:
Authors: Google Research
This is not an officially supported Google product.
timesfm-1.0-200m is the first open model checkpoint:
Please refer to our result tables on the extended benchmarks and the long horizon benchmarks.
Please look into the README files in the respective benchmark directories within experiments/ for instructions for running TimesFM on the respective benchmarks.
This HuggingFace repo hosts TimesFm checkpoints. Please visit our GitHub repo and follow the instructions there to install the timesfm library for model inference.
In particular, the dependency lingvo does not support ARM architectures and the inference code is not working for machines with Apple silicon. We are aware of this issue and are working on a solution. Stay tuned.
Then the base class can be loaded as,
tcm = TimesFMConfig(<correct parameters>)
tfm_torch = PatchedTimeSeriesDecoder(tcm)
tfm_torch.load_state_dict(torch.load(PATH))
Note that the four parameters are fixed to load the 200m model
input_patch_len=32,
output_patch_len=128,
num_layers=20,
model_dims=1280,
tfm.forecast() function and the model will handle it. Currently, the model handles a max context length of 512, which can be increased in later releases. The input time series can have any context length. Padding / truncation will be handled by the inference code if needed.We provide APIs to forecast from either array inputs or pandas dataframe. Both forecast methods expect (1) the input time series contexts, (2) along with their frequencies. Please look at the documentation of the functions tfm.forecast() and tfm.forecast_on_df() for detailed instructions.
In particular, regarding the frequency, TimesFM expects a categorical indicator valued in {0, 1, 2}:
import numpy as np
forecast_input = [
np.sin(np.linspace(0, 20, 100))
np.sin(np.linspace(0, 20, 200)),
np.sin(np.linspace(0, 20, 400)),
]
frequency_input = [0, 1, 2]
point_forecast, experimental_quantile_forecast = tfm.forecast(
forecast_input,
freq=frequency_input,
)
pandas dataframe, with the frequency set to "M" monthly.
import pandas as pd
# e.g. input_df is
# unique_id ds y
# 0 T1 1975-12-31 697458.0
# 1 T1 1976-01-31 1187650.0
# 2 T1 1976-02-29 1069690.0
# 3 T1 1976-03-31 1078430.0
# 4 T1 1976-04-30 1059910.0
# ... ... ... ...
# 8175 T99 1986-01-31 602.0
# 8176 T99 1986-02-28 684.0
# 8177 T99 1986-03-31 818.0
# 8178 T99 1986-04-30 836.0
# 8179 T99 1986-05-31 878.0
forecast_df = tfm.forecast_on_df(
inputs=input_df,
freq="M", # monthly
value_name="y",
num_jobs=-1,
)
3 commits